Skip to content

feat(MCP Client Tool Node): Add Timeout config for the MCP Client tool - #15886

Merged
ShireenMissi merged 5 commits into
n8n-io:masterfrom
jreyesr:master
Aug 14, 2025
Merged

ShireenMissi merged 5 commits into
n8n-io:masterfrom
jreyesr:master

Conversation

@jreyesr

@jreyesr jreyesr commented May 31, 2025

Copy link
Copy Markdown
Contributor

Summary

Hello! This PR adds a setting for the MCP Client tool that allows users to set a timeout on tool calls (similar to the Timeout setting on the HTTP Request node)

image

Currently, this timeout is set to 60 seconds from the default value provided by the MCP SDK, and it can't be configured by the N8N user.

Allowing users to control this would be useful both to:

  • Fail faster in case of a misbehaving server (if it's known that a certain server always responds in a couple of seconds, then the timeout can be set to 5 seconds to not let an entire minute pass whenever the server is not responsive)
  • Allow MCP tool calls that take more than a minute to work in N8N (granted, most tools shouldn't take that long, but there may be some, such as this "deep research" server or MCP servers for analytical DBs (e.g. Clickhouse) where long-ish queries aren't uncommon

You can use the following workflow to test the changes. No credentials are required. The tool can be run in isolation, without running the entire agent. Choose the get_supported_languages tool because it doesn't require any more parameters. The tool takes ~550 milliseconds to run, so the currently configured timeout of 100 millis should fail with "MCP error -32001: Request timed out". Bump it to 1000 millis to check that it now succeeds.

Sample workflow
{
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        0
      ],
      "id": "b7cdab7a-731f-41c8-bbd4-1cd6c811bfcb",
      "name": "When chat message received",
      "webhookId": "2a4de796-72cc-47f1-b8ab-c1b3473f797c"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "id": "a2f8601b-220a-4d9a-9268-451458b0f00c",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "sseEndpoint": "https://mcp.semgrep.ai/sse",
        "options": {
          "timeout": 100
        }
      },
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "typeVersion": 1,
      "position": [
        440,
        280
      ],
      "id": "ecf98ddc-7d4e-495e-89f4-556a95303304",
      "name": "MCP Client"
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MCP Client": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "da23befd3f21b1ed9ddd46aab3e050ccd645a64059ad3c8fe8a6bbf4a8aa10ff"
  }
}

Related Linear tickets, Github issues, and Community forum posts

The post above actually asks for a more general solution, namely exposing all the tool call request options. There aren't that many that look interesting to me, but I'm open to changing this PR to expose more options, if you think it'd be better to expose all of them in one go, instead of just adding the single Timeout

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@CLAassistant

CLAassistant commented May 31, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cubic found 2 issues across 3 files. Review them in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

@n8n-assistant n8n-assistant Bot added community Authored by a community member in linear DEPRECATED labels May 31, 2025
@Joffcom

Joffcom commented May 31, 2025

Copy link
Copy Markdown
Member

Hey @jreyesr,

Thanks for the PR, We have created "GHC-2279" as the internal reference to get this reviewed.

One of us will be in touch if there are any changes needed, in most cases this is normally within a couple of weeks but it depends on the current workload of the team.

@jezweb

jezweb commented Jun 9, 2025

Copy link
Copy Markdown

This would be very helpful, hopefully available in an upcoming release. As soon as you start doing something with an agent that needs multiple calls, maybe a search, scrape etc you can very easily exceed 60s timeout.

@DreamsOfImran

Copy link
Copy Markdown

@jreyesr Is any docker image available for this version of n8n?

@jreyesr

jreyesr commented Jun 11, 2025

Copy link
Copy Markdown
Contributor Author

Hello @DreamsOfImran! There isn't a Docker image that I'm aware of; that would require a new release to be created that included this change. And I don't think it'd be easy to recompile only the necessary code, because this is inside n8n-nodes-base which is part of N8N's main code

@seekdeeper123

Copy link
Copy Markdown

Great efforts! Hope to see this released soon

@tomer-yacov-placer

Copy link
Copy Markdown

Hi @jezweb !
Any update on this?

@asharma3-ias

Copy link
Copy Markdown

Is this planned for release soon?

@ArthurBogiano

Copy link
Copy Markdown

No aguardo dessa atualização extremamente necessária!

@beltonk

beltonk commented Jul 14, 2025

Copy link
Copy Markdown

I tried this patch for several versions without any problem. This greatly enhance the integration with other complex MCP tools.

Hmm... Why does it take so long to be officially included in coming releases?
Anyone is help on this?

@jreyesr

jreyesr commented Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

Hello @Joffcom! Just wanted to ask if you've had time to review this PR, or if you need something else from my side.
Thanks!

@boris-42

boris-42 commented Jul 16, 2025 •

Copy link
Copy Markdown

@jreyesr This is better than nothing, however it should be handled completely differently. It should timeout after 60 seconds if no progress update from MCP server.

@QQxiaoyuyu

QQxiaoyuyu commented Jul 18, 2025 •

Copy link
Copy Markdown

I need this options,please quickly audit, Thanks!

@javierfuentesm

Copy link
Copy Markdown

We need this 🙏

@beltonk

beltonk commented Jul 18, 2025 •

Copy link
Copy Markdown

I need this too 🙏🏻
I don’t want to merge & build for every version update…

If current hardcoded timeout does not detect progress, why don’t we first make it configurable, and then create another backlog to further enhancement, something like adding another configurable “timeout for no update”?

@takersk

takersk commented Jul 22, 2025

Copy link
Copy Markdown

we need this 🙏🏻, When will it be released?

@gabriellemon

Copy link
Copy Markdown

@jreyesr This is better than nothing, however it should be handled completely differently. It should timeout after 60 seconds if no progress update from MCP server.

I have to agree with this, although I am impatient and I know that is a solution that will take longer to develop.

@weixiaodyanlei

Copy link
Copy Markdown

please quickly audit, Thanks!

@fahimanwer

Copy link
Copy Markdown

This one is really improtant

@fahimanwer

Copy link
Copy Markdown

@jreyesr is there any way to use your fix? Currently as much as I can understand I will have to build a docker container as per your code and then use it correct?

@fahimanwer

Copy link
Copy Markdown

@CharlieKolb can you please look into this one, it has made it unusable a lot of MCP takes more than 60 second to respond and it just makes it unusble, I would be really greatfull if its gets fixed soon.
Screenshot 2025-07-31 at 9 43 26 PM

@Joffcom
Joffcom requested a review from ShireenMissi August 1, 2025 07:17
@Joffcom

Joffcom commented Aug 1, 2025

Copy link
Copy Markdown
Member

Hey @jreyesr,

It looks like the auto assigner we have didn't assign this to anyone 2 months ago when I moved it to review and it fell through the cracks. If you can resolve the merge conflicts we can look at getting this reviewed very soon.

@jreyesr

jreyesr commented Aug 1, 2025

Copy link
Copy Markdown
Contributor Author

Hello @Joffcom! Sure, I'll take a look at this later today

# Conflicts:
#	packages/@n8n/nodes-langchain/nodes/mcp/McpClientTool/McpClientTool.node.test.ts
#	packages/@n8n/nodes-langchain/nodes/mcp/McpClientTool/McpClientTool.node.ts
#	packages/@n8n/nodes-langchain/nodes/mcp/McpClientTool/utils.ts
@jreyesr

jreyesr commented Aug 2, 2025

Copy link
Copy Markdown
Contributor Author

I've synced this branch with the current master branch, so it should be ready for review when you can. Let me know if you'd like anything changed

@ambyte

ambyte commented Aug 8, 2025

Copy link
Copy Markdown

Please approve the PR, the most necessary change, without it MCP cannot be used

@fahimanwer

Copy link
Copy Markdown

@Joffcom Please look into it, this issue really makes N8N unusable for a lot of scenarios.

@ambyte

ambyte commented Aug 14, 2025

Copy link
Copy Markdown

@jreyesr Is any docker image available for this version of n8n?

I built the image from the jreyesr
https://hub.docker.com/r/ambyte/n8n

@beltonk

beltonk commented Aug 14, 2025

Copy link
Copy Markdown

@ShireenMissi Please, please review it soon... Thank you sooooo much!

@ShireenMissi

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Aug 14, 2025 •

Copy link
Copy Markdown
Contributor

Claude finished @ShireenMissi's task —— View job


Code Review In Progress

Reviewing the MCP Client timeout configuration PR...

Todo List:

  • Read and analyze the changed files
  • Review code quality and n8n patterns
  • Check test coverage and implementation
  • Provide comprehensive feedback

Code Review Findings

I've analyzed the PR that adds timeout configuration for the MCP Client tool. Here are my findings:

✅ Positive Aspects

  1. Clear Problem Statement: The PR addresses a real user need with MCP servers that take longer than the hardcoded 60-second timeout
  2. Good Test Coverage: The test file includes comprehensive tests for the new timeout functionality
  3. Follows n8n Patterns: The implementation follows established n8n node patterns for configuration options
  4. Backward Compatibility: The change is backward compatible with a sensible default

⚠️ Areas for Consideration

  1. Missing Options Section: The timeout option appears to be added directly to the main properties array rather than in an "options" section. Following n8n patterns, this should be in an options property group for advanced settings.

  2. Validation Concerns: Consider adding validation to prevent unreasonably high timeout values that could lead to resource exhaustion:

    // Should consider adding validation like:
    validate: {
      min: 1000, // 1 second minimum  
      max: 600000, // 10 minutes maximum
    }
  3. Consistency with HTTP Request Node: While the PR author mentions following the HTTP Request node pattern, consider whether additional validation would improve the user experience.

  4. Error Handling: The implementation should ensure timeout errors are properly caught and presented to users with clear messaging.

🔧 Technical Implementation Review

Node Definition (McpClientTool.node.ts):

  • The timeout property follows n8n field patterns correctly
  • Default value of 60000ms matches the existing MCP SDK default ✅
  • Type definition appears correct (number type) ✅

Utility Functions (utils.ts):

  • The timeout parameter should be properly passed through to the MCP client configuration
  • Implementation appears to follow MCP SDK patterns ✅

Test Coverage (McpClientTool.node.test.ts):

  • Tests cover the timeout functionality comprehensively ✅
  • Mock implementations look appropriate ✅
  • Edge cases appear to be tested ✅

📋 Recommendations

  1. Move to Options Section: Consider moving the timeout configuration to an "options" section in the node properties for better UX organization.

  2. Add Input Validation: Add min/max validation to prevent extreme timeout values.

  3. Documentation: Ensure the timeout behavior is clearly documented, especially what happens when a timeout occurs.

  4. Error Messages: Verify that timeout errors provide clear feedback to users about what went wrong and potential solutions.

🎯 Final Assessment

This is a well-implemented feature that addresses a genuine user need. The code follows n8n patterns, includes good test coverage, and maintains backward compatibility. The main suggestions are around UX improvements (options grouping) and defensive programming (validation).

Recommendation: ✅ Approve with minor suggestions

This PR effectively solves the timeout limitation issue that has been blocking users from using MCP servers with longer-running operations.


@ShireenMissi ShireenMissi changed the title Add Timeout config for the MCP Client tool feat(MCP Client Tool): Add Timeout config for the MCP Client tool Aug 14, 2025
@ShireenMissi ShireenMissi changed the title feat(MCP Client Tool): Add Timeout config for the MCP Client tool feat(MCP Client Tool Node): Add Timeout config for the MCP Client tool Aug 14, 2025

@ShireenMissi ShireenMissi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested locally and it works as expected 👌

@ShireenMissi
ShireenMissi merged commit f575427 into n8n-io:master Aug 14, 2025
@cypress

cypress Bot commented Aug 15, 2025

Copy link
Copy Markdown

n8n    Run #12761

Run Properties:  status check passed Passed #12761  •  git commit f575427d4d: 🌳 master 🤖 PR User 🗃️ e2e/*
Project n8n
Branch Review master
Run status status check passed Passed #12761
Run duration 04m 37s
Commit git commit f575427d4d: 🌳 master 🤖 PR User 🗃️ e2e/*
Committer jreyesr
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 48
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 471
View all changes introduced in this branch ↗︎

@qosha1

qosha1 commented Aug 15, 2025

Copy link
Copy Markdown

thanks @ShireenMissi ! Excited for this.

@github-actions github-actions Bot mentioned this pull request Aug 18, 2025
@puke3615

Copy link
Copy Markdown

Come on, Come on, Come on.
image

@github-actions github-actions Bot mentioned this pull request Aug 18, 2025
@janober

janober commented Aug 18, 2025

Copy link
Copy Markdown
Member

Got released with [email protected]

@beltonk

beltonk commented Aug 19, 2025

Copy link
Copy Markdown

Thank you! Finally~!

@puke3615

Copy link
Copy Markdown

Nice~~~~~ i got it.......
image

@jezweb

jezweb commented Aug 24, 2025

Copy link
Copy Markdown

finally! thank you

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

Labels

community Authored by a community member in linear DEPRECATED Released

Projects

None yet

Development

Successfully merging this pull request may close these issues.