Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ADK web not working, but runs in terminal #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dominicdev opened this issue May 23, 2025 · 9 comments
Closed

ADK web not working, but runs in terminal #893

dominicdev opened this issue May 23, 2025 · 9 comments
Assignees
Labels
tools Issues related to tools
Milestone

Comments

@dominicdev
Copy link

I got a working agent with notion mcp, it runs without a problem in teminal but getting error running in adk web, the error show up when starting to chat with the agent

here's is the log for error

2025-05-23 20:28:33,851 - INFO - envs.py:47 - Loaded .env file for main_agent at D:\Documents\Python\git\agent system\agent_notion_tool\main_agent\.env 2025-05-23 20:28:33,866 - ERROR - fast_api.py:637 - Error in event_generator: Traceback (most recent call last): File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 625, in event_generator runner = await _get_runner_async(req.app_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 796, in _get_runner_async root_agent = await _get_root_agent_async(app_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 773, in _get_root_agent_async agent_module = importlib.import_module(app_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\importlib\__init__.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 995, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "D:\Documents\Python\git\agent system\agent_notion_tool\main_agent\__init__.py", line 1, in <module> from . import agent File "D:\Documents\Python\git\agent system\agent_notion_tool\main_agent\agent.py", line 51, in <module> root_agent = asyncio.run(build_agent())[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\nest_asyncio.py", line 30, in run return loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\nest_asyncio.py", line 98, in run_until_complete return f.result() ^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\futures.py", line 203, in result raise self._exception.with_traceback(self._exception_tb) File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\tasks.py", line 314, in __step_run_and_handle_result result = coro.send(None) ^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\main_agent\agent.py", line 27, in build_agent notion_tools, stack = await MCPToolset.from_server( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 223, in from_server await async_exit_stack.enter_async_context(toolset) File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\contextlib.py", line 659, in enter_async_context result = await _enter(cm) ^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 258, in __aenter__ raise e File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 255, in __aenter__ await self._initialize() File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 229, in _initialize self.session = await self.session_manager.create_session() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 132, in create_session return await MCPSessionManager.initialize_session( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 173, in initialize_session transports = await exit_stack.enter_async_context(client) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\contextlib.py", line 659, in enter_async_context result = await _enter(cm) ^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\contextlib.py", line 210, in __aenter__ return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\mcp\client\stdio.py", line 104, in stdio_client process = await anyio.open_process( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\anyio\_core\_subprocesses.py", line 190, in open_process return await get_async_backend().open_process( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Documents\Python\git\agent system\agent_notion_tool\.venv\Lib\site-packages\anyio\_backends\_asyncio.py", line 2561, in open_process process = await asyncio.create_subprocess_exec( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\subprocess.py", line 224, in create_subprocess_exec transport, protocol = await loop.subprocess_exec( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 1743, in subprocess_exec transport = await self._make_subprocess_transport( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 524, in _make_subprocess_transport raise NotImplementedError NotImplementedError

here is also my code

`
from dotenv import load_dotenv
import nest_asyncio
import os, json, asyncio
from contextlib import AsyncExitStack

from google.adk.agents.llm_agent import LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import (
MCPToolset, StdioServerParameters, SseServerParams
)

MODEL = "gemini-2.5-flash-preview-04-17" # Or "gemini-1.5-pro-latest" for more power

nest_asyncio.apply()

load_dotenv()

NOTION_API_KEY = os.getenv("NOTION_API_KEY")
NOTION_HEADERS = json.dumps({
"Authorization": f"Bearer {NOTION_API_KEY}",
"Notion-Version": "2022-06-28"
})

async def build_agent():
notion_tools, stack = await MCPToolset.from_server(
connection_params=StdioServerParameters(
command="npx.cmd",
args=["-y", "@notionhq/notion-mcp-server"],
env={"OPENAPI_MCP_HEADERS": NOTION_HEADERS},
)
)

print(f"total tools {len(notion_tools)}")

agent = LlmAgent(
    model="gemini-2.0-flash",
    name="notion_helper",
    instruction=(
        "You are my workspace assistant. "
        "Use the provided tools to read, search, comment on, "
        "or create Notion pages. Ask clarifying questions when unsure."
    ),
    tools=notion_tools,
)
return agent, stack

root_agent = asyncio.run(build_agent())[0]
`

@seanzhou1023
Copy link
Collaborator

looks like you are using old adk versions. we have changed he MCPToolset interface in 1.0.0 + could you try the new version ?

something like below :

agent = LlmAgent(
model="gemini-2.0-flash",
name="notion_helper",
instruction=(
"You are my workspace assistant. "
"Use the provided tools to read, search, comment on, "
"or create Notion pages. Ask clarifying questions when unsure."
),
tools=[
MCPToolset(
connection_params=StdioServerParameters(
command="npx",
args=["-y", "@notionhq/notion-mcp-server"],
env={"OPENAPI_MCP_HEADERS": NOTION_HEADERS},
)
)
],
)

@seanzhou1023 seanzhou1023 self-assigned this May 23, 2025
@seanzhou1023 seanzhou1023 added the tools Issues related to tools label May 23, 2025
@Anusha2015
Copy link

When using MCPToolset I am getting the below error. Can you please help me on this. I am using google-adk 1.0.0

2025-05-25 12:31:22,303 - ERROR - fast_api.py:817 - Error in event_generator:
Traceback (most recent call last):
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 806, in event_generator
async for event in runner.run_async(
...<8 lines>...
yield f"data: {sse_event}\n\n"
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
...<2 lines>...
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
self.__maybe_save_output_to_state(event)
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
last_event = event
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 293, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 331, in _preprocess_async
for tool in await agent.canonical_tools(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ReadonlyContext(invocation_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
):
^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 367, in canonical_tools
resolved_tools.extend(await _convert_tool_union_to_tools(tool_union, ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 114, in _convert_tool_union_to_tools
return await tool_union.get_tools(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 95, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 214, in get_tools
await self._initialize()
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 112, in _initialize
self._session, process = await self._session_manager.create_session()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 201, in create_session
session, process = await self._initialize_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 237, in _initialize_session
client, process = await cls._create_stdio_client(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 277, in _create_stdio_client
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
)
^
File "C:\Python313\Lib\asyncio\subprocess.py", line 224, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
stderr=stderr, **kwds)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\asyncio\base_events.py", line 1788, in subprocess_exec
transport = await self._make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
protocol, popen_args, False, stdin, stdout, stderr,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bufsize, **kwargs)
^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\asyncio\base_events.py", line 533, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError
2025-05-25 12:31:22,303 - ERROR - fast_api.py:817 - Error in event_generator:
Traceback (most recent call last):
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 806, in event_generator
async for event in runner.run_async(
...<8 lines>...
yield f"data: {sse_event}\n\n"
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
...<2 lines>...
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
self.__maybe_save_output_to_state(event)
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
last_event = event
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 293, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
yield event
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 331, in _preprocess_async
for tool in await agent.canonical_tools(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ReadonlyContext(invocation_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
):
^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 367, in canonical_tools
resolved_tools.extend(await _convert_tool_union_to_tools(tool_union, ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 114, in _convert_tool_union_to_tools
return await tool_union.get_tools(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 95, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 214, in get_tools
await self._initialize()
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 112, in _initialize
self._session, process = await self._session_manager.create_session()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 201, in create_session
session, process = await self._initialize_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 237, in _initialize_session
client, process = await cls._create_stdio_client(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
)
^
File "D:\Learnings\MCP\adk_agent_samples.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 277, in _create_stdio_client
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
)
^
File "C:\Python313\Lib\asyncio\subprocess.py", line 224, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<3 lines>...
stderr=stderr, **kwds)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\asyncio\base_events.py", line 1788, in subprocess_exec
transport = await self._make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
protocol, popen_args, False, stdin, stdout, stderr,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
bufsize, **kwargs)
^^^^^^^^^^^^^^^^^^
File "C:\Python313\Lib\asyncio\base_events.py", line 533, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError

@dominicdev
Copy link
Author

looks like you are using old adk versions. we have changed he MCPToolset interface in 1.0.0 + could you try the new version ?

I tried using 1.0.0 but wont work , it starts the web thought, you can chat normal but when it start using tool it will ge error

this is the log when it start using the tool

`
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: 127.0.0.1:62594 - "GET /dev-ui?app=main_agent HTTP/1.1" 200 OK
INFO: 127.0.0.1:62594 - "GET /list-apps?relative_path=./ HTTP/1.1" 200 OK
2025-05-26 19:43:44,447 - INFO - fast_api.py:457 - New session created
2025-05-26 19:43:44,447 - INFO - fast_api.py:457 - New session created
INFO: 127.0.0.1:62594 - "POST /apps/main_agent/users/user/sessions HTTP/1.1" 200 OK
INFO: 127.0.0.1:62595 - "GET /apps/main_agent/eval_sets HTTP/1.1" 200 OK
INFO: 127.0.0.1:62594 - "GET /apps/main_agent/eval_results HTTP/1.1" 200 OK
INFO: 127.0.0.1:62594 - "GET /apps/main_agent/users/user/sessions HTTP/1.1" 200 OK
INFO: 127.0.0.1:62594 - "GET /apps/main_agent/users/user/sessions HTTP/1.1" 200 OK
INFO: 127.0.0.1:62594 - "POST /run_sse HTTP/1.1" 200 OK
2025-05-26 19:43:46,137 - INFO - envs.py:47 - Loaded .env file for main_agent at D:\Documents\Python\git\agent system\agent_search_notion_tool_terminal\main_agent.env
2025-05-26 19:43:46,412 - INFO - google_llm.py:85 - Sending out request, model: gemini-2.5-flash-preview-04-17, backend: ml_dev, stream: False
2025-05-26 19:43:46,412 - INFO - google_llm.py:85 - Sending out request, model: gemini-2.5-flash-preview-04-17, backend: ml_dev, stream: False
2025-05-26 19:43:46,413 - INFO - google_llm.py:91 -
LLM Request:

System Instruction:
You are the CoordinatorAgent, responsible for managing and orchestrating specialized agents to complete tasks efficiently.

You have access to:

  • SearchAgent: An expert in performing web searches using Google.
  • NotionAgent: A Notion specialist who can read, write, search, and comment on Notion pages.

Your role is to delegate tasks to the appropriate agent based on their specialization. If a task requires external information, use SearchAgent. For anything related to Notion content management, utilize NotionAgent. Ensure smooth collaboration between the agents. If any ambiguity arises in a task, ask for clarification before proceeding.In Notion always show details for pages like id, title, and page link

You are an agent. Your internal name is "coordinator".

Contents:
{"parts":[{"text":"can you show me reecent ai page"}],"role":"user"}

Functions:
SearchAgent: {'request': {'type': <Type.STRING: 'STRING'>}} -> None
NotionAgent: {'request': {'type': <Type.STRING: 'STRING'>}} -> None

2025-05-26 19:43:46,413 - INFO - google_llm.py:91 -
LLM Request:

System Instruction:
You are the CoordinatorAgent, responsible for managing and orchestrating specialized agents to complete tasks efficiently.

You have access to:

  • SearchAgent: An expert in performing web searches using Google.
  • NotionAgent: A Notion specialist who can read, write, search, and comment on Notion pages.

Your role is to delegate tasks to the appropriate agent based on their specialization. If a task requires external information, use SearchAgent. For anything related to Notion content management, utilize NotionAgent. Ensure smooth collaboration between the agents. If any ambiguity arises in a task, ask for clarification before proceeding.In Notion always show details for pages like id, title, and page link

You are an agent. Your internal name is "coordinator".

Contents:
{"parts":[{"text":"can you show me reecent ai page"}],"role":"user"}

Functions:
SearchAgent: {'request': {'type': <Type.STRING: 'STRING'>}} -> None
NotionAgent: {'request': {'type': <Type.STRING: 'STRING'>}} -> None

2025-05-26 19:43:46,413 - INFO - models.py:7118 - AFC is enabled with max remote calls: 10.
2025-05-26 19:43:48,404 - INFO - _client.py:1740 - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-04-17:generateContent "HTTP/1.1 200 OK"
2025-05-26 19:43:48,406 - WARNING - types.py:4572 - Warning: there are non-text parts in the response: ['function_call'], returning concatenated text result from text parts. Check the full candidates.content.parts accessor to get the full model response.
2025-05-26 19:43:48,406 - INFO - google_llm.py:148 -
LLM Response:

Text:
None

Function calls:
name: NotionAgent, args: {'request': 'show me recent ai page'}

Raw response:
{"candidates":[{"content":{"parts":[{"function_call":{"args":{"request":"show me recent ai page"},"name":"NotionAgent"}}],"role":"model"},"finish_reason":"STOP","index":0}],"model_version":"models/gemini-2.5-flash-preview-04-17","usage_metadata":{"candidates_token_count":19,"prompt_token_count":222,"prompt_tokens_details":[{"modality":"TEXT","token_count":222}],"thoughts_token_count":75,"total_token_count":316},"automatic_function_calling_history":[]}

2025-05-26 19:43:48,406 - INFO - google_llm.py:148 -
LLM Response:

Text:
None

Function calls:
name: NotionAgent, args: {'request': 'show me recent ai page'}

Raw response:
{"candidates":[{"content":{"parts":[{"function_call":{"args":{"request":"show me recent ai page"},"name":"NotionAgent"}}],"role":"model"},"finish_reason":"STOP","index":0}],"model_version":"models/gemini-2.5-flash-preview-04-17","usage_metadata":{"candidates_token_count":19,"prompt_token_count":222,"prompt_tokens_details":[{"modality":"TEXT","token_count":222}],"thoughts_token_count":75,"total_token_count":316},"automatic_function_calling_history":[]}

2025-05-26 19:43:48,408 - INFO - fast_api.py:814 - Generated event in agent run streaming: {"content":{"parts":[{"functionCall":{"id":"adk-de94915d-a991-432e-8936-1d9943c35331","args":{"request":"show me recent ai page"},"name":"NotionAgent"}}],"role":"model"},"usageMetadata":{"candidatesTokenCount":19,"promptTokenCount":222,"promptTokensDetails":[{"modality":"TEXT","tokenCount":222}],"thoughtsTokenCount":75,"totalTokenCount":316},"invocationId":"e-ef822dd1-0588-4a26-88d1-c6d456fdf92c","author":"coordinator","actions":{"stateDelta":{},"artifactDelta":{},"requestedAuthConfigs":{}},"longRunningToolIds":[],"id":"DS26lViq","timestamp":1748259826.148182}
2025-05-26 19:43:48,408 - INFO - fast_api.py:814 - Generated event in agent run streaming: {"content":{"parts":[{"functionCall":{"id":"adk-de94915d-a991-432e-8936-1d9943c35331","args":{"request":"show me recent ai page"},"name":"NotionAgent"}}],"role":"model"},"usageMetadata":{"candidatesTokenCount":19,"promptTokenCount":222,"promptTokensDetails":[{"modality":"TEXT","tokenCount":222}],"thoughtsTokenCount":75,"totalTokenCount":316},"invocationId":"e-ef822dd1-0588-4a26-88d1-c6d456fdf92c","author":"coordinator","actions":{"stateDelta":{},"artifactDelta":{},"requestedAuthConfigs":{}},"longRunningToolIds":[],"id":"DS26lViq","timestamp":1748259826.148182}
2025-05-26 19:43:48,418 - ERROR - fast_api.py:817 - Error in event_generator:
Traceback (most recent call last):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 806, in event_generator
async for event in runner.run_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 309, in _run_one_step_async
async for event in self._postprocess_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 381, in _postprocess_async
async for event in self._postprocess_handle_function_calls_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 456, in _postprocess_handle_function_calls_async
if function_response_event := await functions.handle_function_calls_async(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\functions.py", line 166, in handle_function_calls_async
function_response = await __call_tool_async(
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\functions.py", line 431, in __call_tool_async
return await tool.run_async(args=args, tool_context=tool_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\agent_tool.py", line 139, in run_async
async for event in runner.run_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 293, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 331, in _preprocess_async
for tool in await agent.canonical_tools(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 367, in canonical_tools
resolved_tools.extend(await _convert_tool_union_to_tools(tool_union, ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 114, in _convert_tool_union_to_tools
return await tool_union.get_tools(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 95, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 214, in get_tools
await self._initialize()
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 112, in _initialize
self._session, process = await self._session_manager.create_session()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 201, in create_session
session, process = await self._initialize_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 237, in _initialize_session
client, process = await cls._create_stdio_client(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 277, in _create_stdio_client
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\subprocess.py", line 224, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 1743, in subprocess_exec
transport = await self._make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 524, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError
2025-05-26 19:43:48,418 - ERROR - fast_api.py:817 - Error in event_generator:
Traceback (most recent call last):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\cli\fast_api.py", line 806, in event_generator
async for event in runner.run_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 309, in _run_one_step_async
async for event in self._postprocess_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 381, in _postprocess_async
async for event in self._postprocess_handle_function_calls_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 456, in _postprocess_handle_function_calls_async
if function_response_event := await functions.handle_function_calls_async(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\functions.py", line 166, in handle_function_calls_async
function_response = await __call_tool_async(
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\functions.py", line 431, in __call_tool_async
return await tool.run_async(args=args, tool_context=tool_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\agent_tool.py", line 139, in run_async
async for event in runner.run_async(
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\runners.py", line 196, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 147, in run_async
async for event in self._run_async_impl(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 278, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 279, in run_async
async for event in self._run_one_step_async(invocation_context):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 293, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 331, in _preprocess_async
for tool in await agent.canonical_tools(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 367, in canonical_tools
resolved_tools.extend(await _convert_tool_union_to_tools(tool_union, ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 114, in _convert_tool_union_to_tools
return await tool_union.get_tools(ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 95, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 214, in get_tools
await self._initialize()
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_toolset.py", line 112, in _initialize
self._session, process = await self._session_manager.create_session()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 201, in create_session
session, process = await self._initialize_session(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 237, in _initialize_session
client, process = await cls._create_stdio_client(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\tools\mcp_tool\mcp_session_manager.py", line 277, in create_stdio_client
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\subprocess.py", line 224, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 1743, in subprocess_exec
transport = await self.make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Roaming\uv\python\cpython-3.12.7-windows-x86_64-none\Lib\asyncio\base_events.py", line 524, in make_subprocess_transport
raise NotImplementedError
NotImplementedError
2025-05-26 19:43:48,423 - ERROR - init.py:157 - Failed to detach context
Traceback (most recent call last):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\opentelemetry\trace_init
.py", line 587, in use_span
yield span
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\opentelemetry\sdk\trace_init
.py", line 1105, in start_as_current_span
yield span
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\opentelemetry\trace_init
.py", line 452, in start_as_current_span
yield span
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 539, in _call_llm_async
yield llm_response
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\opentelemetry\context_init_.py", line 155, in detach
_RUNTIME_CONTEXT.detach(token)
File "D:\Documents\Python\git\agent system\anget_workflow.venv\Lib\site-packages\opentelemetry\context\contextvars_context.py", line 53, in detach
self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x0000020AC08BFC40> at 0x0000020ACDE5C380> was created in a different Context
`

@huang4956
Copy link

When I use adk web call Agent, I get the same error as @Anusha2015 , I am using google-adk 1.0.0,my Agent code is as follows:
`# ./adk_agent_samples/mcp_agent/agent.py
import os # Required for path operations
from google.adk.agents import LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters

TARGET_FOLDER_PATH = os.path.join(os.path.dirname(os.path.abspath(file)), "/path/to/your/folder")
#TARGET_FOLDER_PATH = "C:\Users\Administrator\PycharmProjects\ADK_Agent\mcp_agent\file_data"

root_agent = LlmAgent(
model='gemini-2.0-flash', # Adjust model name if needed based on availability
name='filesystem_assistant',
instruction='Help user interact with the local filesystem using available tools.',
tools=[
MCPToolset(
connection_params=StdioServerParameters(
command='npx.cmd',
args=["-y",
"@modelcontextprotocol/server-filesystem",
os.path.abspath(TARGET_FOLDER_PATH)],
)
)
],
)
`

@dominicdev
Copy link
Author

dominicdev commented May 27, 2025

still no update? I got another agent using google map working in temirnal but not in web

here is the current code

import asyncio
import os
from google.adk.agents import Agent, LlmAgent
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, StdioServerParameters

from dotenv import load_dotenv
import json
import nest_asyncio
nest_asyncio.apply()

load_dotenv()
google_maps_api_key = os.environ.get("GOOGLE_MAPS_API_KEY")

root_agent = LlmAgent(
name="google_maps_expert_agent",
description="A Google Maps expert agent that provides location-based information using connected MCP tools (e.g., for directions, nearby places, or location details).",
model="gemini-2.0-flash",
instruction=(
"You are the Google Maps Expert Agent. Your task is to assist users with geographic information using the connected Google Maps MCP tools.\n"
"1. Understand the Query: Determine what the user wants to know (e.g., nearby places, directions, location details).\n"
" - 'What’s nearby?' → Use a nearby places tool.\n"
" - 'How do I get from X to Y?' → Use a directions tool.\n"
" - 'Tell me more about [location]' → Use a location details tool.\n"
"2. Choose the Right Tool: Identify and use the most appropriate tool for the user’s request.\n"
" - Look through all available tools.\n"
" - Select the one that best matches the query type.\n"
" - Pass relevant parameters like location, place type, start and end points, or keywords.\n"
"3. Present the Results: Clearly share what the tool returns.\n"
" - Include names, distances, ratings, or directions if relevant.\n"
" - Mention the query type being answered.\n"
" - If the tool returns an error, state it accurately.\n"
"4. Handle Missing Capability: If no suitable tool is available, inform the user that you're unable to complete the request due to a configuration issue.\n"
"5. Strictly Use Tool Output: Never fabricate information. Only return data provided by the tools.\n"
),
tools=[MCPToolset(connection_params=StdioServerParameters(
command='npx.cmd',
args=["-y", "@modelcontextprotocol/server-google-maps"],
# Pass the API key as an environment variable to the npx process
# This is how the MCP server for Google Maps expects the key.
env={"GOOGLE_MAPS_API_KEY": google_maps_api_key}
))],
)

@huang4956
Copy link

@dominicdev refer to 378#(#387 have solved the problem. with the --no-reload option, the agent can be run in the terminal or on the web.

@seanzhou1023
Copy link
Collaborator

The issue should have been fixed in the latest codes. Let's verify the user's agent codes on HEAD

@seanzhou1023 seanzhou1023 added this to the FixIt Week milestone May 27, 2025
@genquan9
Copy link
Collaborator

I verified locally with https://github.com/google/adk-python/blob/main/contributing/samples/mcp_stdio_server_agent/agent.py and latest ADK, and it worked well.

@genquan9 genquan9 self-assigned this May 27, 2025
@genquan9
Copy link
Collaborator

Feel free to reopen if you can still reproduce on latest source. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Issues related to tools
Projects
None yet
Development

No branches or pull requests

5 participants