modelcontextprotocol / modelcontextprotocol/java-sdk

Add JPMS compatibility to Jackson JSON mapper

Open
#753 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

Expected Behavior

Applications using the MCP Java SDK should work with JPMS (Java Platform Module System) without requiring --add-opens JVM flags. Record deserialization should work through public constructors and parameter name discovery rather than reflective access.

  // Should work without --add-opens flags
  McpJsonMapper mapper = new JacksonMcpJsonMapperSupplier().get();
  MyRecord record = mapper.readValue(json, MyRecord.class);

Current Behavior

The JacksonMcpJsonMapperSupplier creates a plain ObjectMapper that uses reflection to access record constructors. This requires --add-opens JVM flags like:

  --add-opens java.base/java.lang.reflect=ALL-UNNAMED

Without these flags, deserialization of Java records fails with InaccessibleObjectException.

Context

We're integrating the MCP SDK into a JPMS-modularized application and cannot use --add-opens flags as they break module encapsulation.

The fix is straightforward:

  1. Disable MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS to prevent setAccessible() calls
  2. Add ParameterNamesModule to discover constructor parameters from bytecode

The SDK already compiles with -parameters, so ParameterNamesModule will work without additional configuration.

Workaround: We currently maintain a custom MCP client with JPMS-compatible Jackson configuration, but would prefer to use the upstream SDK directly.

I have a PR.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at JacksonMcpJsonMapperSupplier and inspect how its ObjectMapper handles record constructors and parameter names. Verify the mapper configuration against the JPMS example, then confirm record deserialization works without --add-opens flags and preserves existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.