From cda2719416c1bad7291017db3c5f5e1b93795c2c Mon Sep 17 00:00:00 2001 From: iceymoss <114280774+iceymoss@users.noreply.github.com> Date: Wed, 1 Apr 2026 03:33:35 +0800 Subject: [PATCH] fix(commands): add timeout context for MCP prompt retrieval (#2517) The GetMCPPrompt function was using context.Background() without any timeout, which could cause the request to hang indefinitely. Since tea.Cmd doesn't support context passing, we add a 30-second timeout as a safeguard, consistent with the pattern used in OAuth modules. Assisted-by: GLM-5 via Crush --- internal/commands/commands.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/commands/commands.go b/internal/commands/commands.go index 786f99019d737b32affb44392e0262ca069ab1d2..65192c59e276cec5d3eabb2cc1250a437139797c 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -7,6 +7,7 @@ import ( "path/filepath" "regexp" "strings" + "time" "github.com/charmbracelet/crush/internal/agent/tools/mcp" "github.com/charmbracelet/crush/internal/config" @@ -221,8 +222,12 @@ func isMarkdownFile(name string) bool { } func GetMCPPrompt(cfg *config.ConfigStore, clientID, promptID string, args map[string]string) (string, error) { - // TODO: we should pass the context down - result, err := mcp.GetPromptMessages(context.Background(), cfg, clientID, promptID, args) + // Create a context with timeout since tea.Cmd doesn't support context passing. + // The MCP client has its own timeout, but this provides an additional safeguard. + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + result, err := mcp.GetPromptMessages(ctx, cfg, clientID, promptID, args) if err != nil { return "", err }