modelcontextprotocol / modelcontextprotocol/java-sdk

Add JPMS compatibility to Jackson JSON mapper

Offen
#753 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P2
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:

  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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Ö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

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.