Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/mcp/tool_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,12 @@ func NewErrorCallToolResult(err error) (*sdk.CallToolResult, interface{}, error)
},
}, nil, err
}

// BuildMCPTextResponse returns a raw MCP response map with a single text content item.
func BuildMCPTextResponse(text string) map[string]interface{} {
return map[string]interface{}{
"content": []map[string]interface{}{
{"type": "text", "text": text},
},
}
}
15 changes: 15 additions & 0 deletions internal/mcp/tool_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,18 @@ func TestConvertToCallToolResult_MarshalError(t *testing.T) {
assert.Nil(t, result)
assert.Contains(t, err.Error(), "failed to marshal backend result")
}

func TestBuildMCPTextResponse(t *testing.T) {
text := `{"permission":"write"}`

result := BuildMCPTextResponse(text)

require := require.New(t)
assert := assert.New(t)

content, ok := result["content"].([]map[string]interface{})
require.True(ok)
require.Len(content, 1)
assert.Equal("text", content[0]["type"])
assert.Equal(text, content[0]["text"])
}
8 changes: 2 additions & 6 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/github/gh-aw-mcpg/internal/difc"
"github.com/github/gh-aw-mcpg/internal/guard"
"github.com/github/gh-aw-mcpg/internal/logger"
"github.com/github/gh-aw-mcpg/internal/mcp"
"github.com/github/gh-aw-mcpg/internal/tracing"
)

Expand Down Expand Up @@ -331,12 +332,7 @@ func (r *restBackendCaller) CallTool(ctx context.Context, toolName string, args
}

// Wrap in MCP response format: {content: [{type: "text", text: "..."}]}
mcpResp := map[string]interface{}{
"content": []map[string]interface{}{
{"type": "text", "text": string(body)},
},
}
return mcpResp, nil
return mcp.BuildMCPTextResponse(string(body)), nil
}

// forwardToGitHub sends a request to the upstream GitHub API.
Expand Down
19 changes: 3 additions & 16 deletions internal/server/system_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/github/gh-aw-mcpg/internal/logger"
"github.com/github/gh-aw-mcpg/internal/mcp"
)

var logSys = logger.New("server:system_tools")
Expand Down Expand Up @@ -89,14 +90,7 @@ func (s *SysServer) callTool(name string, args map[string]interface{}) (interfac

func (s *SysServer) sysInit() (interface{}, error) {
logSys.Printf("Initializing MCPG system with %d servers", len(s.serverIDs))
return map[string]interface{}{
"content": []map[string]interface{}{
{
"type": "text",
"text": fmt.Sprintf("MCPG initialized. Available servers: %v", s.serverIDs),
},
},
}, nil
return mcp.BuildMCPTextResponse(fmt.Sprintf("MCPG initialized. Available servers: %v", s.serverIDs)), nil
}

func (s *SysServer) listServers() (interface{}, error) {
Expand All @@ -105,12 +99,5 @@ func (s *SysServer) listServers() (interface{}, error) {
serverList += fmt.Sprintf("%d. %s\n", i+1, id)
}

return map[string]interface{}{
"content": []map[string]interface{}{
{
"type": "text",
"text": fmt.Sprintf("Configured MCP Servers:\n%s", serverList),
},
},
}, nil
return mcp.BuildMCPTextResponse(fmt.Sprintf("Configured MCP Servers:\n%s", serverList)), nil
}
7 changes: 1 addition & 6 deletions internal/server/unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,7 @@ func (g *guardBackendCaller) callCollaboratorPermission(ctx context.Context, arg
}

// Wrap in MCP response format so the WASM guard can parse it consistently
mcpResp := map[string]interface{}{
"content": []map[string]interface{}{
{"type": "text", "text": string(body)},
},
}
return mcpResp, nil
return mcp.BuildMCPTextResponse(string(body)), nil
}

// buildCircuitBreakers creates per-backend circuit breakers from the configuration.
Expand Down
Loading