Skip to content

Conversation

graemerocher
Copy link

@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

Copy link

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

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

I have created a PR on top of this graemerocher#1

Comment on lines 499 to 500
this.jsonMapper = new JacksonMcpJsonMapper(objectMapper);
return this;
Copy link

Choose a reason for hiding this comment

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

Suggested change
this.jsonMapper = new JacksonMcpJsonMapper(objectMapper);
return this;
return jsonMapper(new JacksonMcpJsonMapper(objectMapper));

@He-Pin
Copy link
Contributor

He-Pin commented Sep 11, 2025

Do you want to use Vert.x's json?

@sdelamo
Copy link

sdelamo commented Sep 12, 2025

Do you want to use Vert.x's json?

We want to use Micronaut Serialization. But basically, the idea is to allow users to use whatever JSON Serialization they want.

sdelamo and others added 3 commits September 12, 2025 09:42
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](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html) `JsonSchemaValidatorSupplier` and `JacksonJsonSchemaValidatorSupplier` 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.  

## 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.
@graemerocher graemerocher marked this pull request as ready for review September 12, 2025 08:19
@sdeleuze
Copy link

I did not review everything in detail, but from a high level perspective, this PR looks great, thanks for contributing it @graemerocher @sdelamo.

The main open question for me is related to Jackson 3 which is about to be released. If we want to support Jackson 2 and Jackson 3 (which continues to use the same jackson-annotation:2.x dependency) side by side in the MCP SDK, we may want to rename the module mcp-json-jackson to mcp-json-jackson2 and use a jackson2 subpackage instead of jackson in this module.

If we just plan to upgrade from Jackson 2 to Jackson 3, current naming is fine.

@graemerocher
Copy link
Author

probably including the major version makes sense for Jackson.

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.

4 participants