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)
| 358 | // connectToServer connects to the MCP server and returns a client session. |
| 359 | // The caller is responsible for closing the session. |
| 360 | func 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 | } |
no test coverage detected
searching dependent graphs…