Skip to content

Commit 1a93675

Browse files
Doris26copybara-github
authored andcommitted
fix: Remove GeminiSchemaUtil and use JsonSchema directly in FunctionDeclaration
The `GeminiSchemaUtil` was used to convert the MCP `JsonSchema` to a Gemini-compatible `Schema`. This conversion is now obsolete as the `FunctionDeclaration.Builder` can directly accept `JsonSchema` via the `parametersJsonSchema` method. PiperOrigin-RevId: 795538558
1 parent a0a1616 commit 1a93675

File tree

3 files changed

+9
-991
lines changed

3 files changed

+9
-991
lines changed

core/src/main/java/com/google/adk/tools/mcp/AbstractMcpTool.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import com.google.adk.tools.BaseTool;
2323
import com.google.common.collect.ImmutableMap;
2424
import com.google.genai.types.FunctionDeclaration;
25-
import com.google.genai.types.Schema;
2625
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
2726
import io.modelcontextprotocol.spec.McpSchema.Content;
2827
import io.modelcontextprotocol.spec.McpSchema.JsonSchema;
2928
import io.modelcontextprotocol.spec.McpSchema.TextContent;
3029
import io.modelcontextprotocol.spec.McpSchema.Tool;
31-
import java.io.IOException;
3230
import java.util.ArrayList;
3331
import java.util.List;
3432
import java.util.Map;
@@ -76,32 +74,17 @@ public T getMcpSession() {
7674
return this.mcpSession;
7775
}
7876

79-
protected Schema toGeminiSchema(JsonSchema openApiSchema) {
80-
try {
81-
return GeminiSchemaUtil.toGeminiSchema(openApiSchema, this.objectMapper);
82-
} catch (IOException | IllegalArgumentException e) {
83-
throw new IllegalArgumentException(
84-
"Error generating function declaration for tool '" + this.name() + "': " + e.getMessage(),
85-
e);
86-
}
87-
}
88-
8977
@Override
9078
public Optional<FunctionDeclaration> declaration() {
91-
try {
92-
Schema schema = toGeminiSchema(this.mcpTool.inputSchema());
93-
return Optional.ofNullable(schema)
94-
.map(
95-
value ->
96-
FunctionDeclaration.builder()
97-
.name(this.name())
98-
.description(this.description())
99-
.parameters(value)
100-
.build());
101-
} catch (IllegalArgumentException e) {
102-
System.err.println(e.getMessage());
103-
return Optional.empty();
104-
}
79+
JsonSchema schema = this.mcpTool.inputSchema();
80+
return Optional.ofNullable(schema)
81+
.map(
82+
value ->
83+
FunctionDeclaration.builder()
84+
.name(this.name())
85+
.description(this.description())
86+
.parametersJsonSchema(value)
87+
.build());
10588
}
10689

10790
@SuppressWarnings("PreferredInterfaceType") // BaseTool.runAsync() returns Map<String, Object>

core/src/main/java/com/google/adk/tools/mcp/GeminiSchemaUtil.java

Lines changed: 0 additions & 341 deletions
This file was deleted.

0 commit comments

Comments
 (0)