Skip to content

Conversation

peteski22
Copy link
Contributor

Description

Enhances JSON-RPC error handling by adding typed sentinel errors and response constructors to improve error checking patterns and reduce code duplication.

Summary:

  • Adds sentinel errors (ErrMethodNotFound, ErrInvalidParams, etc.) with errors.Is() support
  • Introduces AsError() method on JSONRPCErrorDetails for converting to typed errors
  • Adds response constructors (NewJSONRPCErrorResponse, NewJSONRPCResultResponse) to eliminate repetitive struct construction

Closes: #593

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Code refactoring (no functional changes)

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works

MCP Spec Compliance

  • This PR implements a feature defined in the MCP specification
  • Link to relevant spec section: Link text
  • Implementation follows the specification exactly

Additional Information

This change enables cleaner error handling patterns in code which consumes the mcp-go library:

err := response.Error.AsError()
if errors.Is(err, mcp.ErrMethodNotFound) {
  // handle method not found
}

It also reduces repetitive response construction throughout the transport layer with dedicated constructors.

@ezynda3 ezynda3 merged commit 7c8a082 into mark3labs:main Sep 24, 2025
3 checks passed
@peteski22 peteski22 deleted the json-rpc-errors branch September 29, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Preserve JSON-RPC Error (Codes) for Typed Error Handling

2 participants