Skip to content

Fix MCPAgent AttributeError due to outdated session references after MCPClients refactor #1110

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/agent/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ async def _refresh_tools(self) -> Tuple[List[str], List[str]]:
Returns:
A tuple of (added_tools, removed_tools)
"""
if not self.mcp_clients.session:
session = next(iter(self.mcp_clients.sessions.values()), None)
if not session:
return [], []

# Get current tool schemas directly from the server
response = await self.mcp_clients.session.list_tools()
response = await session.list_tools()
current_tools = {tool.name: tool.inputSchema for tool in response.tools}

# Determine added, removed, and changed tools
Expand Down Expand Up @@ -134,7 +135,7 @@ async def _refresh_tools(self) -> Tuple[List[str], List[str]]:
async def think(self) -> bool:
"""Process current state and decide next action."""
# Check MCP session and tools availability
if not self.mcp_clients.session or not self.mcp_clients.tool_map:
if not self.mcp_clients.sessions or not self.mcp_clients.tool_map:
logger.info("MCP service is no longer available, ending interaction")
self.state = AgentState.FINISHED
return False
Expand Down Expand Up @@ -171,7 +172,7 @@ def _should_finish_execution(self, name: str, **kwargs) -> bool:

async def cleanup(self) -> None:
"""Clean up MCP connection when done."""
if self.mcp_clients.session:
if self.mcp_clients.sessions:
await self.mcp_clients.disconnect()
logger.info("MCP connection closed")

Expand Down