Minor Changes
-
#565
0e9a607Thanks @mattzcarey! - Add RPC transport for MCP: connect an Agent to an McpAgent via Durable Object bindingsNew feature:
addMcpServerwith DO bindingAgents can now connect to McpAgent instances in the same Worker using RPC transport — no HTTP, no network overhead. Pass the Durable Object namespace directly:
// In your Agent await this.addMcpServer("counter", env.MY_MCP); // With props await this.addMcpServer("counter", env.MY_MCP, { props: { userId: "user-123", role: "admin" }, });
The
addMcpServermethod now acceptsstring | DurableObjectNamespaceas the second parameter with proper TypeScript overloads, so HTTP and RPC paths are type-safe and cannot be mixed.Hibernation support
RPC connections survive Durable Object hibernation automatically. The binding name and props are persisted to storage and restored on wake-up, matching the behavior of HTTP MCP connections. No need to manually re-establish connections in
onStart().Deduplication
Calling
addMcpServerwith the same server name multiple times (e.g., across hibernation cycles) now returns the existing connection instead of creating duplicates. This applies to both RPC and HTTP connections. Connection IDs are stable across hibernation restore.Other changes
- Rewrote
RPCClientTransportto accept aDurableObjectNamespaceand create the stub internally viagetServerByNamefrom partyserver, instead of requiring a pre-constructed stub - Rewrote
RPCServerTransportto drop session management (unnecessary for DO-scoped RPC) and useJSONRPCMessageSchemafrom the MCP SDK for validation instead of 170 lines of hand-written validation - Removed
_resolveRpcBinding,_buildRpcTransportOptions,_buildHttpTransportOptions, and_connectToMcpServerInternalfrom the Agent base class — RPC transport logic no longer leaks intoindex.ts - Added
AddRpcMcpServerOptionstype (discriminated fromAddMcpServerOptions) sopropsis only available when passing a binding - Added
RPC_DO_PREFIXconstant used consistently across all RPC naming - Fixed
MCPClientManager.callToolpassingserverIdthrough toconn.client.callTool(it should be stripped before the call) - Added
getRpcServersFromStorage()andsaveRpcServerToStorage()toMCPClientManagerfor hibernation persistence restoreConnectionsFromStoragenow skips RPC servers (restored separately by the Agent class which has access toenv)- Reduced
rpc.tsfrom 609 lines to 245 lines - Reduced
types.tsfrom 108 lines to 26 lines - Updated
mcp-rpc-transportexample to use Workers AI (no API keys needed), Kumo/agents-ui components, and Tailwind CSS - Updated MCP transports documentation
- Rewrote
Patch Changes
-
#973
969fbffThanks @threepointone! - Update dependencies -
#960
179b8cbThanks @mattzcarey! - Harden JSON Schema to TypeScript converter for production use- Add depth and circular reference guards to prevent stack overflows on recursive or deeply nested schemas
- Add
$refresolution for internal JSON Pointers (#/definitions/...,#/$defs/...,#) - Add tuple support (
prefixItemsfor JSON Schema 2020-12, arrayitemsfor draft-07) - Add OpenAPI 3.0
nullable: truesupport across all schema branches - Fix string escaping in enum/const values, property names (control chars, U+2028/U+2029), and JSDoc comments (
*/) - Add per-tool error isolation in
generateTypes()so one malformed schema cannot crash the pipeline - Guard missing
inputSchemaingetAITools()with a fallback to{ type: "object" } - Add per-tool error isolation in
getAITools()so one bad MCP tool does not break the entire tool set
-
#963
b848008Thanks @threepointone! - MakecallbackHostoptional inaddMcpServerfor non-OAuth serversPreviously,
addMcpServer()always required acallbackHost(either explicitly or derived from the request context) and eagerly created an OAuth auth provider, even when connecting to MCP servers that do not use OAuth. This made simple non-OAuth connections unnecessarily difficult, especially from WebSocket callable methods where the request context origin is unreliable.Now,
callbackHostand the OAuth auth provider are only required when the MCP server actually needs OAuth (returns a 401/AUTHENTICATING state). For non-OAuth servers,addMcpServer("name", url)works with no additional options. If an OAuth server is encountered without acallbackHost, a clear error is thrown: "This MCP server requires OAuth authentication. Provide callbackHost in addMcpServer options to enable the OAuth flow."The restore-from-storage flow also handles missing callback URLs gracefully, skipping auth provider creation for non-OAuth servers.
-
97c6702Thanks @threepointone! - Add one-time console warning when using RPC transport (DO binding) withaddMcpServer, noting the API is experimental and linking to the feedback issue.