Skip to content

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

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
Contributor Author

probably including the major version makes sense for Jackson.

@tzolov tzolov self-assigned this Sep 15, 2025
@tzolov tzolov added this to the 0.13.0 milestone Sep 15, 2025
@tzolov tzolov added breaking-change enhancement New feature or request labels Sep 15, 2025
Copy link
Contributor

@tzolov tzolov left a comment

Choose a reason for hiding this comment

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

Thanks @graemerocher, @sdelamo ! Nice work.

Few improvement requests:

  • Add the mcp-json and mcp-json-jackson modules to the mcp-bom
  • Add missing MIT license headers:
    /*
     * Copyright 2025 - 2025 the original author or authors.
     */
    
  • Update mcp java sdk reference documentation (remainder for a follow-up PR)

There's another conceptual change that I'm puzzled with. Currently the mcp is self-contained. But with this PR it becomes a "core" component requiring an additional mcp-json-xxx (like mcp-json-jackson) dependency for the same bootstrap experience without breaking changes.

I wonder if we should rename the existing mcp module to mcp-core and create a small mcp module that includes both mcp-core and mcp-json-jackson by default?
This will preserver the existing single-click experience for the end users

mcp/pom.xml Outdated
<version>0.13.0-SNAPSHOT</version>
</dependency>

<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

move to the test section of the pom

<artifactId>mcp-parent</artifactId>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>mcp-json</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

add to the mcp-bom

Copy link

Choose a reason for hiding this comment

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

<artifactId>mcp-parent</artifactId>
<version>0.13.0-SNAPSHOT</version>
</parent>
<artifactId>mcp-json-jackson</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

add to the mcp-bom

Copy link

Choose a reason for hiding this comment

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

@sdelamo
Copy link

sdelamo commented Sep 15, 2025

@tzolov

There's another conceptual change that I'm puzzled with. Currently the mcp is self-contained. But with this PR it becomes a "core" component requiring an additional mcp-json-xxx (like mcp-json-jackson) dependency for the same bootstrap experience without breaking changes.

wonder if we should rename the existing mcp module to mcp-core and create a small mcp module that includes both mcp-core and mcp-json-jackson by default?
This will preserver the existing single-click experience for the end users

You are right. To avoid breaking changes, I left in this PR mcp-json-jackson as a compile dependency. Once this PR gets merged, I will create a PR that moves the mcp classes to mcp-core.

@sdelamo
Copy link

sdelamo commented Sep 15, 2025

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.

I renamed to module to mcp-json-jackson2

* add mcp-json and mcp-json-jackson to BOM

* add license header

* add mcp-json-jackon as a compile dependency

* rename to jackson 2
tzolov pushed a commit that referenced this pull request Sep 15, 2025
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.

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov
Copy link
Contributor

tzolov commented Sep 15, 2025

Thank you @graemerocher @sdelamo

Rebased, conflicts resolved, squashed and merged at 80d0ad8

@tzolov tzolov closed this Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants