createMCPRequestWithSession creates a CallToolRequest with a ServerSession that has the given client name in its InitializeParams. When withUI is true the session advertises MCP Apps UI support via the capability extension.
(t *testing.T, clientName string, withUI bool, args any)
| 343 | // that has the given client name in its InitializeParams. When withUI is true |
| 344 | // the session advertises MCP Apps UI support via the capability extension. |
| 345 | func createMCPRequestWithSession(t *testing.T, clientName string, withUI bool, args any) mcp.CallToolRequest { |
| 346 | t.Helper() |
| 347 | |
| 348 | argsMap, ok := args.(map[string]any) |
| 349 | if !ok { |
| 350 | argsMap = make(map[string]any) |
| 351 | } |
| 352 | argsJSON, err := json.Marshal(argsMap) |
| 353 | require.NoError(t, err) |
| 354 | |
| 355 | srv := mcp.NewServer(&mcp.Implementation{Name: "test"}, nil) |
| 356 | |
| 357 | caps := &mcp.ClientCapabilities{} |
| 358 | if withUI { |
| 359 | caps.AddExtension("io.modelcontextprotocol/ui", map[string]any{ |
| 360 | "mimeTypes": []string{"text/html;profile=mcp-app"}, |
| 361 | }) |
| 362 | } |
| 363 | |
| 364 | st, _ := mcp.NewInMemoryTransports() |
| 365 | session, err := srv.Connect(context.Background(), st, &mcp.ServerSessionOptions{ |
| 366 | State: &mcp.ServerSessionState{ |
| 367 | InitializeParams: &mcp.InitializeParams{ |
| 368 | ClientInfo: &mcp.Implementation{Name: clientName}, |
| 369 | Capabilities: caps, |
| 370 | }, |
| 371 | }, |
| 372 | }) |
| 373 | require.NoError(t, err) |
| 374 | |
| 375 | // Close the unused client-side transport and session |
| 376 | t.Cleanup(func() { |
| 377 | _ = session.Close() |
| 378 | }) |
| 379 | |
| 380 | return mcp.CallToolRequest{ |
| 381 | Session: session, |
| 382 | Params: &mcp.CallToolParamsRaw{ |
| 383 | Arguments: json.RawMessage(argsJSON), |
| 384 | }, |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | // getTextResult is a helper function that returns a text result from a tool call. |
| 389 | func getTextResult(t *testing.T, result *mcp.CallToolResult) *mcp.TextContent { |
no test coverage detected