modelcontextprotocol / modelcontextprotocol/java-sdk
Add JPMS compatibility to Jackson JSON mapper
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 3.7k
- Forks
- 1.1k
- Ø Merge
- 1 T. 15 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne bei JacksonMcpJsonMapperSupplier und untersuche, wie sein ObjectMapper mit Record-Konstruktoren und Parameternamen umgeht. Überprüfe die Mapper-Konfiguration anhand des JPMS-Beispiels und bestätige anschließend, dass die Deserialisierung von Records ohne --add-opens-Flags funktioniert und das bestehende Verhalten beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100