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

Function TestChatWithMCPServerIDs

coderd/mcp_test.go:1387–1421  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1385}
1386
1387func TestChatWithMCPServerIDs(t *testing.T) {
1388 t.Parallel()
1389
1390 ctx := testutil.Context(t, testutil.WaitLong)
1391 client := newMCPClient(t)
1392 firstUser := coderdtest.CreateFirstUser(t, client)
1393
1394 expClient := codersdk.NewExperimentalClient(client)
1395
1396 // Create the chat model config required for creating a chat.
1397 _ = createChatModelConfigForMCP(t, expClient)
1398
1399 // Create an enabled MCP server config.
1400 mcpConfig := createMCPServerConfig(t, client, "chat-mcp-server", true)
1401
1402 // Create a chat referencing the MCP server.
1403 chat, err := expClient.CreateChat(ctx, codersdk.CreateChatRequest{
1404 OrganizationID: firstUser.OrganizationID,
1405 Content: []codersdk.ChatInputPart{
1406 {
1407 Type: codersdk.ChatInputPartTypeText,
1408 Text: "hello with mcp server",
1409 },
1410 },
1411 MCPServerIDs: []uuid.UUID{mcpConfig.ID},
1412 })
1413 require.NoError(t, err)
1414 require.NotEqual(t, uuid.Nil, chat.ID)
1415 require.Contains(t, chat.MCPServerIDs, mcpConfig.ID)
1416
1417 // Fetch the chat and verify the MCP server IDs persist.
1418 fetched, err := expClient.GetChat(ctx, chat.ID)
1419 require.NoError(t, err)
1420 require.Contains(t, fetched.MCPServerIDs, mcpConfig.ID)
1421}
1422
1423func createChatModelConfigForMCP(t testing.TB, client *codersdk.ExperimentalClient) codersdk.ChatModelConfig {
1424 t.Helper()

Callers

nothing calls this directly

Calls 9

CreateChatMethod · 0.95
GetChatMethod · 0.95
ContextFunction · 0.92
CreateFirstUserFunction · 0.92
NewExperimentalClientFunction · 0.92
newMCPClientFunction · 0.85
createMCPServerConfigFunction · 0.70
ContainsMethod · 0.45

Tested by

no test coverage detected