modelcontextprotocol / modelcontextprotocol/java-sdk
Add JPMS compatibility to Jackson JSON mapper
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 3.7k
- Fork
- 1.1k
- Merge medio
- 1g 15h
- PR unite (30g)
- 9
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da JacksonMcpJsonMapperSupplier e verifica come il suo ObjectMapper gestisce i costruttori dei record e i nomi dei parametri. Verifica la configurazione del mapper rispetto all'esempio JPMS, quindi conferma che la deserializzazione dei record funzioni senza flag --add-opens e preservi il comportamento esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100