MCPcopy Index your code
hub / github.com/coder/coder / TestMCPHTTP_E2E_ChatGPTEndpoint

Function TestMCPHTTP_E2E_ChatGPTEndpoint

coderd/mcp/mcp_e2e_test.go:1251–1398  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1249}
1250
1251func TestMCPHTTP_E2E_ChatGPTEndpoint(t *testing.T) {
1252 t.Parallel()
1253
1254 // Setup Coder server with authentication
1255 coderClient, closer, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
1256 IncludeProvisionerDaemon: true,
1257 })
1258 defer closer.Close()
1259
1260 user := coderdtest.CreateFirstUser(t, coderClient)
1261
1262 // Create template and workspace for testing search functionality
1263 version := coderdtest.CreateTemplateVersion(t, coderClient, user.OrganizationID, nil)
1264 coderdtest.AwaitTemplateVersionJobCompleted(t, coderClient, version.ID)
1265 template := coderdtest.CreateTemplate(t, coderClient, user.OrganizationID, version.ID)
1266
1267 // Create MCP client pointing to the ChatGPT endpoint
1268 mcpURL := api.AccessURL.String() + mcpserver.MCPEndpoint + "?toolset=chatgpt"
1269
1270 // Configure client with authentication headers using RFC 6750 Bearer token
1271 mcpClient, err := mcpclient.NewStreamableHttpClient(mcpURL,
1272 transport.WithHTTPHeaders(map[string]string{
1273 "Authorization": "Bearer " + coderClient.SessionToken(),
1274 }))
1275 require.NoError(t, err)
1276 t.Cleanup(func() {
1277 if closeErr := mcpClient.Close(); closeErr != nil {
1278 t.Logf("Failed to close MCP client: %v", closeErr)
1279 }
1280 })
1281
1282 ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitLong)
1283 defer cancel()
1284
1285 // Start client
1286 err = mcpClient.Start(ctx)
1287 require.NoError(t, err)
1288
1289 // Initialize connection
1290 initReq := mcp.InitializeRequest{
1291 Params: mcp.InitializeParams{
1292 ProtocolVersion: mcp.LATEST_PROTOCOL_VERSION,
1293 ClientInfo: mcp.Implementation{
1294 Name: "test-chatgpt-client",
1295 Version: "1.0.0",
1296 },
1297 },
1298 }
1299
1300 result, err := mcpClient.Initialize(ctx, initReq)
1301 require.NoError(t, err)
1302 require.Equal(t, mcpserver.MCPServerName, result.ServerInfo.Name)
1303 require.Equal(t, mcp.LATEST_PROTOCOL_VERSION, result.ProtocolVersion)
1304 require.NotNil(t, result.Capabilities)
1305
1306 // Test tool listing - should only have search and fetch tools for ChatGPT
1307 tools, err := mcpClient.ListTools(ctx, mcp.ListToolsRequest{})
1308 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
CreateTemplateVersionFunction · 0.92
CreateTemplateFunction · 0.92
InitializeMethod · 0.80
NotEmptyMethod · 0.80
CloseMethod · 0.65
CleanupMethod · 0.65
LogfMethod · 0.65
ContextMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected