Skip to content

fix(chats): give MCP connector tool calls the MCP tool timeout - #13043

Closed
walcz-de wants to merge 1 commit into
mudler:masterfrom
walcz-de:fix/connector-mcp-tool-timeout
Closed

walcz-de wants to merge 1 commit into
mudler:masterfrom
walcz-de:fix/connector-mcp-tool-timeout

Conversation

@walcz-de

@walcz-de walcz-de commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Description

A tool call through an MCP connector (the MCP servers users add under Chats, Connectors) is cut after 60 seconds, the mcpconns.DefaultCallTimeout, because initStudioMCPConnectors never sets CallTimeout. The model's own MCP servers allow 360 seconds (DistributedConfig.MCPToolTimeoutOrDefault, DefaultMCPToolTimeout). Research and document tools behind a connector often need several minutes, so a chat or saved agent loses them mid-turn with

connection closed: calling tools/call: client is closing

and the model falls back to a weaker tool.

What the change does: initStudioMCPConnectors passes CallTimeout: a.studioMCPCallTimeout(), which returns applicationConfig.Distributed.MCPToolTimeoutOrDefault() — the same timeout the rest of LocalAI uses for MCP tool calls (360 s unless configured otherwise). The mcpconns package default and the 64 KiB per-call output cap are unchanged.

How it was tested

New Ginkgo specs in core/application/studio_mcpconns_timeout_internal_test.go start the connector service on JSON stores against a local MCP server (httptest) with one tool that sleeps:

  • with no MCP tool timeout configured, the connector call timeout equals config.DefaultMCPToolTimeout (and is longer than mcpconns.DefaultCallTimeout);
  • with an MCP tool timeout of 3 s, a tool that takes 1.2 s returns its result;
  • with an MCP tool timeout of 300 ms, a tool that takes 5 s is stopped well before it finishes (< 3 s). This spec shows the timeout is actually wired into the service: with only the CallTimeout: line removed, this spec fails ("Expected an error to have occurred"), the other two pass; with the line it passes.
go test -tags "debug auth" ./core/application/... ./core/services/studio/mcpconns/... ./core/services/studio/... ./core/http/routes/...
ok  	github.com/mudler/LocalAI/core/application	16.519s
ok  	github.com/mudler/LocalAI/core/services/studio/mcpconns	0.486s
ok  	github.com/mudler/LocalAI/core/services/studio	49.478s
ok  	github.com/mudler/LocalAI/core/http/routes	33.344s
(other subpackages ok; see note below)

All packages pass except core/services/studio/store, spec "the GORM store on SQLite: a turn that stops beating is reaped, one that keeps beating is not" (storetest/contract.go:590, both turns reaped). It fails the same way on unmodified master 5b2414f (also with TZ=UTC), and this PR does not touch that package.

gofmt -l is clean and go vet -tags "debug auth" reports nothing for ./core/application/.

Docs

docs/content/features/chats-connectors.md, "How chats use them", Limits: the call time limit is now the MCP tool timeout (360 seconds) instead of 60 seconds.

Signed commits

  • Yes, I signed my commits.
  • Documentation updated (docs/content/) for user-facing changes, or not applicable

The commit carries an Assisted-by: trailer per .agents/ai-coding-assistants.md.

A tool call through an MCP connector was cut after the connector
package default of 60 seconds, while the model's own MCP servers allow
360 seconds. Research and document tools behind a connector take
minutes, so a saved agent lost them mid-turn with "connection closed:
calling tools/call: client is closing" and the model fell back to a
weaker tool.

The connector service now gets the MCP tool timeout the rest of
LocalAI uses (DistributedConfig.MCPToolTimeoutOrDefault, 360 s by
default). The package default and the per-call output cap are
unchanged.

Tests in core/application start the connector service on JSON stores
against a slow MCP server: the timeout defaults to the MCP tool
timeout, a tool slower than the old cap but within the timeout
returns, and a tool past the timeout is still stopped.

Docs: chats-connectors.md, "How chats use them".

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
@mudler-agent

Copy link
Copy Markdown
Collaborator

Thank you for this fix. It is now on master, bundled with a few related fixes in #13044, with your commits and authorship kept (MCP connector call timeout). Some small follow-up changes were needed while rebasing on current master; they are in the same series. Closing this PR as it is now redundant.

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.

2 participants