modelcontextprotocol / modelcontextprotocol/java-sdk
Add JPMS compatibility to Jackson JSON mapper
Nobody has claimed this yet.
- 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:
- Disable
MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERSto preventsetAccessible()calls - Add
ParameterNamesModuleto 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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