MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / connectToServer

Function connectToServer

conformance/everything-client/main.go:360–382  ·  view source on GitHub ↗

connectToServer connects to the MCP server and returns a client session. The caller is responsible for closing the session.

(ctx context.Context, serverURL string, opts ...connectOption)

Source from the content-addressed store, hash-verified

358// connectToServer connects to the MCP server and returns a client session.
359// The caller is responsible for closing the session.
360func connectToServer(ctx context.Context, serverURL string, opts ...connectOption) (*mcp.ClientSession, error) {
361 config := &connectConfig{}
362 for _, opt := range opts {
363 opt(config)
364 }
365
366 client := mcp.NewClient(&mcp.Implementation{
367 Name: "test-client",
368 Version: "1.0.0",
369 }, config.clientOptions)
370
371 transport := &mcp.StreamableClientTransport{
372 Endpoint: serverURL,
373 OAuthHandler: config.oauthHandler,
374 }
375
376 session, err := client.Connect(ctx, transport, nil)
377 if err != nil {
378 return nil, fmt.Errorf("client.Connect(): %w", err)
379 }
380
381 return session, nil
382}

Callers 5

runBasicClientFunction · 0.85
runToolsCallClientFunction · 0.85
runSSERetryClientFunction · 0.85
runAuthClientFunction · 0.85

Calls 2

ConnectMethod · 0.95
NewClientFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…