Skip to content

Conversation

pawel-twardziak
Copy link

The timeout value from RunnableConfig was being lost when calling MCP tools because ensureConfig() converts it to an AbortSignal and removes the numeric timeout field. This prevented the MCP SDK from receiving explicit timeout values.

Changes:

  • Store original timeout in metadata.__lc_originalTimeoutMs in ensureConfig()
  • Retrieve and pass numeric timeout to MCP SDK RequestOptions in _callTool()
  • Add integration test verifying per-call timeout is properly honored

This ensures MCP tools respect timeouts passed through RunnableConfig, allowing callers to override default timeouts on a per-call basis.

Why deleting timeout is necessary (as it is so far)

  • Idempotent normalization: ensureConfig may be called multiple times down the stack. If timeout remains, each call would synthesize new timeout signals and combine them, changing the effective timeout unpredictably.
  • Single enforcement path: downstream code relies on signal to enforce cancellation. Leaving timeout means two competing mechanisms (numeric timeout and signal) can be applied, sometimes with different semantics.
  • Propagation to children: pickRunnableConfigKeys would keep forwarding timeout to nested runnables, causing repeated re-normalization and stacked timeouts.
  • Backward compatibility: a lot of components and tests assume ensureConfig removes timeout post-normalization; changing that would be a breaking change.

If an integration needs the numeric value later (e.g., to pass to an SDK that expects timeout), preserve it out-of-band (e.g., via metadata) and still use signal for actual cancellation.

Fixes #9136

…alls

The timeout value from RunnableConfig was being lost when calling MCP tools because ensureConfig() converts it to an AbortSignal and removes the numeric timeout field. This prevented the MCP SDK from receiving explicit timeout values.

Changes:
  - Store original timeout in metadata.__lc_originalTimeoutMs in ensureConfig()
  - Retrieve and pass numeric timeout to MCP SDK RequestOptions in _callTool()
  - Add integration test verifying per-call timeout is properly honored

This ensures MCP tools respect timeouts passed through RunnableConfig, allowing callers to override default timeouts on a per-call basis.
@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2025

⚠️ No Changeset found

Latest commit: b1a4d04

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Updated (UTC)
langchainjs-docs Ignored Ignored Oct 13, 2025 11:10pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long timeouts on MCP calls ignored

1 participant