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

Function TestMCPHTTP_E2E_ClientIntegration

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

Source from the content-addressed store, hash-verified

45}
46
47func TestMCPHTTP_E2E_ClientIntegration(t *testing.T) {
48 t.Parallel()
49
50 // Setup Coder server with authentication
51 coderClient, closer, api := coderdtest.NewWithAPI(t, nil)
52 defer closer.Close()
53
54 _ = coderdtest.CreateFirstUser(t, coderClient)
55
56 // Create MCP client pointing to our endpoint
57 mcpURL := api.AccessURL.String() + mcpserver.MCPEndpoint
58
59 // Configure client with authentication headers using RFC 6750 Bearer token
60 mcpClient, err := mcpclient.NewStreamableHttpClient(mcpURL,
61 transport.WithHTTPHeaders(map[string]string{
62 "Authorization": "Bearer " + coderClient.SessionToken(),
63 }))
64 require.NoError(t, err)
65 defer func() {
66 if closeErr := mcpClient.Close(); closeErr != nil {
67 t.Logf("Failed to close MCP client: %v", closeErr)
68 }
69 }()
70
71 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
72 defer cancel()
73
74 // Start client
75 err = mcpClient.Start(ctx)
76 require.NoError(t, err)
77
78 // Initialize connection
79 initReq := mcp.InitializeRequest{
80 Params: mcp.InitializeParams{
81 ProtocolVersion: mcp.LATEST_PROTOCOL_VERSION,
82 ClientInfo: mcp.Implementation{
83 Name: "test-client",
84 Version: "1.0.0",
85 },
86 },
87 }
88
89 result, err := mcpClient.Initialize(ctx, initReq)
90 require.NoError(t, err)
91 require.Equal(t, mcpserver.MCPServerName, result.ServerInfo.Name)
92 require.Equal(t, mcp.LATEST_PROTOCOL_VERSION, result.ProtocolVersion)
93 require.NotNil(t, result.Capabilities)
94
95 // Test tool listing
96 tools, err := mcpClient.ListTools(ctx, mcp.ListToolsRequest{})
97 require.NoError(t, err)
98 require.NotEmpty(t, tools.Tools)
99
100 // Verify we have some expected Coder tools
101 var foundTools []string
102 var userTool *mcp.Tool
103 var writeFileTool *mcp.Tool
104 for i := range tools.Tools {

Callers

nothing calls this directly

Calls 15

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
InitializeMethod · 0.80
NotEmptyMethod · 0.80
CloseMethod · 0.65
LogfMethod · 0.65
StartMethod · 0.65
ListToolsMethod · 0.65
CallToolMethod · 0.65
PingMethod · 0.65
StringMethod · 0.45
SessionTokenMethod · 0.45

Tested by

no test coverage detected