Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR integrates MCP sessions, converts tool execution to async, and reorganizes decorators for cleaner control flow.
- Introduces
MCPSessionManagerand updates main to discover and load MCP tools. - Refactors
process_tool_callsand all toolrunmethods to async with callback support. - Adds utility decorators (
graceful_exit,mainloop,chatutil) and updates tests for async behavior.
Reviewed Changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_agent_root.py | Updated tests to call process_tool_calls asynchronously with callbacks |
| tests/test_agent_process_coverage.py | Added async tests for edge cases in process_tool_calls |
| tests/test_agent_main_block.py | Added asyncio-based test for the __main__ block |
| tests/test_agent_edge_cases.py | Consolidated and converted edge-case tests to a single async test |
| tests/test_agent_additional.py | Updated exception-handling tests to async callbacks |
| src/utils/mcpclient/sessions_manager.py | New MCPSessionManager for loading and listing MCP servers |
| src/utils/mcpclient/session.py | New MCPSession wrapper for MCP client with graceful exits |
| src/utils/mcpclient/client.py | Removed example client script |
| src/utils/azureopenai/chat.py | Added add_tool method to register MCP tools dynamically |
| src/utils/init.py | Introduced mainloop, graceful_exit, and chatutil decorators |
| src/tools/write_file.py | Converted run to async |
| src/tools/web_fetch.py | Converted run to async |
| src/tools/read_file.py | Converted run to async |
| src/tools/list_files.py | Converted run to async |
| src/tools/google_search.py | Converted run to async |
| src/tools/init.py | Enhanced Tool class to support async tool execution |
| src/main.py | Orchestrates MCP discovery, decorator-driven loops, and agent tasks |
| src/chat.py | Updated decorators and fixed invocation of run_conversation |
| src/agent.py | Refactored to async process_tool_calls, added callback API |
| config/mcp.template.json | Added template for MCP configuration |
Comments suppressed due to low confidence (5)
src/agent.py:30
- [nitpick] The parameter
call_backwould be clearer ascallback(no underscore) to match common naming conventions.
async def process_tool_calls(response: Dict[str, Any], call_back) -> None:
src/utils/mcpclient/sessions_manager.py:10
- There are no tests covering
MCPSessionManager.load_mcp_sessionsorlist_tools. Consider adding unit tests or integration tests for session loading and tool listing.
class MCPSessionManager:
src/utils/mcpclient/sessions_manager.py:15
- The return type is annotated as
Dict[str, MCPSession]but the method returnsTrueorNone. Update it to returnself._sessionson success or raise/log errors, and adjust the type hint accordingly.
async def load_mcp_sessions(self) -> Dict[str, mcp.MCPSession]:
src/utils/init.py:35
- The
chatutildecorator’s_wrapperdoes not return the wrapped function’s result, so the decorated function always returnsNone. Addreturn resultat the end of_wrapper.
async def _wrapper(*args, **kwargs):
tests/test_agent_root.py:28
- This test uses
asyncio.runbut the module doesn’t importasyncio. Addimport asyncioat the top of the file soasyncio.runis defined.
with patch('builtins.print'): # Suppress print output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant enhancements to the MCP integration, asynchronous tool execution, and overall code organization. Key changes include the implementation of an MCP session manager, refactoring tool execution to support asynchronous operations, and introducing utility decorators for improved code readability and error handling. Below is a categorized summary of the most important changes: