Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.agents.api.tools.Tool;
import org.apache.flink.agents.api.tools.ToolMetadata;
Expand All @@ -38,6 +39,7 @@
* <p>This represents a single tool from an MCP server. It extends the base Tool class and delegates
* actual execution to the MCP server.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class MCPTool extends Tool {

private static final String FIELD_MCP_SERVER = "mcpServer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ class MCPToolTest {

private static final String DEFAULT_ENDPOINT = "http://localhost:8000/mcp";

@Test
@DisabledOnJre(JRE.JAVA_11)
@DisplayName("JSON deserialization works with default ObjectMapper (no FAIL_ON_UNKNOWN_PROPERTIES override)")
void testJsonDeserializationWithDefaultMapper() throws Exception {
ToolMetadata metadata =
new ToolMetadata("add", "Add two numbers", "{\"type\":\"object\"}");
MCPServer server = new MCPServer(DEFAULT_ENDPOINT);
MCPTool original = new MCPTool(metadata, server);

// Use a default ObjectMapper — this would fail without @JsonIgnoreProperties
// because Tool.getName()/getDescription() are serialized but MCPTool's
// @JsonCreator only accepts metadata + mcpServer.
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(original);
MCPTool deserialized = mapper.readValue(json, MCPTool.class);

assertThat(deserialized.getName()).isEqualTo("add");
assertThat(deserialized.getMetadata()).isEqualTo(metadata);
assertThat(deserialized.getMcpServer()).isEqualTo(server);
}

@Test
@DisabledOnJre(JRE.JAVA_11)
@DisplayName("Create MCPTool with metadata and server")
Expand Down
Loading