-
Notifications
You must be signed in to change notification settings - Fork 785
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.