281 make mcp clients persist throughout the run#289
Conversation
…persist-throughout-the-run
There was a problem hiding this comment.
Pull Request Overview
This PR overhauls the MCP client integration by replacing the old from_mcp_server helper with a new MCPServer class that maintains a persistent client connection and exposes tools via a .tools property. It also refactors MCPAsyncClient to use explicit connect() and close() methods instead of async context managers, and removes the OAuth callback server code.
- Refactored
MCPAsyncClientto useconnect()/close()in place of__aenter__/__aexit__ - Introduced
MCPServerclass and updatedfrom_mcp_serverto return anMCPServerinstance - Updated tests, examples, and documentation to reference
MCPServerand its.toolsproperty
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/requestcompletion/rc_mcp/main.py | Added connect/close methods, introduced MCPServer, updated from_mcp |
| src/requestcompletion/nodes/library/mcp_tool.py | Changed from_mcp_server to return MCPServer and removed async helper |
| tests/unit_tests/rc_mcp/test_oauth.py | Removed obsolete OAuth tests |
| tests/unit_tests/rc_mcp/test_main.py | Updated client tests for new connect/close API |
| tests/integration_tests/rc_mcp/*.py | Adapted integration tests to use server.tools |
| examples/rc_basics/.py, examples/integrations/.py | Updated examples to assign from_mcp_server result to server and use .tools |
| docs/tools/guides/*.md | Updated code snippets to use MCPServer |
Comments suppressed due to low confidence (4)
src/requestcompletion/nodes/library/mcp_tool.py:16
- The docstring for
from_mcp_serverstill says it returns a list of Node classes, but the function now returns anMCPServerinstance. Please update the docstring to reflect the new return type.
List of Nodes, one for each discovered tool.
docs/tools/guides/websearch_integration.md:50
- There's a TODO in the documentation link. Please update the link to the correct location for the
from_mcp_serverreference.
Read more about the `from_mcp_server` utility [TODO: change this link](../../mcp/index.md). <br>
examples/rc_basics/mcp_example.py:5
- The symbol
async_from_mcp_serverwas removed in this PR, so importing it will cause an error. Remove or update that import to only referencefrom_mcp_server.
from requestcompletion.nodes.library.mcp_tool import async_from_mcp_server, from_mcp_server
Aryan-Railtown
left a comment
There was a problem hiding this comment.
Another small thing. I believe patch_httpx_AsyncClient fixture in the conftest for unit_tests/rc_mcp folder is not being used elsewhere. That can be safely remove.
Other than that, the tests and implementation looko good to me 👍
soulFood5632
left a comment
There was a problem hiding this comment.
Some design comments around the approach. Looking forward to your responses
…make-mcp-clients-persist-throughout-the-run

This PR is somewhat of an overhaul of how from_mcp_server works. from_mcp_server no longer returns a list of tools/nodes, but instead a new class, MCPServer. This is the new user facing MCP interaction object. It allows for clients to be persistent, and gives the user control to be able to close the server. To get the tools like we did before, MCPServer.tools returns the same list.
So, usage will be as follows: