AttributeError: 'MCPTool' object has no attribute 'func'
Describe the bug
AttributeError: 'MCPTool' object has no attribute 'func'
I am getting this error when I integrated airbnb mcp in adk streaming example along with the google search tool.
To Reproduce In the agent if we add airbnb mcp example, I am getting this error when agent is trying to use the airbnb tool to execute task. For all the google search related queries, no issues were reported.
Adding the stacktrace
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 243, in run_asgi
result = await self.app(self.scope, self.asgi_receive, self.asgi_send) # type: ignore[func-returns-value]
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
return await self.app(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 152, in __call__
await self.app(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/routing.py", line 714, in __call__
await self.middleware_stack(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/routing.py", line 734, in app
await route.handle(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/routing.py", line 362, in handle
await self.app(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/routing.py", line 95, in app
await wrap_app_handling_exceptions(app, session)(scope, receive, send)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/starlette/routing.py", line 93, in app
await func(session)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/fastapi/routing.py", line 383, in app
await dependant.call(**solved_result.values)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/app/main.py", line 146, in websocket_endpoint
await asyncio.gather(agent_to_client_task, client_to_agent_task)
File "/Users/bipulkarnani/PycharmProjects/mcp-server/app/main.py", line 73, in agent_to_client_messaging
async for event in live_events:
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/runners.py", line 296, in run_live
async for event in invocation_context.agent.run_live(invocation_context):
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/agents/base_agent.py", line 168, in run_live
async for event in self._run_live_impl(ctx):
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/agents/llm_agent.py", line 240, in _run_live_impl
async for event in self._llm_flow.run_live(ctx):
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 105, in run_live
async for event in self._receive_from_model(
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 202, in _receive_from_model
async for event in self._postprocess_live(
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 378, in _postprocess_live
function_response_event = await functions.handle_function_calls_live(
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/flows/llm_flows/functions.py", line 233, in handle_function_calls_live
function_response = await _process_function_live_helper(
File "/Users/bipulkarnani/PycharmProjects/mcp-server/venv/lib/python3.10/site-packages/google/adk/flows/llm_flows/functions.py", line 313, in _process_function_live_helper
elif inspect.isasyncgenfunction(tool.func):
AttributeError: 'MCPTool' object has no attribute 'func'
Live(https://google.github.io/adk-docs/get-started/quickstart-streaming/) is not working with MCPTool yet.
We should add a error here when users try to use MCPTool for streaming. This is a good first issue(just adding the warning.)
We are working to support MCPTool with streaming/live.
Could you share the example and steps to reproduce your error?
Any timeline by when can we expect MCPTool support with streaming/live?
Hi @hangfei I'd like to work on this issue if it's still available. I understand that we need to add a warning/error message when users try to use MCPTool with streaming/live mode. I'll implement a check that detects when MCPTool is being used with streaming and provides a clear error message to guide users. If you're okay with me taking this on, I'll create a PR once I have a solution ready. Thanks!
@devxaitist please. thanks.
This is fixed by: https://github.com/google/adk-python/commit/f7b436a98519fda026409882f271c40b7375ab23.
I have verified with :
# ./adk_agent_samples/mcp_agent/agent.py
from google.adk.agents.llm_agent import LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters
async def attach_everything_tools():
tools, exit_stack = await MCPToolset.from_server(
connection_params=StdioServerParameters(
command='npx',
args=[
'-y',
'@modelcontextprotocol/server-everything',
'/tmp/mcp-test',
],
)
)
# `tools` now contains the `echo`, `add`, etc. tools
return tools, exit_stack
# async def create_agent():
# """Gets tools from MCP Server."""
# tools, exit_stack = await MCPToolset.from_server(
# connection_params=StdioServerParameters(
# command='npx',
# args=["-y", # Arguments for the command
# "@modelcontextprotocol/server-filesystem",
# # TODO: IMPORTANT! Change the path below to an ABSOLUTE path on your system.
# "/Users/",
# ],
# )
# )
async def create_agent():
tools, exit_stack = await attach_everything_tools()
agent = LlmAgent(
model='gemini-2.0-flash-exp',
name='enterprise_assistant',
instruction=(
'Help user accessing a few commands like echo, add, etc.'
),
tools=tools,
)
return agent, exit_stack
root_agent = create_agent()
Closing the issue. Feel free to re-open if you still experience this.