Skip to content

Commit 21c0599

Browse files
authored
fix: improve MCP schema compatibility and LLM guidance for reporting tools (#135)
1 parent a4d0407 commit 21c0599

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

analytics_mcp/coordinator.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@
7171
)
7272

7373
mcp_tools = [adk_to_mcp_tool_type(tool) for tool in tools]
74+
75+
76+
def sanitize_mcp_schema_properties(node: dict) -> None:
77+
"""Ensure additionalProperties is a boolean value to satisfy certain MCP clients.
78+
79+
This addresses issues with clients like Claude Desktop that fail when
80+
additionalProperties is a schema object instead of a boolean.
81+
"""
82+
if not isinstance(node, dict):
83+
return
84+
85+
# Check and update the current node
86+
if "additionalProperties" in node:
87+
val = node["additionalProperties"]
88+
if not isinstance(val, bool):
89+
node["additionalProperties"] = True
90+
91+
# Traverse children
92+
for key, child in node.items():
93+
if isinstance(child, dict):
94+
sanitize_mcp_schema_properties(child)
95+
elif isinstance(child, list):
96+
for element in child:
97+
if isinstance(element, dict):
98+
sanitize_mcp_schema_properties(element)
99+
100+
74101
# Update the inputSchema for tools that do not have parameters.
75102
# TODO: This is a bug in the ADK and can be removed once it is fixed.
76103
# https://github.com/google/adk-python/issues/948
@@ -83,6 +110,20 @@
83110
if "anyOf" in prop and prop.get("type") == "null":
84111
del prop["type"]
85112

113+
# Ensure additionalProperties is compatible with all MCP clients
114+
sanitize_mcp_schema_properties(tool.inputSchema)
115+
116+
# Explicitly mark required fields for reporting tools to guide the LLM
117+
if tool.name == "run_report":
118+
tool.inputSchema["required"] = [
119+
"property_id",
120+
"date_ranges",
121+
"dimensions",
122+
"metrics",
123+
]
124+
elif tool.name == "run_realtime_report":
125+
tool.inputSchema["required"] = ["property_id", "dimensions", "metrics"]
126+
86127

87128
@app.list_tools()
88129
async def list_tools() -> list[mcp_types.Tool]:

0 commit comments

Comments
 (0)