Skip to content

Commit 92206b5

Browse files
committed
feat: provide more detailed logs when mcp tool declaration failed.
1 parent 48cfb3d commit 92206b5

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.core.type.TypeReference;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222
import com.google.adk.tools.BaseTool;
23+
import com.google.adk.tools.mcp.McpToolException.McpToolDeclarationException;
2324
import com.google.common.collect.ImmutableMap;
2425
import com.google.genai.types.FunctionDeclaration;
2526
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
@@ -77,14 +78,20 @@ public T getMcpSession() {
7778
@Override
7879
public Optional<FunctionDeclaration> declaration() {
7980
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());
81+
try {
82+
return Optional.ofNullable(schema)
83+
.map(
84+
value ->
85+
FunctionDeclaration.builder()
86+
.name(this.name())
87+
.description(this.description())
88+
.parametersJsonSchema(value)
89+
.build());
90+
} catch (Exception e) {
91+
throw new McpToolDeclarationException(
92+
String.format("MCP tool:%s failed to get declaration, schema:%s.", this.name(), schema),
93+
e);
94+
}
8895
}
8996

9097
@SuppressWarnings("PreferredInterfaceType") // BaseTool.runAsync() returns Map<String, Object>
@@ -141,4 +148,5 @@ protected static Map<String, Object> wrapCallResult(
141148
}
142149
return ImmutableMap.of("text_output", resultMaps);
143150
}
151+
144152
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.adk.tools.mcp;
18+
19+
/** Base exception for all errors originating from {@code AbstractMcpTool} and its subclasses. */
20+
public class McpToolException extends RuntimeException {
21+
22+
public McpToolException(String message, Throwable cause) {
23+
super(message, cause);
24+
}
25+
26+
/** Exception thrown when there's an error during MCP tool declaration generated. */
27+
public static class McpToolDeclarationException extends McpToolException {
28+
public McpToolDeclarationException(String message, Throwable cause) {
29+
super(message, cause);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)