@mcp-ts/sdk/shared) provides the core TypeScript types used across server-side and client-side code. Import from @mcp-ts/sdk/server or @mcp-ts/sdk/client — both re-export everything from the shared module.
McpConnectionState
A string union representing the lifecycle of a single MCP connection. Both the server and the client use these states to communicate progress, errors, and readiness.
| State | When it occurs |
|---|---|
INITIALIZING | MCPClient.connect() is called for the first time; loading config from storage |
VALIDATING | Restoring a session — verifying the server is still reachable |
CONNECTING | OAuth tokens validated; transport handshake in progress |
CONNECTED | Transport handshake succeeded; tool discovery about to start |
DISCOVERING | listTools() (or listPrompts, listResources) is running |
READY | Tools discovered; the connection is usable |
AUTHENTICATING | OAuth redirect issued; waiting for the user to authorize |
RECONNECTING | Background reconnect triggered after a transient failure |
FAILED | Non-recoverable error; the connection must be removed or retried manually |
DISCONNECTED | disconnect() was called or the transport closed cleanly |
McpConnectionEvent
A discriminated union emitted by MCPClient and forwarded over SSE to connected browser clients. Subscribe via onConnectionEvent in useMcp.
state_changed
state_changed
Fired whenever the connection state transitions.
previousState lets you implement fine-grained UI updates.tools_discovered
tools_discovered
Fired after
listTools() succeeds. Contains the full tool list. The useMcp hook automatically updates the connections[].tools array when this event arrives.auth_required
auth_required
Fired when the server returns a 401 and an OAuth URL is available. The
useMcp hook redirects to authUrl automatically (or calls onRedirect if provided).error
error
Fired when a connection, auth, or validation step fails. The
errorType field narrows the cause.disconnected
disconnected
Fired when a session is cleanly closed. The
useMcp hook removes the connection from connections on this event.progress
progress
Informational messages emitted during long-running steps (e.g.
"Validating OAuth tokens...", "Connected successfully").McpObservabilityEvent
Structured log events emitted alongside connection events. Use these for debugging, tracing, or shipping logs to an observability backend.
onLog callback in useMcp:
ToolInfo
A lightweight representation of a tool. Used in connections[].tools on the client side.
Tool type (including inputSchema.properties and required), use:
SessionInfo
A lightweight session summary returned by getSessions(). Does not include OAuth tokens.
ConnectRequest / ConnectResponse
RPC types used when connecting to an MCP server via the SSE client.
CallToolRequest / CallToolResponse
RPC types for tool execution.
ListToolsResponse
RPC response type for listing tools.
isListToolsSuccess type guard:
UnauthorizedError
Thrown by MCPClient.connect() when the server requires OAuth authorization and a valid authUrl is available.
'OAuth authorization required'. The authUrl is not a property of UnauthorizedError itself — it is emitted via the auth_required connection event on the client’s onConnectionEvent emitter.
Utility classes
Emitter<T>
A type-safe event emitter for connection and observability events. Used by MCPClient and SSEClient, and exported for advanced use cases.
DisposableStore
Collects multiple Disposable objects and disposes them all at once. Useful in useEffect cleanup.