on main help sign in
feat(permissions): pretty-print MCP JSON

Add pretty-printed JSON parameters to MCP tool permission dialogs so users can read more of the content. Co-Authored-By: Crush <crush@charm.land>

commit9654218e61ff58326e4524f34086822e6d7c2864 authorAmolith <amolith@secluded.site> dateSun 21 Sep 2025, 16:17 (1 year ago) parent6b161d2
2 files changed+31−1
internal/llm/agent/mcp-tools.go+1−1 internal/tui/components/dialogs/permissions/permissions.go+30
internal/llm/agent/mcp-tools.go+1−1
@@ -176,7 +176,7 @@ func (b *McpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolRes
176176 if sessionID == "" || messageID == "" {
177177 return tools.ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
178178 }
179− permissionDescription := fmt.Sprintf("execute %s with the following parameters: %s", b.Info().Name, params.Input)
179+ permissionDescription := fmt.Sprintf("execute %s with the following parameters:", b.Info().Name)
180180 p := b.permissions.Request(
181181 permission.CreatePermissionRequest{
182182 SessionID: sessionID,
internal/tui/components/dialogs/permissions/permissions.go+30
@@ -1,6 +1,7 @@
11package permissions
22
33import (
4+ "encoding/json"
45 "fmt"
56 "strings"
67
@@ -614,6 +615,35 @@ func (p *permissionDialogCmp) generateDefaultContent() string {
614615
615616 content := p.permission.Description
616617
618+ // Add pretty-printed JSON parameters for MCP tools
619+ if p.permission.Params != nil {
620+ var paramStr string
621+
622+ // Ensure params is a string
623+ if str, ok := p.permission.Params.(string); ok {
624+ paramStr = str
625+ } else {
626+ paramStr = fmt.Sprintf("%v", p.permission.Params)
627+ }
628+
629+ // Try to parse as JSON for pretty printing
630+ var parsed any
631+ if err := json.Unmarshal([]byte(paramStr), &parsed); err == nil {
632+ if b, err := json.MarshalIndent(parsed, "", " "); err == nil {
633+ if content != "" {
634+ content += "\n\n"
635+ }
636+ content += string(b)
637+ }
638+ } else {
639+ // Not JSON, show as-is
640+ if content != "" {
641+ content += "\n\n"
642+ }
643+ content += paramStr
644+ }
645+ }
646+
617647 content = strings.TrimSpace(content)
618648 content = "\n" + content + "\n"
619649 lines := strings.Split(content, "\n")