feat(agents) Add MCP toolset support - #2492
paulheinrichs-jb wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 9565a9f The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
f90155e to
3da834b
Compare
|
@chenghao-mou - Noticed you were assigned to the old one but noticed it was quite outdated. I took a pass at it, i was a bit conscious of the "ongoing" work in the Please let me know if you have any thoughts / opinions or would prefer to take it on yourself. The mcp_agent works as anticipated connecting with livekits mcp server. |
3da834b to
330471b
Compare
330471b to
08603d5
Compare
13a3f10 to
48d8002
Compare
There was a problem hiding this comment.
Note
This report is out of date. Scroll down for Devin Review's latest report on this PR.
Devin Review found 4 new potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| ) | ||
| .join('\n'), | ||
| ); | ||
| return await this.toolResultResolver({ toolName: name, arguments: args, result }); |
There was a problem hiding this comment.
🔴 Pending resolver blocks MCP shutdown
When toolResultResolver never settles, the default non-cancellable MCP tool remains active after its request completes. MCPToolset.aclose() then waits forever while draining it.
Learn more
clientSessionTimeout bounds only SDK requests. The custom result resolver runs afterward and receives no abort signal or deadline. MCP tools default to non-cancellable, so drain awaits the resolver's raw promise without a deadline. The bounded-request shutdown branch therefore relies on a bound that does not cover the complete tool execution.
Example: A resolver awaits a database lookup that never returns. The MCP server responds within one second, but the resolver stays pending. Closing the session calls MCPToolset.aclose(), and executor drain never reaches server cleanup.
Recommended fix: Make resolver completion bounded or cancellable as part of MCP tool execution. Pass an abort signal to the resolver and abort it during teardown, or enforce a resolver timeout aligned with clientSessionTimeout. Ensure shutdown does not await an arbitrary resolver promise indefinitely.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
This is an MCP-specific instance of the broader hung-tool behavior tracked in #2428. We’re avoiding an MCP-only timeout so the eventual framework-level solution can consistently cover the complete tool execution, including custom result resolvers.
48d8002 to
db407fd
Compare
There was a problem hiding this comment.
Devin Review found 2 new potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
db407fd to
9565a9f
Compare
• ## Summary
Adds Model Context Protocol (MCP) tool support to Agents JS through the current
MCPToolsetlifecycle.MCPServerHTTP,MCPServerStdio, andMCPToolset.@modelcontextprotocol/sdkpeer dependency, loaded only when MCP is used.notifications/tools/list_changed.ToolError.Why this API
This intentionally uses
MCPToolsetthroughtools: [...], rather than adding directmcpServersoptions toAgentorAgentSession.That matches the current Python direction:
mcp_serversconfiguration in favor ofMCPToolset: livekit/agents#5667MCPToolsetwith per-tool options: mcp.py, MCPToolsetThe optional peer dependency preserves the original JS MCP PR’s goal: applications that do not use MCP do not need to install the MCP SDK. agents-js#1451
Parity and reliability choices
ToolError. This is exact Python parity: default resolver._DEFAULT_TOOL_OPTIONS: mcp.py.Verification
Pre-Review Checklist
Testing
ToolErrorAbortSignalpropagation to MCP SDK callspnpm exec vitest run agents/src/llm/mcp.test.tspnpm --filter @livekit/agents typecheckpnpm --filter @livekit/agents buildpnpm --filter @livekit/agents api:updategit diff --checkAdditional Notes
Note to reviewers: Please ensure the pre-review checklist is completed before starting your review.