createNextMcpHandler(options)
Creates handlers for Next.js App Router API routes.
getIdentity- Function to extract identity from request (required)getAuthToken- Function to extract auth token from request (optional)authenticate- Custom authentication logic (optional)heartbeatInterval- SSE heartbeat interval in ms (default: 30000)clientDefaults- Static OAuth client metadata (optional)getClientMetadata- Dynamic OAuth metadata getter (optional, overrides defaults)
{ GET, POST } - HTTP method handlers
createSSEHandler(options)
Creates an SSE handler for standard Node.js/Express applications.
identity- User/Client identifier (required)onAuth- Authentication callback (optional)heartbeatInterval- Heartbeat interval in ms (default: 30000)clientDefaults- Static OAuth client metadata (optional)getClientMetadata- Dynamic OAuth metadata getter (optional)
MCPClient
Direct MCP client class for server-side operations.
Methods
connect(): Promise<void>
Connect to the MCP server. May throw UnauthorizedError if OAuth is required.
disconnect(): Promise<void>
Disconnect from the MCP server.
listTools(): Promise<ListToolsResult>
List available tools from the MCP server.
callTool(name: string, args: object): Promise<CallToolResult>
Call a tool with arguments.
getAITools(): Promise<ToolSet>
Get all MCP tools and convert them to AI SDK compatible tools.
listPrompts(): Promise<ListPromptsResult>
List available prompts.
getPrompt(name: string, args?: object): Promise<GetPromptResult>
Get a prompt with optional arguments.
listResources(): Promise<ListResourcesResult>
List available resources.
readResource(uri: string): Promise<ReadResourceResult>
Read a specific resource by URI.
finishAuth(code: string): Promise<void>
Complete OAuth authorization with authorization code.
MultiSessionClient
Manages multiple MCP connections for a single user identity, allowing aggregation of tools from all connected servers.
timeout- Connection timeout in milliseconds (default: 15000)maxRetries- Maximum number of retry attempts for each session (default: 2)retryDelay- Delay between retries in milliseconds (default: 1000)
Methods
connect(): Promise<void>
Connects to all active sessions for the user. Skips sessions that fail to connect after retries, but logs errors.
getClients(): MCPClient[]
Returns the array of currently connected clients.
disconnect(): void
Disconnects all active clients and clears the internal client list.