Skip to content

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Jul 9, 2025

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:

  • Added a new MCPTimeout field to the Config 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].
  • Updated the help map to include a description for the mcp-timeout option.
  • Integrated the MCPTimeout value into context creation for MCP server calls, replacing hardcoded timeouts [1] [2] [3].

Context and Concurrency Improvements:

  • Refactored the Mods struct to manage multiple cancel functions (cancelRequest changed from a single context.CancelFunc to a slice) and added a shared context field (ctx) for centralized context management [1] [2] [3].
  • Improved concurrency in MCP tool listing by using errgroup.Group for parallel execution and a mutex to safely update shared data.
  • Enhanced error handling for MCP tool listing, including specific handling for context deadline exceeded errors.

Type Updates:

  • Replaced the interface{} type with any 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.

caarlos0 added 2 commits July 9, 2025 14:41
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0 caarlos0 requested review from bashbunni and Copilot July 9, 2025 17:44
@caarlos0 caarlos0 self-assigned this Jul 9, 2025
@caarlos0 caarlos0 added the bug Something isn't working label Jul 9, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 to Config with default and YAML/env support.
  • Refactors Mods to use a shared ctx and a slice of cancel functions, and wires MCPTimeout into all MCP contexts.
  • Parallelizes tool listing via errgroup, updates interface{} to any, 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 to cancelRequests or cancelFuncs would more clearly communicate its purpose.
	cancelRequest []context.CancelFunc

mcp.go:118

  • Using context.Background() here bypasses the passed-in ctx, ignoring timeouts and cancellations. Replace with client.CallTool(ctx, request).
		return "", fmt.Errorf("mcp: invalid tool name: %q", name)

@bashbunni
Copy link
Contributor

bashbunni commented Jul 9, 2025

image

1st is main 2nd is this branch
Looks good. I think it could be helpful to make the message "timeout while listing tools for "github" - make sure the configuration is correct. If your server requires a docker container, make sure it's running"

I could totally see that tripping people up! (Not me or anything 😂 )

caarlos0 and others added 3 commits July 10, 2025 11:29
Co-authored-by: bashbunni <15822994+bashbunni@users.noreply.github.com>
@caarlos0 caarlos0 merged commit 9b36cf8 into main Jul 10, 2025
16 checks passed
@caarlos0 caarlos0 deleted the mcp-timeouts branch July 10, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants