modelcontextprotocol / modelcontextprotocol/java-sdk

Add JPMS compatibility to Jackson JSON mapper

未关闭
#753 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2
主要语言
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:

  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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 JacksonMcpJsonMapperSupplier 开始,检查其 ObjectMapper 如何处理 record 构造函数和参数名。对照 JPMS 示例验证 mapper 配置,然后确认 record 反序列化无需 --add-opens 标志即可正常工作,并保持现有行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
api, backend
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。