Skip to content

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Sep 23, 2025

Why

What

  • Added eager_connect: bool = True to MCPTool and MCPToolset
  • MCPTool: added _ensure_connected(); in lazy mode uses a permissive schema then tightens after first invoke.
  • MCPToolset: if eager_connect=False, returns an empty toolset at construction; eager discovery path unchanged.
  • Added test_mcp_tool_lazy_connect_updates_schema unit test

How Can It Be Used

  • Lazy single tool (connects on first use):
    • tool = MCPTool(name="add", server_info=InMemoryServerInfo(...), eager_connect=False)
    • result = json.loads(tool.invoke(a=2, b=5))
  • Eager (default) single tool:
    • tool = MCPTool(name="add", server_info=InMemoryServerInfo(...)) # unchanged behavior

How Did You Test It

  • Added unit test validating lazy construction, first-use connect.
  • Ran existing unit/integration tests to ensure no regressions.
  • Ran itinerary agent with bunch of MCP tools to see if there are any regressions - none!

Notes For The Reviewer

  • Default behavior is unchanged; lazy path only activates with eager_connect=False.
  • Serialization now includes eager_connect; deserialization defaults to True if missing (backward compatible).
  • Changes are surgical, confined to mcp_tool.py, mcp_toolset.py, and one new test.
  • Lazy connect is thread-safe (RLock)

@github-actions github-actions bot added integration:mcp type:documentation Improvements or additions to documentation labels Sep 23, 2025
@vblagoje vblagoje marked this pull request as ready for review September 24, 2025 09:49
@vblagoje vblagoje requested a review from a team as a code owner September 24, 2025 09:49
@vblagoje vblagoje requested review from Amnah199 and removed request for a team September 24, 2025 09:49
@vblagoje vblagoje marked this pull request as draft September 24, 2025 10:14
@vblagoje
Copy link
Member Author

@Amnah199 converting to draft - getting some unusual behaviour with eager_connect = False in itinerary agent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:mcp type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MCPToolset raises MCPConnectionError in init if authentication fails
1 participant