Skip to content

Introduce McpJsonMapper interface to decouple from Jackson#543

Closed
graemerocher wants to merge 7 commits intomodelcontextprotocol:mainfrom
graemerocher:jackson-decoupling
Closed

Introduce McpJsonMapper interface to decouple from Jackson#543
graemerocher wants to merge 7 commits intomodelcontextprotocol:mainfrom
graemerocher:jackson-decoupling

Conversation

@graemerocher
Copy link
Contributor

@graemerocher graemerocher commented Sep 10, 2025

Motivation and Context

The current MCP SDK is coupled to Jackson which prevents the use of other JSON serialization libraries and techniques.

This PR is an initial go and abstracting away Jackson usage in order to generate discussion. Left in draft to gather feedback.

This pull request creates two modules, mcp-json and mcp-json-jackson. It removes the com.fasterxml.jackson.core:jackson-databind and com.networknt:json-schema-validator dependencies from the mcp module. The mcp module now only depends on com.fasterxml.jackson.core:jackson-annotations.

To use Jackson, you have to add mcp-jackson to your dependencies in addition to mcp. I added the dependency mcp-jackson to both mcp-spring-mvc and mcp-spring-webflux to avoid a breaking change in those modules.

It provides two SPI JsonSchemaValidatorSupplier and JsonSchemaValidatorSupplier to allow easy replacement for consumers who don't want to use Jackson.

This pull request also ensures no McpJsonMapper is instantiated if one is provided via a builder method. Only if the builders don't receive a McpJsonMapper mapper, one is instantiated in the build method of the builder.
The logic behind this is to allow frameworks to provide a McpJsonMapper mapper singleton implementation and feed it to the builders without paying the price of instantiating McpJsonMappers, which will not be used. The goal is to be able to use the ObjectMapper singleton of an application also for the MCP code.

How Has This Been Tested?

Yes tests included.

Breaking Changes

  • This pull request also removes the deprecated Tool constructors, and it updates every test to use the builder API to instantiate tools.
  • Several constructors taking an ObjectMapper or constructor which forced the instantiation of a generic McpJsonMapper have been removed.

Types of changes

  • 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

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

Additional context

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants