Skip to content

[plan] Add newMCPError helper to reduce jsonrpc.Error literal repetition #18338

@github-actions

Description

@github-actions

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

  • newMCPError helper added to mcp_server_helpers.go
  • All (or majority of) &jsonrpc.Error{...} literals in tool files replaced with newMCPError(...) calls
  • No behavioral changes — error codes and messages remain identical
  • make test-unit passes
  • make agent-finish passes

Generated by Plan Command for issue #discussion #18080

  • expires on Feb 27, 2026, 12:38 PM UTC

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions