on main help sign in
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 <crush@charm.land>

commitcda2719416c1bad7291017db3c5f5e1b93795c2c authoriceymoss <114280774+iceymoss@users.noreply.github.com> dateWed 1 Apr 2026, 03:33 (7 months ago) parent97c9f4b
1 file changed+7−2
internal/commands/commands.go+7−2
internal/commands/commands.go+7−2
@@ -7,6 +7,7 @@ import (
77 "path/filepath"
88 "regexp"
99 "strings"
10+ "time"
1011
1112 "github.com/charmbracelet/crush/internal/agent/tools/mcp"
1213 "github.com/charmbracelet/crush/internal/config"
@@ -221,8 +222,12 @@ func isMarkdownFile(name string) bool {
221222}
222223
223224func GetMCPPrompt(cfg *config.ConfigStore, clientID, promptID string, args map[string]string) (string, error) {
224− // TODO: we should pass the context down
225− result, err := mcp.GetPromptMessages(context.Background(), cfg, clientID, promptID, args)
225+ // Create a context with timeout since tea.Cmd doesn't support context passing.
226+ // The MCP client has its own timeout, but this provides an additional safeguard.
227+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
228+ defer cancel()
229+
230+ result, err := mcp.GetPromptMessages(ctx, cfg, clientID, promptID, args)
226231 if err != nil {
227232 return "", err
228233 }