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

Open
dominicdev opened this issue May 23, 2025 · 1 comment
Open

ADK web not working, but runs in terminal #893

dominicdev opened this issue May 23, 2025 · 1 comment
Assignees
Labels
tools Issues related to tools

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
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

2 participants