Importing the right way using MCP tools in a sub agent
Hey guys,
Im defining a sub browser use agent in the sub agent folder, like the docs mentioned, but im having trouble importing this into the main agent that is going to use this sub agent.
I tried changing the init file but that didnt work either. For reference like this
Importing like this in the main file
but its not working
Any comments, concerns or outright im doing something dumb?
Can you provide more of your project structure and the command you run the main.py file with? @kanlanc
This is the current file structure
And in the main file
Doing it this way, removed the errors
But the console it forever stuck on connecting to browserbase
Is this problem solved yet? I can only use MCP in the root agent.
@hangfei @seanzhou1023 @ngothetai Has this been resolved where you can import MCP tools to a sub agent? Im still getting issues when i do this in a sub agent following the exact code in the docs specifically im talking about getting coroutine issues specifically when i call mcp toolset on a sub agent
This is the code from docs that errors out into coroutine is not being awaited issue when I run it in a subagent
# ./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 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.
"/path/to/your/folder",
],
)
)
agent = LlmAgent(
model='gemini-2.0-flash',
name='enterprise_assistant',
instruction=(
'Help user accessing their file systems'
),
tools=tools,
)
return agent, exit_stack
root_agent = create_agent()
I pulled a weird work around for this by using custom agents and inside the async run implementation function where your supposed to write the core code, I called the async function for getting MCP toolset
It looks promising but one thing im unsure about that could lead to issues is where should i close the connection from for a custom sub agent
I knew it was too good to be true and im running into this error
Re-opened this issue, as it has the most context on the problem. Closing the other one instead as duplicate. https://github.com/google/adk-python/issues/712
My current work around for this is to call MCP toolset in root agent and pass it down to sub agents for them to use.
It works rn
we have already changed the way MCP toolset is used. We no longer support the old way. And please install from source or wait for next minor release since 1.0 still has some issues.
example to follow :
https://github.com/google/adk-python/tree/main/contributing/samples/mcp_stdio_server_agent
feel free to reopen if latest codes on main or in next minor release still don't work