Skip to content

Conversation

@lvliang-intel
Copy link
Collaborator

@lvliang-intel lvliang-intel commented May 8, 2025

Description

Enable MCP client tool for Agent

Issues

1832

Type of change

List the type of change like below. Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would break existing design and interface)
  • Others (enhancement, documentation, validation, etc.)

Dependencies

mcp

Tests

Local test and unit test.

[2025-05-08 06:02:38,047] [ INFO] - comps-mcp-manager - Initializing MCP client for SSE server: http://localhost:8931/sse
[2025-05-08 06:02:38,092] [ INFO] - comps-mcp-client - Connected to server with tools: ['browser_close', 'browser_wait', 'browser_resize', 'browser_console_messages', 'browser_handle_dialog', 'browser_file_upload', 'browser_install', 'browser_press_key', 'browser_navigate', 'browser_navigate_back', 'browser_navigate_forward', 'browser_network_requests', 'browser_pdf_save', 'browser_snapshot', 'browser_click', 'browser_drag', 'browser_hover', 'browser_type', 'browser_select_option', 'browser_take_screenshot', 'browser_tab_list', 'browser_tab_new', 'browser_tab_select', 'browser_tab_close', 'browser_generate_playwright_test']
[2025-05-08 06:02:38,093] [ INFO] - comps-mcp-manager - Successfully connected to MCP server: url='http://localhost:8931/sse' api_key=None
[2025-05-08 06:02:38,093] [ INFO] - comps-mcp-manager - Initializing MCP client for Stdio server: uv
[2025-05-08 06:02:38,646] [ INFO] - comps-mcp-client - Connected to server with tools: ['fetch']
[2025-05-08 06:02:38,646] [ INFO] - comps-mcp-manager - Successfully connected to MCP server: name='mcp-simple-tool' command='uv' args=['run', 'mcp-simple-tool'] env={}

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
…to agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
pre-commit-ci bot and others added 3 commits May 8, 2025 13:19
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
…enAIComps into agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
pre-commit-ci bot and others added 7 commits May 8, 2025 14:02
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
…enAIComps into agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
…enAIComps into agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
@codecov
Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 58 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
comps/cores/mcp/client.py 61.17% 33 Missing ⚠️
comps/cores/mcp/manager.py 82.95% 15 Missing ⚠️
comps/cores/mcp/config.py 58.33% 10 Missing ⚠️
Files with missing lines Coverage Δ
comps/cores/mcp/tool.py 100.00% <100.00%> (ø)
comps/cores/mcp/config.py 58.33% <58.33%> (ø)
comps/cores/mcp/manager.py 82.95% <82.95%> (ø)
comps/cores/mcp/client.py 61.17% <61.17%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lvliang-intel lvliang-intel changed the title Enable MCP client tool for Agent FEAT: Enable MCP client tool for Agent May 11, 2025
lvliang-intel and others added 5 commits May 11, 2025 21:18
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
…enAIComps into agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
@Spycsh
Copy link
Collaborator

Spycsh commented May 12, 2025

For the client side, I think a FastMCP client is a cleaner solution. https://gofastmcp.com/clients/client

import asyncio
from fastmcp import Client, FastMCP

# Example transports (more details in Transports page)
server_instance = FastMCP(name="TestServer") # In-memory server
sse_url = "http://localhost:8000/sse"       # SSE server URL
ws_url = "ws://localhost:9000"             # WebSocket server URL
server_script = "my_mcp_server.py"         # Path to a Python server file

# Client automatically infers the transport type
client_in_memory = Client(server_instance)
client_sse = Client(sse_url)
client_ws = Client(ws_url)
client_stdio = Client(server_script)

print(client_in_memory.transport)
print(client_sse.transport)
print(client_ws.transport)
print(client_stdio.transport)

# Expected Output (types may vary slightly based on environment):
# <FastMCP(server='TestServer')>
# <SSE(url='http://localhost:8000/sse')>
# <WebSocket(url='ws://localhost:9000')>
# <PythonStdioTransport(command='python', args=['/path/to/your/my_mcp_server.py'])>

Copy link
Collaborator

@Spycsh Spycsh left a comment

Choose a reason for hiding this comment

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

LGTM, but I doubt whether it is necessary to use a registry pattern here. One good example what the FastMCP does: https://gofastmcp.com/clients/client, which provides methods such as:
list_tools, list_resources, call_tool and also manage different transport automatically (be checking the url format) instead of passing different OpeaMCPxxxServerConfig.

@minmin-intel
Copy link
Collaborator

@lvliang-intel @Spycsh Do we have a conclusion on whether using fastmcp or not? what are the pros and cons of the methods implemented by @lvliang-intel vs. fastmcp?

@joshuayao joshuayao linked an issue May 13, 2025 that may be closed by this pull request
@Spycsh
Copy link
Collaborator

Spycsh commented May 13, 2025

@minmin-intel we will suggest users to use OPEA MCP client. There should not be any difference between FastMCP/OPEA's. The initial plan is to only use the official mcp package but only the server side from FastMCP 1.0 was migrated into the official mcp. Since we only want to use that part from official mcp python sdk, we need another OPEA MCP client implementation aligned with the FastMCP's client.

…to agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
…enAIComps into agent_mcp_client

Signed-off-by: lvliang-intel <liang1.lv@intel.com>
lvliang-intel and others added 4 commits June 10, 2025 15:31
Copy link
Collaborator

@lkk12014402 lkk12014402 left a comment

Choose a reason for hiding this comment

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

LGTM

@lvliang-intel lvliang-intel merged commit 1647423 into opea-project:main Jun 10, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Model Context Protocol (MCP) Compatibility for Agent

4 participants