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

Conversation

Peleton-011
Copy link

Features

  • Fix MCPAgent to correctly reference self.mcp_clients.sessions instead of the obsolete self.mcp_clients.session.
  • Update _refresh_tools, think(), and cleanup() methods to properly support multiple MCP sessions.
  • Prevents runtime AttributeError when running run_mcp.py.

Feature Docs

  • No documentation updates required — internal bug fix only.

Influence

  • Fixes a blocking runtime bug introduced by MCPClients multi-session support (commit 7326cca).
  • Ensures MCPAgent can properly initialize, think, and clean up across sessions.
  • Unblocks users trying to run OpenManus MCP agents in stdio mode or others.

Result

  • Manual run after fix: agent initializes, connects via stdio, prompts the user, and executes successfully without crashes.
  • Verified that tools are properly refreshed and agent cleanup occurs without errors.

Other

  • This PR closes #1099.
  • Confirmed this was introduced in commit 7326cca4504fdaf5249ca3c2d36e39d09d83a6a7.
  • Future follow-up work: optional support for selecting among multiple sessions explicitly, if desired.

- Replace all accesses to `self.mcp_clients.session` with checks on `self.mcp_clients.sessions` (plural).
- Pick the first available session instead of assuming a single one.
- Aligns MCPAgent behavior with recent MCPClients refactor to support multi-server connections.
- Update `think()` and `cleanup()` methods to correctly check `self.mcp_clients.sessions` instead of the old `self.mcp_clients.session`.
- Prevent runtime AttributeError when the agent starts thinking or cleaning up.
- Fully align MCPAgent with MCPClients multi-session support.
- Allows agent to handle connections and disconnections properly after receiving user input.

This completes the migration to the new MCPClients structure where multiple sessions are supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants