MCPcopy Index your code
hub / github.com/github/github-mcp-server / runProbe

Function runProbe

internal/ghmcp/oauth_test.go:35–69  ·  view source on GitHub ↗

runProbe stands up an in-memory MCP client/server pair, registers a tool whose handler runs probe against a sessionPrompter wrapping the live server session, and returns the text the probe produced. The client is configured with the given capabilities and elicitation handler so the adapter sees a re

(
	t *testing.T,
	clientCaps *mcp.ClientCapabilities,
	elicitationHandler func(context.Context, *mcp.ElicitRequest) (*mcp.ElicitResult, error),
	probe func(context.Context, *sessionPrompter) string,
)

Source from the content-addressed store, hash-verified

33// given capabilities and elicitation handler so the adapter sees a real,
34// fully-negotiated session rather than a hand-built fake.
35func runProbe(
36 t *testing.T,
37 clientCaps *mcp.ClientCapabilities,
38 elicitationHandler func(context.Context, *mcp.ElicitRequest) (*mcp.ElicitResult, error),
39 probe func(context.Context, *sessionPrompter) string,
40) string {
41 t.Helper()
42
43 server := mcp.NewServer(&mcp.Implementation{Name: "test-server", Version: "v0.0.1"}, nil)
44 mcp.AddTool(server, &mcp.Tool{Name: probeToolName}, func(ctx context.Context, req *mcp.CallToolRequest, _ struct{}) (*mcp.CallToolResult, any, error) {
45 text := probe(ctx, &sessionPrompter{session: req.Session})
46 return &mcp.CallToolResult{Content: []mcp.Content{&mcp.TextContent{Text: text}}}, nil, nil
47 })
48
49 st, ct := mcp.NewInMemoryTransports()
50
51 ss, err := server.Connect(context.Background(), st, nil)
52 require.NoError(t, err)
53 t.Cleanup(func() { _ = ss.Close() })
54
55 client := mcp.NewClient(&mcp.Implementation{Name: "test-client", Version: "v0.0.1"}, &mcp.ClientOptions{
56 Capabilities: clientCaps,
57 ElicitationHandler: elicitationHandler,
58 })
59 cs, err := client.Connect(context.Background(), ct, nil)
60 require.NoError(t, err)
61 t.Cleanup(func() { _ = cs.Close() })
62
63 res, err := cs.CallTool(context.Background(), &mcp.CallToolParams{Name: probeToolName})
64 require.NoError(t, err)
65 require.Len(t, res.Content, 1)
66 text, ok := res.Content[0].(*mcp.TextContent)
67 require.True(t, ok, "probe result should be text content")
68 return text.Text
69}
70
71func TestSessionPrompterCapabilities(t *testing.T) {
72 t.Parallel()

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected