Elicitation fails with Jackson 3.2+: ElicitRequest `mode` conflicts with @JsonTypeInfo
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 McpSchema 开始,ElicitRequest 在此声明 @JsonTypeInfo(property = "mode"),ElicitFormRequest/ElicitUrlRequest 在此暴露 mode()。用 -Djackson3.version=3.3.0 运行 ElicitRequestJsonTests 来复现,然后添加提出的、用 JSONRPCRequest 包装的测试,以覆盖 params 的序列化路径。完成的标准是:在 Jackson 3.3.0 上,form 和 url 请求都在 params 内只序列化 mode 一次;但在打补丁之前,请与 maintainer 确认他们想要两种修复方案中的哪一种。
由索引模型根据 Issue 内容生成。
描述
Bug description
With Jackson 3.2.0 or newer, server-initiated elicitation fails. ElicitRequest declares @JsonTypeInfo(include = As.PROPERTY, property = "mode"), and ElicitFormRequest/ElicitUrlRequest also expose @JsonProperty("mode"). Since 3.2.0, Jackson rejects this:
InvalidDefinitionException: Conflict between type id property 'mode' and …
at …_verifyNoTypeIdPropertyConflict
The transport closes the response stream, so the tool result is lost too and the client times out. Jackson 3.1.8 (the version the SDK builds with) works.
This is also a security concern. Several Jackson 3.2.x releases have known CVEs in their modules (see MvnRepository, e.g. 3.2.0), while 3.2.4 and 3.3.0 list none. Upgrading to a clean release breaks elicitation, so elicitation users are stuck on 3.1.8 and cannot pick up future Jackson security fixes.
The conflict was introduced in #993 (URL elicitation), which added the ElicitRequest interface with @JsonTypeInfo(include = As.PROPERTY, property = "mode") while the ElicitFormRequest and ElicitUrlRequest records also expose @JsonProperty("mode").
Environment
MCP Java SDK 2.2.0, Streamable HTTP servlet transport, Java 25, MCP Inspector 2.13.0. Fails with every Jackson release since 3.2.0 that I tried (3.2.0, 3.2.4, 3.3.0).
Steps to reproduce
- Use SDK 2.2.0 with Jackson 3.3.0 (import
tools.jackson:jackson-bom:3.3.0beforemcp-bom). - In a tool handler, call
exchange.createElicitation(ElicitFormRequest.builder(message, schema).build()). - Call the tool from a client that supports elicitation.
Expected behavior
Elicitation works with current Jackson 3 releases (e.g. 3.3.0), and mode is sent exactly once inside params of elicitation/create, for both form and URL requests.
Minimal Complete Reproducible example
A test for ElicitRequestJsonTests (from #1045) that serializes the request the way the transport does, as params of a JSONRPCRequest:
@Test
void urlRequestKeepsModeAsJsonRpcParams() throws IOException {
McpSchema.ElicitUrlRequest request = McpSchema.ElicitUrlRequest.builder("msg", "https://example.com", "eid")
.build();
McpSchema.JSONRPCRequest message = new McpSchema.JSONRPCRequest(McpSchema.JSONRPC_VERSION,
McpSchema.METHOD_ELICITATION_CREATE, "1", request);
String json = mapper.writeValueAsString(message);
assertThatJson(json).node("params.mode").isEqualTo("url");
}
Run with -Djackson3.version=3.3.0:
| Version | Result |
|---|---|
| #1045 | fails: Missing node in path "params.mode" |
EXISTING_PROPERTY (below) |
passes (5/5 in ElicitRequestJsonTests) |
Fix options
#1045 marks mode() with @JsonIgnore. That removes the exception, but when the request is the value of JSONRPCRequest.params (declared as Object), no type id is written either, so mode is not sent at all. Form mode still works by default, but URL mode would reach the client without mode. The same @JsonIgnore approach works for Content.type() because content is declared as List<Content>, so Jackson writes the type id there. Raw SSE captures in a comment on #1045.
Alternative: change only the discriminator to EXISTING_PROPERTY:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "mode",
defaultImpl = ElicitFormRequest.class)
and keep @JsonProperty("mode") on the mode() accessors of both ElicitFormRequest and ElicitUrlRequest, as in 2.2.0:
@Override
@JsonProperty("mode")
public String mode() {
return MODE;
}
Tested on top of v2.2.0 with Jackson 3.3.0: #1045's ElicitRequestJsonTests and the test above pass, and on the wire (Streamable HTTP, MCP Inspector) "mode":"form" is sent exactly once.
Which approach would you prefer? I can open a PR if that helps, but I'm equally fine with a maintainer picking this up.
- 主要语言
- Java
- 星标
- 3.8k
- 派生
- 1.1k
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/java-sdk 的其他 Issue
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON string可能已有人在做 @starryeye 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
modelcontextprotocol/java-sdk#1352 · 1 条评论 ·
维护者通常 1 天内回复
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was called未关闭
难度 1/5 1 小时以内 新手友好度 85/100
modelcontextprotocol/java-sdk#1346 · 1 条评论 ·
维护者通常 1 天内回复
-
area/server legacy P3
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/java-sdk#1330 · 1 条评论 ·
维护者通常 1 天内回复
-
Client request handlers that complete empty send no JSON-RPC response可能已有人在做 @1fanwang 于 83 天前认领。 未关闭area/client bug P2
难度 2/5 1-3 小时 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 6 条评论 ·
维护者通常 1 天内回复
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities可能已有人在做 @1yuxiangJ 于 98 天前认领。 未关闭bug P2 ready for work
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/java-sdk#1086 · 2 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
crash
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 74/100
-
account bug course exam iris lecture
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100