Objective
Add a newMCPError helper function to reduce the 30+ repeated &jsonrpc.Error{Code: ..., Message: ..., Data: ...} literals scattered across MCP tool files.
Context
From discussion #18080 (go-sdk module review): The tool files (mcp_tools_readonly.go, mcp_tools_privileged.go, mcp_tools_management.go) contain many duplicated jsonrpc.Error struct literals. A small helper function would reduce repetition, enforce consistent error patterns, and make future error format changes easier.
Files to Modify
pkg/cli/mcp_server_helpers.go — add the helper function
pkg/cli/mcp_tools_readonly.go — replace error literals with helper calls
pkg/cli/mcp_tools_privileged.go — replace error literals with helper calls
pkg/cli/mcp_tools_management.go — replace error literals with helper calls
Implementation
// In mcp_server_helpers.go
func newMCPError(code int, msg string, data any) error {
return &jsonrpc.Error{Code: code, Message: msg, Data: mcpErrorData(data)}
}
Replace all &jsonrpc.Error{...} literals with newMCPError(...) calls where there's an existing mcpErrorData helper or equivalent.
Acceptance Criteria
Generated by Plan Command for issue #discussion #18080
Objective
Add a
newMCPErrorhelper function to reduce the 30+ repeated&jsonrpc.Error{Code: ..., Message: ..., Data: ...}literals scattered across MCP tool files.Context
From discussion #18080 (go-sdk module review): The tool files (
mcp_tools_readonly.go,mcp_tools_privileged.go,mcp_tools_management.go) contain many duplicatedjsonrpc.Errorstruct literals. A small helper function would reduce repetition, enforce consistent error patterns, and make future error format changes easier.Files to Modify
pkg/cli/mcp_server_helpers.go— add the helper functionpkg/cli/mcp_tools_readonly.go— replace error literals with helper callspkg/cli/mcp_tools_privileged.go— replace error literals with helper callspkg/cli/mcp_tools_management.go— replace error literals with helper callsImplementation
Replace all
&jsonrpc.Error{...}literals withnewMCPError(...)calls where there's an existingmcpErrorDatahelper or equivalent.Acceptance Criteria
newMCPErrorhelper added tomcp_server_helpers.go&jsonrpc.Error{...}literals in tool files replaced withnewMCPError(...)callsmake test-unitpassesmake agent-finishpasses