Elicitation fails with Jackson 3.2+: ElicitRequest `mode` conflicts with @JsonTypeInfo

Đang mở Phù hợp với người mới
#1,345 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
64/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu ở McpSchema, nơi ElicitRequest khai báo @JsonTypeInfo(property = "mode") và nơi ElicitFormRequest/ElicitUrlRequest cung cấp mode(). Tái hiện bằng cách chạy ElicitRequestJsonTests với -Djackson3.version=3.3.0, rồi thêm bài test được đề xuất có bọc JSONRPCRequest để đường đi tuần tự hóa params được bao phủ. Xong nghĩa là cả request form lẫn url đều tuần tự hóa mode đúng một lần bên trong params trên Jackson 3.3.0, nhưng hãy xác nhận với maintainer xem họ muốn lựa chọn sửa lỗi nào trong hai lựa chọn trước khi patch.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

  1. Use SDK 2.2.0 with Jackson 3.3.0 (import tools.jackson:jackson-bom:3.3.0 before mcp-bom).
  2. In a tool handler, call exchange.createElicitation(ElicitFormRequest.builder(message, schema).build()).
  3. 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.

Ngôn ngữ chính
Java
Star
3.8k
Fork
1.1k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
38

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/java-sdk

Tất cả issue của modelcontextprotocol/java-sdk

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.