MCP-Web Bridge API
MCPWebBridge
Class — packages/bridge/src/core.ts
Core bridge server that connects web frontends to AI agents via MCP.
MCPWebBridge manages WebSocket connections from frontends, routes tool calls, handles queries, and exposes an HTTP API for MCP clients. It is runtime-agnostic and delegates I/O operations to adapters.
Properties:
MCP_SESSION_IDLE_TIMEOUT_MS: anyAccessors:
get config(): MCPWebConfigOutputThe validated bridge configuration.
Methods:
getHandlers(): BridgeHandlersReturns handlers for wiring to runtime-specific I/O.
Use these handlers to connect the bridge to your runtime's WebSocket and HTTP servers. Pre-built adapters (Node, Bun, Deno, PartyKit) handle this automatically.
close(): Promise<void>Gracefully shuts down the bridge.
Closes all WebSocket connections, cancels scheduled tasks, and clears all internal state. Call this when shutting down your server.
AuthenticateMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'authenticate'sessionId: stringauthToken: stringorigin: stringpageTitle?: stringsessionName?: stringuserAgent?: stringtimestamp: numberAuthenticatedMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'authenticated'mcpPort?: numbersessionId: stringsuccess: booleanAuthenticationFailedMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'authentication-failed'error: stringcode: stringRegisterToolMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'register-tool'tool: {
name: string;
description: string;
inputSchema?: z.core.JSONSchema.JSONSchema;
outputSchema?: z.core.JSONSchema.JSONSchema;
_meta?: Record<string, unknown>;
}RegisterResourceMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'register-resource'resource: ResourceMetadataResourceReadMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'resource-read'requestId: stringuri: stringResourceResponseMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'resource-response'requestId: stringcontent?: stringblob?: stringmimeType: stringerror?: stringActivityMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'activity'timestamp: numberToolCallMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'tool-call'requestId: stringtoolName: stringtoolInput?: Record<string, unknown>queryId?: stringToolRegistrationErrorMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'tool-registration-error'toolName: stringerror: stringmessage: stringToolResponseMessage
Interface — packages/bridge/src/types.ts
Properties:
type: 'tool-response'requestId: stringresult: unknownTrackedToolCall
Interface — packages/bridge/src/types.ts
Properties:
tool: stringarguments: unknownresult: unknownQueryTracking
Interface — packages/bridge/src/types.ts
Properties:
sessionId: stringresponseTool?: stringtoolCalls: TrackedToolCall[]ws: WS.WebSocketstate: QueryStatetools?: ToolMetadata[]restrictTools?: booleanMcpRequest
Interface — packages/bridge/src/types.ts
Properties:
jsonrpc: stringid: string | numbermethod: stringparams?: {
name?: string;
arguments?: Record<string, unknown>;
_meta?: McpRequestMetaParams;
}McpResponse
Interface — packages/bridge/src/types.ts
Properties:
jsonrpc: stringid: string | numberresult?: unknownerror?: {
code: number;
message: string;
data?: unknown;
}ToolDefinition
Interface — packages/bridge/src/types.ts
Properties:
name: stringdescription: stringinputSchema?: z.core.JSONSchema.JSONSchemaoutputSchema?: z.core.JSONSchema.JSONSchemahandler?: stringSessionData
Interface — packages/bridge/src/types.ts
Properties:
ws: WS.WebSocketauthToken: stringorigin: stringpageTitle?: stringsessionName?: stringuserAgent?: stringconnectedAt: numberlastActivity: numbertools: Map<string, ToolDefinition>resources: Map<string, ResourceMetadata>FrontendMessage
Type — packages/bridge/src/types.ts
| AuthenticateMessage
| RegisterToolMessage
| RegisterResourceMessage
| ActivityMessage
| ToolResponseMessage
| ResourceResponseMessage
| QueryMessage
| QueryCompleteClientMessage
| QueryProgressMessage
| QueryCancelMessageBridgeMessage
Type — packages/bridge/src/types.ts
| AuthenticatedMessage
| AuthenticationFailedMessage
| ToolCallMessage
| ToolRegistrationErrorMessage
| ResourceReadMessage
| QueryAcceptedMessage
| QueryProgressMessage
| QueryCompleteBridgeMessage
| QueryFailureMessage
| QueryCancelMessageQueryState
Type — packages/bridge/src/types.ts
'active' | 'completed' | 'failed' | 'cancelled'MissingAuthenticationErrorMessage
Variable — packages/bridge/src/schemas.ts
unknownMissingAuthenticationErrorMessageSchema
Variable — packages/bridge/src/schemas.ts
unknownInvalidAuthenticationErrorMessage
Variable — packages/bridge/src/schemas.ts
unknownInvalidAuthenticationErrorMessageSchema
Variable — packages/bridge/src/schemas.ts
unknown