-
Notifications
You must be signed in to change notification settings - Fork 179
fix: improve mcp timeout handling #551
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
Conversation
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a configurable timeout for MCP calls, refactors context and cancellation handling in Mods
, and modernizes type usage in the codebase.
- Adds
MCPTimeout
toConfig
with default and YAML/env support. - Refactors
Mods
to use a sharedctx
and a slice of cancel functions, and wiresMCPTimeout
into all MCP contexts. - Parallelizes tool listing via
errgroup
, updatesinterface{}
toany
, and replaces hardcoded timeouts.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
mods.go | Changed cancelRequest to slice, added ctx field, and integrated MCPTimeout |
mcp.go | Switched to iter.Seq2 , added errgroup parallelism, and mutex for results |
main.go | Passed CLI context into newMods , applied MCPTimeout to timeouts |
config.go | Added MCPTimeout field and help text; updated YAML unmarshal signature |
config_template.yml | Added default mcp-timeout entry |
Comments suppressed due to low confidence (2)
mods.go:66
- [nitpick] The field
cancelRequest
is now a slice of cancel functions; renaming it tocancelRequests
orcancelFuncs
would more clearly communicate its purpose.
cancelRequest []context.CancelFunc
mcp.go:118
- Using
context.Background()
here bypasses the passed-inctx
, ignoring timeouts and cancellations. Replace withclient.CallTool(ctx, request)
.
return "", fmt.Errorf("mcp: invalid tool name: %q", name)
1st is I could totally see that tripping people up! (Not me or anything 😂 ) |
Co-authored-by: bashbunni <15822994+bashbunni@users.noreply.github.com>
This pull request introduces a configurable timeout for MCP server calls, refactors context handling to improve cancellation and concurrency, and updates type usage for better code consistency. The most significant changes are grouped into three themes: MCP timeout configuration, context and concurrency improvements, and type updates.
MCP Timeout Configuration:
MCPTimeout
field to theConfig
struct with a default value of 15 seconds. This timeout is configurable via YAML and environment variables (yaml:"mcp-timeout" env:"MCP_TIMEOUT"
) [1] [2] [3].help
map to include a description for themcp-timeout
option.MCPTimeout
value into context creation for MCP server calls, replacing hardcoded timeouts [1] [2] [3].Context and Concurrency Improvements:
Mods
struct to manage multiple cancel functions (cancelRequest
changed from a singlecontext.CancelFunc
to a slice) and added a shared context field (ctx
) for centralized context management [1] [2] [3].errgroup.Group
for parallel execution and a mutex to safely update shared data.Type Updates:
interface{}
type withany
in YAML unmarshaling and error handling for improved readability and modern Go practices [1] [2] [3] [4].These changes collectively enhance the configurability, robustness, and maintainability of the codebase.