fix(mcp): make setup timeout configurable#291
Conversation
| if serverCfg.Timeout > 0 { | ||
| setupTimeout = serverCfg.Timeout | ||
| } |
There was a problem hiding this comment.
JSON serialization issue with time.Duration: Go's time.Duration is an int64 (nanoseconds) and does not implement json.Marshaler/json.Unmarshaler. This means:
- When saved to the JSON config file via
saveConfig, the timeout will be stored as a raw nanosecond integer (e.g.,1800000000000for 30 minutes), which is not human-readable. - If a user manually edits the JSON config and writes
"timeout": "30m",json.UnmarshalinloadOrCreateConfig/LoadAppConfigwill fail because it expects a number, not a string.
Consider using a custom type that implements json.Marshaler/json.Unmarshaler to serialize/deserialize as a human-readable duration string (e.g., "30m"), or use a string field and parse it at point-of-use.
lizhengfeng101
left a comment
There was a problem hiding this comment.
1. Field type & naming — timeout (time.Duration)
Two issues with the current Timeout time.Duration:
- Serialization is opaque and fragile.
time.Durationhas no JSON string form, so30mis written toconfig.jsonas nanoseconds:"timeout": 1800000000000. Worse, if a user hand-edits the file to the documented"30m", the entire config fails to load (cannot unmarshal string into ... time.Duration). timeoutis too broad a name. At the MCP-server level it reads like a connection/request timeout, but it only bounds thesetupcommand.
Suggest storing a plain positive integer in minutes and renaming the field to tie it to setup — setup_timeout:
SetupTimeout int `json:"setup_timeout,omitempty"` // minutescase "setup_timeout":
n, err := strconv.Atoi(value)
if err != nil || n <= 0 {
return fmt.Errorf("invalid value for %s: must be a positive integer (minutes)", key)
}
entry.SetupTimeout = nsetupTimeout := 30 * time.Minute
if serverCfg.SetupTimeout > 0 {
setupTimeout = time.Duration(serverCfg.SetupTimeout) * time.Minute
}This stores "setup_timeout": 30 — readable and safe to hand-edit — and the name makes the association with setup explicit. Usage becomes ocr config set mcp_servers.<name>.setup_timeout 30. Since the value is a bare number in minutes, please state the unit clearly in the README/help text. (The time import in config_cmd.go is then no longer needed.)
2. Localized READMEs not synced
Per the repo convention, README changes must be mirrored to all localized copies. This PR updates README.md and README.zh-CN.md, but README.ja-JP.md, README.ko-KR.md, and README.ru-RU.md all contain the same MCP setup section — and still carry the stale "5-minute timeout" note. Please update those three as well.
3. New tests don't assert anything
TestInitMCPClients_SetupOnly and TestInitMCPClients_TimeoutConfig end with _ = clients and pass regardless of behavior — they don't actually verify the timeout feature. They also spawn a real echo and try to exec /nonexistent/cmd, so they carry environment side effects for no coverage gain. Consider asserting real behavior, e.g. a very short timeout against a sleep setup command should abort setup. The positive/negative cases in config_cmd_test.go are a good template.
Nits / positives
- Nice consistency: the field is threaded through the unknown-key error (
config_cmd.go), theflags.gohelp text, and thesetMCPServerValueerror. With the rename, update those same three strings and theconfig_cmd_test.gocases too. - Raising the default from 5m → 30m and documenting it is a sensible change on its own.
The MCP server setup command (e.g. codegraph init && codegraph index) previously had a hardcoded 5-minute timeout, which was too short for large repositories and caused the process to be killed. - Add `setup_timeout` field to mcp_servers config (default 30m), controlling the setup command's maximum execution time - Update config CLI, tests, and README docs accordingly
|
all fixed:
|
25b829c to
d25a5ae
Compare
Test feedback (
|
The MCP server setup command (e.g. codegraph init && codegraph index) previously had a hardcoded 5-minute timeout, which was too short for large repositories and caused the process to be killed.
timeoutfield to mcp_servers config (default 30m), controlling the setup command's maximum execution timeDescription
Type of Change
How Has This Been Tested?
make testpasses locallyChecklist
go fmt,go vet)Related Issues