Skip to content

Commit c07b2c0

Browse files
authored
MCP client refactor - storage adapter (#652)
* move storage to the client manager * fix: url missing after page load * fix: dots * fix: callback handling is now in client manager with 2 stage storage. * some auth edge cases * make storage sync for the moment to reduce complexity * better default states * cancel button on frontend * remove openai from agents package.json * unify mcp storage * fix lock file * fix: tests * feat: more refactor * tools tests * update x402 * fix: types * update default model in playground * reasoning card * Apply suggestion from @mattzcarey * fix: from review * add smooth scrolling * fix: calling restore onstart and json schema the rest of the time * fix: oauth tests * remove smooth scroll :( * make tests smaller * rename to client for review * revert changes to mcp.connect() * make storage async * fix readonly nit * revert remove openai ai sdk provider * remove public storage api * add todos for ensureJsonSchema * fix: mcp server states and unify observability to the mcp client manager class. * remove callback cache * dead * createConnection. in memory method * add tests * changeset * formatting * claude comments * remove redundant checks
1 parent 412321b commit c07b2c0

File tree

17 files changed

+2881
-725
lines changed

17 files changed

+2881
-725
lines changed

.changeset/plenty-friends-hope.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
"agents": minor
3+
---
4+
5+
### Breaking Changes
6+
7+
- **`getMcpServers()` is now async**: Changed from synchronous to asynchronous method to support storage operations
8+
- **`DurableObjectOAuthClientProvider` constructor**: Now accepts `OAuthClientStorage` interface instead of `DurableObjectStorage`
9+
10+
### New Features
11+
12+
- **`MCPClientManager` API changes**:
13+
- New `registerServer()` method to register servers (replaces part of `connect()`)
14+
- New `connectToServer()` method to establish connection (replaces part of `connect()`)
15+
- `connect()` method deprecated (still works for backward compatibility)
16+
- Requires `MCPClientStorage` interface implementation (provided via `AgentMCPClientStorage`)
17+
- **Storage abstraction layer**: New `MCPClientStorage` and `OAuthClientStorage` interfaces enable custom storage implementations beyond Durable Objects
18+
- **Connection state observability**: New `onServerStateChanged()` event for tracking all server state changes
19+
- **Improved reconnect logic**: `restoreConnectionsFromStorage()` handles failed connections
20+
21+
### Bug Fixes
22+
23+
- Fixed failed connections not being recreated on restore
24+
- Fixed redundant storage operations during connection restoration

packages/agents/src/ai-chat-agent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,12 @@ export class AIChatAgent<Env = unknown, State = unknown> extends Agent<
190190
override async onRequest(request: Request): Promise<Response> {
191191
return this._tryCatchChat(() => {
192192
const url = new URL(request.url);
193+
193194
if (url.pathname.endsWith("/get-messages")) {
194195
const messages = this._loadMessagesFromDb();
195196
return Response.json(messages);
196197
}
198+
197199
return super.onRequest(request);
198200
});
199201
}

0 commit comments

Comments
 (0)