on main help sign in
fix(commands): add timeout context for MCP prompt retrieval (#2517)
cda2719iceymoss
internal/commands/commands.go+7−2
@@ -7,6 +7,7 @@ import (
7 "path/filepath"
7 "path/filepath"
8 "regexp"
8 "regexp"
9 "strings"
9 "strings"
10+ "time"
10
11
11 "github.com/charmbracelet/crush/internal/agent/tools/mcp"
12 "github.com/charmbracelet/crush/internal/agent/tools/mcp"
12 "github.com/charmbracelet/crush/internal/config"
13 "github.com/charmbracelet/crush/internal/config"
@@ -221,8 +222,12 @@ func isMarkdownFile(name string) bool {
221}
222}
222
223
223func GetMCPPrompt(cfg *config.ConfigStore, clientID, promptID string, args map[string]string) (string, error) {
224func GetMCPPrompt(cfg *config.ConfigStore, clientID, promptID string, args map[string]string) (string, error) {
224− // TODO: we should pass the context down
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+
225− result, err := mcp.GetPromptMessages(context.Background(), cfg, clientID, promptID, args)
230+ result, err := mcp.GetPromptMessages(ctx, cfg, clientID, promptID, args)
226 if err != nil {
231 if err != nil {
227 return "", err
232 return "", err
228 }
233 }