ITADN

ChatGoogle: MCP tools don't work due to schema generation from wrapper function

#257Opencpsievert 创建于 2026-01-03
C
cpsievertcommented
## Summary MCP tools don't work with `ChatGoogle()` because the Google provider generates tool schemas from the wrapper function rather than using the pre-computed schema. ## Root Cause In `_provider_google.py` (around line 339-346), regular tools are converted using: ```python gtool = GoogleTool( function_declarations=[ FunctionDeclaration.from_callable( client=self._client._api_client, callable=tool.func, ) ] ) ``` For MCP tools, `tool.func` is an async wrapper function created in `Tool.from_mcp()`: ```python async def _call(**args: Any) -> AsyncGenerator[ContentToolResult, None]: result = await session.call_tool(mcp_tool.name, args) # ... process result ``` When `FunctionDeclaration.from_callable()` inspects this wrapper: - **Name**: `_call` (wrapper function name, not `fetch`) - **Description**: Empty or minimal docstring - **Parameters**: `None` (because `**args` has no type hints) ## Observed Behavior ```python from chatlas import ChatGoogle chat = ChatGoogle() await chat.register_mcp_tools_stdio_async( command='uvx', args=['mcp-server-fetch'], ) # Tool is registered but Google refuses to use it response = await chat.chat_async('Fetch https://example.com') # Output: "I am sorry, I cannot fulfill this request. The available tools lack the desired functionality." ``` ## Proposed Fix Instead of using `from_callable()`, create `FunctionDeclaration` directly from `tool.schema`: ```python if isinstance(tool, ToolBuiltIn): # ... existing builtin handling else: func = tool.schema["function"] gtool = GoogleTool( function_declarations=[ FunctionDeclaration( name=func["name"], description=func.get("description", ""), parameters=func.get("parameters"), ) ] ) ``` This would use the pre-computed schema (which has the correct name, description, and parameters from the MCP tool definition) rather than trying to introspect the wrapper function. ## Scope This bug affects: - All MCP tools registered via `register_mcp_tools_stdio_async()` or `register_mcp_tools_http_stream_async()` - Only the Google provider (`ChatGoogle`) Other providers (OpenAI, Anthropic, etc.) work correctly because they use `tool.schema` directly.
0 条评论