on main help sign in
feat(permissions): pretty-print MCP JSON
9654218Amolith
internal/llm/agent/mcp-tools.go+1−1
@@ -176,7 +176,7 @@ func (b *McpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolRes
176 if sessionID == "" || messageID == "" {
176 if sessionID == "" || messageID == "" {
177 return tools.ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
177 return tools.ToolResponse{}, fmt.Errorf("session ID and message ID are required for creating a new file")
178 }
178 }
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)
180 p := b.permissions.Request(
180 p := b.permissions.Request(
181 permission.CreatePermissionRequest{
181 permission.CreatePermissionRequest{
182 SessionID: sessionID,
182 SessionID: sessionID,
internal/tui/components/dialogs/permissions/permissions.go+30
@@ -1,6 +1,7 @@
1package permissions
1package permissions
2
2
3import (
3import (
4+ "encoding/json"
4 "fmt"
5 "fmt"
5 "strings"
6 "strings"
6
7
@@ -614,6 +615,35 @@ func (p *permissionDialogCmp) generateDefaultContent() string {
614
615
615 content := p.permission.Description
616 content := p.permission.Description
616
617
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+
617 content = strings.TrimSpace(content)
647 content = strings.TrimSpace(content)
618 content = "\n" + content + "\n"
648 content = "\n" + content + "\n"
619 lines := strings.Split(content, "\n")
649 lines := strings.Split(content, "\n")