Skip to content

Add Timeout config for the MCP Client tool #15886

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jreyesr
Copy link

@jreyesr jreyesr commented May 31, 2025

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
Copy link

CLAassistant commented May 31, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

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

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.

displayName: 'Timeout',
name: 'timeout',
type: 'number',
typeOptions: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a maxValue to prevent users from setting excessively long timeouts that could lead to resource exhaustion.

Copy link
Author

Choose a reason for hiding this comment

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

Should this be done? I lifted this straight from the HTTP Request node, where it doesn't have a max either. And I don't feel quite comfortable setting a hard cap on behalf of users, they'll know better than me what they need

typeOptions: {
minValue: 1,
},
default: 60000,
Copy link
Contributor

Choose a reason for hiding this comment

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

The default timeout value (60000ms) in the UI doesn't match the value mentioned in the PR description (default is described as being set to 60 seconds in the MCP SDK).

Copy link
Author

Choose a reason for hiding this comment

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

Am I crazy, or is it the bot? I swear 60000ms===60 seconds :)

@n8n-assistant n8n-assistant bot added community Authored by a community member in linear Issue or PR has been created in Linear for internal review labels May 31, 2025
@Joffcom
Copy link
Member

Joffcom commented May 31, 2025

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.

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 Issue or PR has been created in Linear for internal review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants