-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix: Resolve asyncio 'NotImplementedError' for 'adk web' on Windows and test import issues (#585) #958
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
Conversation
PiperOrigin-RevId: 763648920
…issues (google#585) This pull request addresses a `NotImplementedError` encountered when running `adk web` with MCP tools on Windows, which was caused by issues with `asyncio` subprocess creation in the Uvicorn/FastAPI environment. It also resolves several `ImportError`s that were occurring during unit tests. **Key Changes:** * **Asyncio Subprocess Management (Windows):** * Ensured `WindowsProactorEventLoopPolicy` is consistently applied for `adk web` by prioritizing its setup in `google/adk/cli/cli_tools_click.py`. * Disabled Uvicorn's auto-reload feature on Windows to prevent potential event loop conflicts that can interfere with `asyncio` subprocesses. * Refactored `google/adk/tools/mcp_tool/mcp_session_manager.py` to use `asyncio.create_subprocess_exec` directly for creating MCP tool subprocesses on Windows. This includes the use of a `StreamWriterWrapper` (adjust if not used) to ensure compatibility with the asyncio streams. * **Test Import Fixes:** * Created the missing `EvalSetResult` definition (e.g., class `EvalSetResult: pass`) in `google/adk/cli/cli_eval.py`. This resolves import errors in tests that depend on `google/adk/cli/fast_api.py`. * Adjusted the `agent_dir` parameter handling within `google/adk/cli/fast_api.py` to align with expectations from `test_fast_api.py`, resolving related import or runtime errors in tests. (Ensure you've made this specific change based on your findings). These changes allow `adk web` to function correctly with MCP tools on Windows and ensure the relevant unit tests can pass. Fixes google#585
@Kk12suthar Please resolve the conflicts. @wyf7107 @ankursharmas PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
why are we changing eval related code? If not intended, could you remove those changes and focus on the asyncio issue in this PR?
Ohh So Eval code change was originally not intended it was done during unit testing when i saw the difference in eval file of both version ( one of this cloned repo and other was google-adk 1.0.0 (pip install)) so i had to stay with running code so i decided that i should just use the version 1.0.0 code if its stable. All the cases ran fine when i did the unit testing locally and after then i did made a PR. Also i noticed one more thing that you addressed that asyncio issue is now resolved in adk version==1.1.0 but i dont think so because when i tried it gave me the same error for adk web. Thanks Edit-: I did install the latest version of google-adk(1.1.0) tried and fixed it with the same issues without changing the eval code. So the latest merge bring those changes please review them and let me know |
This commit addresses a series of issues primarily related to the management and operation of MCP (Model Context Protocol) sessions, particularly over stdio on Windows. Key changes include: - Refactored MCP stdio client handling in `mcp_session_manager.py`: - The `_create_stdio_client` method now consistently uses `mcp.client.stdio.stdio_client` for all platforms. - This removes the custom `StreamWriterWrapper` and `manual_stdio_transport` logic, which was a source of serialization errors (e.g., `SessionMessage` encoding, `cbor2` dependency) and import issues (`mcp.common`). This change delegates stdio transport and serialization to the `mcp` library, improving robustness. - Corrected session object handling in `MCPToolset` and `MCPTool`: - Ensured that the `(session, process)` tuple returned by `MCPSessionManager.create_session()` is correctly unpacked. - `self._session` in `MCPToolset` and the local `session` variable in `MCPTool.run_async()` now correctly reference the `ClientSession` object, resolving `AttributeError`s for `list_tools` and `call_tool`. - Improved resource management in `MCPToolset`: - Ensured `AsyncExitStack` is properly initialized, passed to `MCPSessionManager`, and closed in `MCPToolset.close()`. - Addressed miscellaneous errors in `fast_api.py`: - Corrected the import location for `EvalSetResult`. - Fixed an incorrect keyword argument (`agent_dir` to `agents_dir`) in `LocalEvalSetsManager` initialization. These changes collectively stabilize the `adk web` functionality by resolving critical runtime errors during MCP session establishment and tool invocation.
aaf87e2
to
6a6e436
Compare
get_fast_api expects keywords "agent_dir" not "agents_dir"
Could you resolve the conflicts? |
Feel free to re-open after the conflicts are resolved. |
This pull request addresses a
NotImplementedError
encountered when runningadk web
with MCP tools on Windows, which was caused by issues withasyncio
subprocess creation in the Uvicorn/FastAPI environment. It also resolves severalImportError
s that were occurring during unit tests.Key Changes:
Asyncio Subprocess Management (Windows):
WindowsProactorEventLoopPolicy
is consistently applied foradk web
by prioritizing its setup ingoogle/adk/cli/cli_tools_click.py
.asyncio
subprocesses.google/adk/tools/mcp_tool/mcp_session_manager.py
to useasyncio.create_subprocess_exec
directly for creating MCP tool subprocesses on Windows. This includes the use of aStreamWriterWrapper
(adjust if this was not part of your final implementation) to ensure compatibility with the asyncio streams.Test Import Fixes:
EvalSetResult
definition (e.g., classEvalSetResult: pass
) ingoogle/adk/cli/cli_eval.py
. This resolves import errors in tests that depend ongoogle/adk/cli/fast_api.py
.agent_dir
parameter handling withingoogle/adk/cli/fast_api.py
to align with expectations fromtest_fast_api.py
. (Please ensure this specific change has been made based on your detailed investigation).These changes aim to allow
adk web
to function correctly with MCP tools on Windows and ensure the relevant unit tests can pass.Fixes #585