modelcontextprotocol / modelcontextprotocol/java-sdk
Add JPMS compatibility to Jackson JSON mapper
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 JacksonMcpJsonMapperSupplier 开始,检查其 ObjectMapper 如何处理 record 构造函数和参数名。对照 JPMS 示例验证 mapper 配置,然后确认 record 反序列化无需 --add-opens 标志即可正常工作,并保持现有行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100