Introduce MCP tools#2427
Merged
openminddev merged 32 commits intomainfrom Apr 3, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
openminddev
reviewed
Apr 2, 2026
Comment on lines
+623
to
+624
| self.current_config.cortex_llm, | ||
| dispatch_om1=self.action_orchestrator.promise, |
Contributor
There was a problem hiding this comment.
Please store both of them in the initialization.
openminddev
reviewed
Apr 2, 2026
* Refactor MCP action execution and handling Add a guard for missing MCP server config and refactor how MCP actions are executed. extract_mcp_actions was replaced by execute_mcp_actions which filters out already-succeeded calls (using a succeeded_calls set), runs new MCP actions, updates succeeded_calls in-place, and returns (results, mcp_actions) or (None, None) when no new actions remain. The internal concurrent executor was renamed to _execute_mcp_actions. Updated ModeCortexRuntime to consume the new API, break when there are no new MCP actions, and adjust logging to report the executed action count. * Rename origin_mcp_actions to all_mcp_actions Rename local variable origin_mcp_actions to all_mcp_actions in MCPOrchestrator._get_mcp_actions to improve clarity. No logic changes; comprehensions were updated to use the new name when filtering MCP tool actions and excluding already-succeeded call signatures. * Abort on invalid cortex generation and LLM cancel Add guards to abort processing when the cortex loop generation has changed to avoid using stale LLM responses. Inserted generation checks before and after the recall LLM call with informative logging and an early return to discard invalidated responses. Wrap the LLM call in a try/except to log and re-raise asyncio.CancelledError so cancellations during mode transitions are handled cleanly. Minor restructuring of output None handling to accommodate these checks. * Remove redundant output assignment Remove a redundant `output = None` assignment in ModeCortexRuntime when `output` is already `None`. This is a minor cleanup to eliminate a no-op statement and clarify the control flow before the break; no behavior changes expected. * Centralize cortex generation validation Add a private _is_generation_valid method to ModeCortexRuntime to consolidate generation checks and provide consistent logging/context. Replace duplicated inline generation comparisons in the cortex loop, tick handling, LLM calls, MCP execution, and MCP recall prompt with calls to this helper, reducing code duplication and standardizing early-exit behavior when the cortex generation mismatches. * Remove type annotation on succeeded_calls In src/runtime/cortex.py, replace the annotated assignment `succeeded_calls: set = set()` with a plain assignment `succeeded_calls = set()` inside ModeCortexRuntime's mcp_orchestrator block. This simplifies the variable initialization and avoids potential issues with inline type annotations or compatibility with tooling. * update mcp orchestrator * fix tests * fix logic * fix lint * update comment * update comment --------- Co-authored-by: YuchengZhou821 <yucheng@openmind.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces integration with MCP servers, enabling external tool execution and orchestration within the runtime system. The changes add support for configuring MCP servers, managing their connections, injecting tool schemas into the LLM, and handling tool calls and results in the agent's workflow. The implementation is modular, with new classes for client management and orchestration, and updates to configuration and runtime initialization to support MCP functionality.
MCP Server Integration and Orchestration
MCPClientManagerand transport support for stdio and HTTP, including tool discovery, schema conversion, and tool call execution (src/mcp_servers/client.py).MCPOrchestratorto manage MCP tool execution, intercept tool calls from LLM output, execute tools concurrently, and re-invoke LLM with tool results (src/mcp_servers/orchestrator.py).load_mcp) to initialize connections based on configuration (src/mcp_servers/__init__.py).Configuration and Runtime Changes
ModeConfigandRuntimeConfigto support MCP server configuration, including parsing and loading from config files (src/runtime/config.py,src/runtime/converter.py). [1] [2] [3] [4] [5] [6] [7]src/runtime/cortex.py). [1] [2] [3] [4]LLM and Action Handling
src/llm/function_schemas.py).src/runtime/cortex.py).Prompt and Tool Description Improvements
src/fuser/__init__.py).These changes collectively enable seamless integration of external MCP tools into the agent's workflow, allowing the LLM to call tools, receive results, and generate informed responses.