Skip to content
Merged
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
4 changes: 4 additions & 0 deletions api/src/main/java/org/apache/flink/agents/api/tools/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.flink.agents.api.tools;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.flink.agents.api.resource.ResourceType;
import org.apache.flink.agents.api.resource.SerializableResource;

Expand All @@ -41,6 +42,7 @@ public final ToolMetadata getMetadata() {
}

/** Return resource type of class. */
@JsonIgnore
@Override
public final ResourceType getResourceType() {
return ResourceType.TOOL;
Expand All @@ -53,11 +55,13 @@ public final ResourceType getResourceType() {
public abstract ToolResponse call(ToolParameters parameters);

/** Get the tool name from metadata. */
@JsonIgnore
public final String getName() {
return metadata.getName();
}

/** Get the tool description from metadata. */
@JsonIgnore
public final String getDescription() {
return metadata.getDescription();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ class MCPToolTest {

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

@Test
@DisabledOnJre(JRE.JAVA_11)
@DisplayName(
"JSON round-trip works because @JsonIgnore on Tool getters prevents redundant fields")
void testJsonDeserializationWithDefaultMapper() throws Exception {
ToolMetadata metadata = new ToolMetadata("add", "Add two numbers", "{\"type\":\"object\"}");
MCPServer server = MCPServer.builder(DEFAULT_ENDPOINT).build();
MCPTool original = new MCPTool(metadata, server);

// Use a default ObjectMapper — @JsonIgnore on Tool.getName()/getDescription()/
// getResourceType() prevents these from being serialized, so deserialization
// succeeds without needing @JsonIgnoreProperties on MCPTool.
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(original);

// Verify redundant top-level fields are not serialized
// (name/description inside metadata are expected)
com.fasterxml.jackson.databind.JsonNode tree = mapper.readTree(json);
assertThat(tree.has("name")).isFalse();
assertThat(tree.has("description")).isFalse();
assertThat(tree.has("resourceType")).isFalse();

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