Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/smooth-rats-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"agents": patch
---

### Breaking

- ClientConnection.init() no long tries discovery automatically. That should be done from the MCPCLientManager after explicitely setting the server to "discovering"

### Features

- New discoverIfConnected() function on MCPClientManager which allows for simpler discover of my capabilities per server.

### Fixes

- MCP Client Discovery failures now throw errors immediately instead of continuing with empty arrays
- Added new "connected" MCP Connection State to use for a connected server with no tools loaded
- Created the enum MCPConnectionState to formalise possible states
26 changes: 11 additions & 15 deletions packages/agents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,10 +1449,11 @@ export class Agent<
}
});

// Connect to server (updates storage with auth URL if OAuth)
// This fires onServerStateChanged event which triggers broadcast
const result = await this.mcp.connectToServer(id);

// If state is connected then this is an non oauth connection and we should try discovery.
await this.mcp.discoverIfConnected(id);

return {
id,
authUrl: result.state === "authenticating" ? result.authUrl : undefined
Expand Down Expand Up @@ -1538,21 +1539,16 @@ export class Agent<

// If auth was successful, establish the connection in the background
if (result.authSuccess) {
this.broadcastMcpServers();

this.mcp
.establishConnection(result.serverId)
.catch((error) => {
console.error(
"[Agent handleMcpOAuthCallback] Connection establishment failed:",
error
);
})
.finally(() => {
this.broadcastMcpServers();
});
this.mcp.establishConnection(result.serverId).catch((error) => {
console.error(
"[Agent handleMcpOAuthCallback] Connection establishment failed:",
error
);
});
}

this.broadcastMcpServers();

// Return the HTTP response for the OAuth callback
return this.handleOAuthCallbackResponse(result, request);
}
Expand Down
Loading
Loading