fix(commands): add timeout context for MCP prompt retrieval (#2517)

iceymoss created

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>

Change summary

internal/commands/commands.go | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

Detailed changes

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
 	}