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

Function TestToolInjectionOrder

aibridge/mcp/mcp_test.go:297–333  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

295}
296
297func TestToolInjectionOrder(t *testing.T) {
298 t.Parallel()
299
300 // Setup.
301 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: false}).Leveled(slog.LevelDebug)
302 ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitLong)
303 t.Cleanup(cancel)
304
305 // Given: a MCP mock server offering a set of tools.
306 mcpSrv := httptest.NewServer(createMockMCPSrv(t))
307 t.Cleanup(mcpSrv.Close)
308
309 tracer := otel.Tracer("forTesting")
310 // When: creating two MCP server proxies, both listing the same tools by name but under different server namespaces.
311 proxy, err := mcp.NewStreamableHTTPServerProxy("coder", mcpSrv.URL, nil, nil, nil, logger, tracer)
312 require.NoError(t, err)
313 proxy2, err := mcp.NewStreamableHTTPServerProxy("shmoder", mcpSrv.URL, nil, nil, nil, logger, tracer)
314 require.NoError(t, err)
315
316 // Then: initialize both proxies.
317 require.NoError(t, proxy.Init(ctx))
318 require.NoError(t, proxy2.Init(ctx))
319
320 // Then: validate that their tools are separately sorted stably.
321 validateToolOrder(t, proxy)
322 validateToolOrder(t, proxy2)
323
324 // When: creating a manager which contains both MCP server proxies.
325 mgr := mcp.NewServerProxyManager(map[string]mcp.ServerProxier{
326 "coder": proxy,
327 "shmoder": proxy2,
328 }, otel.GetTracerProvider().Tracer("test"))
329 require.NoError(t, mgr.Init(ctx))
330
331 // Then: the tools from both servers should be collectively sorted stably.
332 validateToolOrder(t, mgr)
333}
334
335func validateToolOrder(t *testing.T, proxy mcp.ServerProxier) {
336 t.Helper()

Callers

nothing calls this directly

Calls 9

InitMethod · 0.95
InitMethod · 0.95
NewServerProxyManagerFunction · 0.92
validateToolOrderFunction · 0.85
TracerMethod · 0.80
createMockMCPSrvFunction · 0.70
ContextMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected