Feature/133 mcptoolfactory fetch tools without event loop #139
+556
−4
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.
Adds
fetch_mcp_tools_async
, enabling nativeawait
-based tool fetching and removing the need to pass an event loop (closes #133). Docs, sample client, and tests were updated.This was actually pretty difficult and non trivial to make work. I tried a number of different ways to get this working without adding a new async api function to MCPToolFactory, but wasn't able to get it working. Maybe theres something I haven't considered, but opening this pr none the less with what i have.
GITHUB COPILOT SUMMARY
This pull request introduces a new asynchronous method for fetching MCP tools, updates the documentation to reflect the new functionality, and adds extensive test coverage for the feature. Additionally, an example client implementation demonstrates the usage of the new asynchronous method.
New Asynchronous Tool Fetching
atomic_agents/lib/factories/mcp_tool_factory.py
: Addedfetch_mcp_tools_async
, an asynchronous method for dynamically generatingBaseTool
subclasses by connecting to an MCP server. This method supports multiple transport types (STDIO, HTTP_STREAM, SSE) and allows for an optional pre-initializedClientSession
.Test Coverage for Asynchronous Fetching
atomic_agents/tests/lib/factories/test_mcp_tool_factory.py
: Added comprehensive tests forfetch_mcp_tools_async
, covering scenarios such as fetching with and without a client session, handling different transport types, multiple tool definitions, and error propagation (e.g., connection errors, runtime errors).Example Usage
atomic-examples/mcp-agent/example-client/example_client/main_stdio_async.py
: Added a new example client demonstrating how to usefetch_mcp_tools_async
with STDIO transport. The example includes initializing an MCP server, fetching tools asynchronously, and interacting with the tools in a chat-like interface.Documentation Updates
docs/examples/mcp_agent.md
: Updated documentation to include examples of both synchronous and asynchronous tool fetching, highlighting the advantages of each approach. Detailed explanations of supported transport types and their use cases were also added. [1] [2] [3]Minor Updates
atomic_agents/tests/lib/factories/test_mcp_tool_factory.py
: Updated imports to includefetch_mcp_tools_async
.