Skip to content

feat(mcp-adapters): respect tool timeouts #8241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged

Conversation

benjamincburns
Copy link
Collaborator

fixes #8193

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 23, 2025
Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2025 5:11am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) May 28, 2025 5:11am

@benjamincburns benjamincburns requested a review from Copilot May 23, 2025 06:40
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for respecting per-tool timeouts (and abort signals) by forwarding LangChain's RunnableConfig into MCP SDK calls.

  • Extend _callTool to extract timeout and signal from RunnableConfig and pass them to client.callTool
  • Update loadMcpTools to wrap tool functions so they accept and forward config
  • Add unit and integration tests for timeout behavior, plus documentation in README

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
libs/langchain-mcp-adapters/src/tools.ts Implemented timeout/signal forwarding in _callTool and updated loader wraps
libs/langchain-mcp-adapters/tests/tools.test.ts Adjusted mock expectations to include the new config parameters
libs/langchain-mcp-adapters/tests/fixtures/dummy-http-server.ts Added sleep_tool to simulate delays
libs/langchain-mcp-adapters/tests/client.int.test.ts Added integration tests for respecting tool timeouts
libs/langchain-mcp-adapters/README.md Documented timeout configuration for MCP tools

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for respecting RunnableConfig timeouts and abort signals when calling MCP tools, updates the tool loader to forward these settings, augments tests to cover timeout behavior, and documents the new configuration options.

  • Forward timeout and signal from RunnableConfig into the MCP SDK call in _callTool
  • Update loadMcpTools to accept and pass along the optional config parameter
  • Add integration tests for timeout success and failure scenarios and extend the dummy server fixture
  • Document the new timeout configuration section in README.md

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
libs/langchain-mcp-adapters/src/tools.ts Extract and pass timeout/signal from RunnableConfig into client.callTool
libs/langchain-mcp-adapters/tests/tools.test.ts Adjust unit tests to expect the additional parameters on callTool
libs/langchain-mcp-adapters/tests/fixtures/dummy-http-server.ts Add a sleep_tool endpoint to simulate delay for timeout tests
libs/langchain-mcp-adapters/tests/client.int.test.ts Increase expected tool counts and add integration tests for timeout behavior
libs/langchain-mcp-adapters/README.md Introduce "Tool Timeout Configuration" section with examples and parameter table
Comments suppressed due to low confidence (2)

libs/langchain-mcp-adapters/src/tools.ts:182

  • Wrapping all non-ToolException errors in a ToolException can obscure the original TimeoutError type, making it harder for callers to catch timeouts specifically. Consider detecting and rethrowing TimeoutError (or AbortError) unmodified before the generic wrap.
throw new ToolException(`Error calling tool ${toolName}: ${String(error)}`);

libs/langchain-mcp-adapters/tests/tools.test.ts:125

  • There’s no unit test verifying that an abort signal from RunnableConfig is passed through to client.callTool. Adding a test that supplies an AbortSignal and asserts it appears in the third argument would improve coverage for cancellation behavior.
expect(mockClient.callTool).toHaveBeenCalledWith(

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label May 26, 2025
Base automatically changed from ben/mcp-error-headers to main May 28, 2025 04:13
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 28, 2025
@benjamincburns benjamincburns force-pushed the ben/mcp-tool-timeouts branch from 73dad70 to 4e0325b Compare May 28, 2025 04:59
@benjamincburns benjamincburns merged commit 0065c92 into main May 28, 2025
23 of 24 checks passed
@benjamincburns benjamincburns deleted the ben/mcp-tool-timeouts branch May 28, 2025 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PRs that are ready to be merged as-is size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mcp-adapters] Allow configuration of MCP tool call timeout
2 participants