feat: make MCP tool request timeout configurable#262
Conversation
WalkthroughThis PR adds configurable MCP tool-call request timeout throughout the system. The timeout flows from configuration schema and daemon CLI flags, through API options and route registration, into request handlers that apply it as a context deadline. All configuration paths and timeout application are tested. ChangesMCP Request Timeout Configuration
Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/daemon.go`:
- Around line 147-148: Add a CLI flag so mcpRequest can be overridden like the
other timeouts: define a new flag constant (e.g., flagMCPRequestTimeout) and add
a corresponding flag in newDaemonCobraCmd alongside the existing
apiShutdown/mcpInit/mcpShutdown/healthCheck flags, then update
loadConfigMCPTimeout to check the new flag and override the config value when
present; target the mcpRequest field and the new flag name in your changes so
the CLI takes precedence over config when provided.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 41e9c53b-008a-4f87-9785-13cb48be99a0
📒 Files selected for processing (11)
cmd/daemon.gocmd/daemon_test.godocs/daemon-configuration.mdinternal/api/routes.gointernal/api/servers.gointernal/api/servers_test.gointernal/api/tools.gointernal/config/daemon_config.gointernal/config/daemon_config_test.gointernal/daemon/api_options.gointernal/daemon/api_server.go
| // mcpRequest specifies how long to wait for MCP tool call requests. | ||
| mcpRequest string |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Consider adding a CLI flag for consistency.
All other timeout settings (apiShutdown, mcpInit, mcpShutdown, healthCheck) have corresponding CLI flags defined in newDaemonCobraCmd, but mcpRequest does not. This means the MCP request timeout can only be configured via the config file, not via command-line flags, which is inconsistent with the other timeouts and limits runtime configurability.
🔧 Add CLI flag for parity with other timeouts
Add a flag constant and flag definition in newDaemonCobraCmd:
const (
// flagTimeoutMCPShutdown is the flag name for timeout when shutting down the MCP client.
flagTimeoutMCPShutdown = "timeout-mcp-shutdown"
+
+ // flagTimeoutMCPRequest is the flag name for MCP tool call request timeout.
+ flagTimeoutMCPRequest = "timeout-mcp-request"
// flagIntervalMCPHealth is the flag name for MCP server health check interval.
flagIntervalMCPHealth = "interval-mcp-health"Then add the flag in newDaemonCobraCmd after the other timeout flags:
cobraCommand.Flags().StringVar(
&daemonCmd.config.timeout.mcpShutdown,
flagTimeoutMCPShutdown,
daemon.DefaultClientShutdownTimeout().String(),
"Timeout in seconds to wait for shutdown of MCP servers (e.g. 5s, 10s)",
)
+
+ cobraCommand.Flags().StringVar(
+ &daemonCmd.config.timeout.mcpRequest,
+ flagTimeoutMCPRequest,
+ daemon.DefaultToolCallTimeout().String(),
+ "Timeout in seconds to wait for MCP tool call requests (e.g. 5s, 15s)",
+ )And add flag override logic in loadConfigMCPTimeout:
// Handle MCP request timeout.
if timeout.Request != nil {
parsed := timeout.Request.String()
- logger.Debug("Using config file value", "setting", "mcp.timeout.request", "value", parsed)
- c.config.timeout.mcpRequest = parsed
+
+ if cmd.Flags().Changed(flagTimeoutMCPRequest) {
+ warnings = append(
+ warnings,
+ flagOverrideWarning(flagTimeoutMCPRequest, parsed, c.config.timeout.mcpRequest),
+ )
+ logger.Debug("Flag overriding config value", "flag", flagTimeoutMCPRequest,
+ "config", parsed, "using", c.config.timeout.mcpRequest)
+ } else {
+ logger.Debug("Using config file value", "setting", "mcp.timeout.request", "value", parsed)
+ c.config.timeout.mcpRequest = parsed
+ }
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/daemon.go` around lines 147 - 148, Add a CLI flag so mcpRequest can be
overridden like the other timeouts: define a new flag constant (e.g.,
flagMCPRequestTimeout) and add a corresponding flag in newDaemonCobraCmd
alongside the existing apiShutdown/mcpInit/mcpShutdown/healthCheck flags, then
update loadConfigMCPTimeout to check the new flag and override the config value
when present; target the mcpRequest field and the new flag name in your changes
so the CLI takes precedence over config when provided.
Summary
mcp.timeout.requestto daemon config get/set/list handling.docs/daemon-configuration.md.Verification
go test ./internal/config ./internal/api ./internal/daemon ./cmdgo test ./...git diff --checkSummary by CodeRabbit
Release Notes
New Features
mcp.timeout.requestparameter, with a default of 15 seconds.Documentation