Skip to content

chore: Add @JsonCreator to McpError#768

Open
He-Pin wants to merge 2 commits intomodelcontextprotocol:mainfrom
He-Pin:creator
Open

chore: Add @JsonCreator to McpError#768
He-Pin wants to merge 2 commits intomodelcontextprotocol:mainfrom
He-Pin:creator

Conversation

@He-Pin
Copy link
Contributor

@He-Pin He-Pin commented Feb 2, 2026

Motivation and Context

Support deserialization McpError

How Has This Been Tested?

Use this in production

Breaking Changes

Types of changes

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • [ x] I have read the MCP Documentation
  • [ x] My code follows the repository's style guidelines
  • [ x] New and existing tests pass locally
  • [x ] I have added appropriate error handling
  • [x ] I have added or updated documentation as needed

Additional context

Signed-off-by: He-Pin <hepin1989@gmail.com>
Copilot AI review requested due to automatic review settings February 27, 2026 03:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Jackson deserialization support to the McpError class by adding the @JsonCreator annotation to its constructor. This enables McpError instances to be properly deserialized from JSON, which is necessary for error handling in MCP protocol communication where McpError objects are serialized and sent over the wire.

Changes:

  • Added @JsonCreator annotation to the McpError constructor
  • Added a Javadoc comment explaining the purpose of the annotation
  • Imported com.fasterxml.jackson.annotation.JsonCreator

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* Add @JsonCreator to make sure Jackson can deserialize it properly.
*/
@JsonCreator
public McpError(JSONRPCError jsonRpcError) {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using @JsonCreator with a single-parameter constructor, it's recommended to explicitly annotate the constructor parameter with @JsonProperty to ensure reliable deserialization across different Jackson configurations. While the current code may work due to the -parameters compiler flag, adding @JsonProperty("jsonRpcError") to the constructor parameter would make the deserialization contract explicit and more robust.

This follows the pattern seen throughout the codebase where all record constructors explicitly use @JsonProperty annotations on their parameters (e.g., JSONRPCError in McpSchema.java:306-308).

Copilot uses AI. Check for mistakes.
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.

2 participants