| title |
|---|
Client |
The SDK provides a high-level Client class that connects to MCP servers over different transports:
StdioClientTransport– for local processes you spawn.StreamableHTTPClientTransport– for remote HTTP servers.SSEClientTransport– for legacy HTTP+SSE servers (deprecated).
Runnable client examples live under:
simpleStreamableHttp.tsstreamableHttpWithSseFallbackClient.tsssePollingClient.tsmultipleClientsParallel.tsparallelToolCallsClient.ts
A typical flow:
- Construct a
Clientwith name, version and capabilities. - Create a transport and call
client.connect(transport). - Use high-level helpers:
listTools,callToollistPrompts,getPromptlistResources,readResource
See simpleStreamableHttp.ts for an interactive CLI client that exercises these methods and shows how to handle notifications, elicitation and tasks.
To support both modern Streamable HTTP and legacy SSE servers, use a client that:
- Tries
StreamableHTTPClientTransport. - Falls back to
SSEClientTransporton a 4xx response.
Runnable example:
For OAuth-secured MCP servers, the client auth module exposes:
ClientCredentialsProviderPrivateKeyJwtProviderStaticPrivateKeyJwtProvider
Examples:
simpleOAuthClient.tssimpleOAuthClientProvider.tssimpleClientCredentials.ts- Server-side auth demo:
demoInMemoryOAuthProvider.ts(tests live underexamples/shared/test/demoInMemoryOAuthProvider.test.ts)
These examples show how to:
- Perform dynamic client registration if needed.
- Acquire access tokens.
- Attach OAuth credentials to Streamable HTTP requests.