Skip to content

Introduce MCP tools#2427

Merged
openminddev merged 32 commits intomainfrom
Introduce-MCP-support
Apr 3, 2026
Merged

Introduce MCP tools#2427
openminddev merged 32 commits intomainfrom
Introduce-MCP-support

Conversation

@YuchengZhou821
Copy link
Copy Markdown
Contributor

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

  • Added MCPClientManager and transport support for stdio and HTTP, including tool discovery, schema conversion, and tool call execution (src/mcp_servers/client.py).
  • Introduced MCPOrchestrator to 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).
  • Provided a loader function for MCP servers (load_mcp) to initialize connections based on configuration (src/mcp_servers/__init__.py).

Configuration and Runtime Changes

  • Extended ModeConfig and RuntimeConfig to 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]
  • Updated runtime initialization and orchestrator lifecycle to create and close MCP orchestrator, ensuring proper startup and shutdown of MCP connections (src/runtime/cortex.py). [1] [2] [3] [4]

LLM and Action Handling

  • Injected MCP tool schemas into LLM function schemas, and updated action conversion logic to handle MCP tool calls distinctly (src/llm/function_schemas.py).
  • Modified the agent tick loop to process MCP tool actions and merge results before further action execution (src/runtime/cortex.py).

Prompt and Tool Description Improvements

  • Enhanced agent prompt generation to include descriptions of available MCP tools for LLM guidance (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.

Copilot AI review requested due to automatic review settings February 27, 2026 01:40
@YuchengZhou821 YuchengZhou821 requested review from a team as code owners February 27, 2026 01:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 82.15488% with 53 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/runtime/cortex.py 52.17% 22 Missing ⚠️
src/mcp_servers/client.py 88.07% 18 Missing ⚠️
src/mcp_servers/orchestrator.py 89.15% 9 Missing ⚠️
src/fuser/__init__.py 25.00% 3 Missing ⚠️
src/llm/function_schemas.py 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.

Comment thread src/runtime/config.py Outdated
Comment thread src/mcp_servers/client.py
Comment thread src/mcp_servers/__init__.py Outdated
Comment thread src/mcp_servers/orchestrator.py Outdated
Comment thread src/llm/function_schemas.py
Comment thread src/runtime/config.py Outdated
Comment thread src/mcp_servers/client.py Outdated
Comment thread src/runtime/cortex.py Outdated
Comment thread src/mcp_servers/client.py Outdated
Comment thread src/runtime/config.py
@YuchengZhou821 YuchengZhou821 requested a review from a team as a code owner February 28, 2026 01:54
@github-actions github-actions Bot added the tests Test files label Feb 28, 2026
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file config Configuration files labels Feb 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 6 comments.

Comment thread src/mcp_servers/orchestrator.py
Comment thread src/runtime/cortex.py Outdated
Comment thread src/runtime/cortex.py Outdated
Comment thread src/llm/function_schemas.py
Comment thread src/runtime/config.py
Comment thread src/mcp_servers/client.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 3 comments.

Comment thread src/mcp_servers/client.py Outdated
Comment thread src/mcp_servers/client.py Outdated
Comment thread src/runtime/cortex.py Outdated
@github-actions github-actions Bot added the infrastructure Docker/Infrastructure label Mar 5, 2026
Comment thread src/runtime/cortex.py Outdated
Comment on lines +623 to +624
self.current_config.cortex_llm,
dispatch_om1=self.action_orchestrator.promise,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please store both of them in the initialization.

Comment thread src/runtime/cortex.py Outdated
YuchengZhou821 and others added 5 commits April 2, 2026 16:44
* 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>
@openminddev openminddev merged commit 834c9d1 into main Apr 3, 2026
6 checks passed
@openminddev openminddev deleted the Introduce-MCP-support branch April 3, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Configuration files dependencies Pull requests that update a dependency file infrastructure Docker/Infrastructure python Python code robotics Robotics code changes tests Test files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants