🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
chore: update mcp usage in test,support all connection modes (#2370)
Wendong-Fand95cf864af32
diff --git a/.gitignore b/.gitignoreindex 304d67d83..2c75b3562 100644--- a/.gitignore+++ b/.gitignore@@ -430,4 +430,7 @@ benchmark/gaia/Datasetbenchmark/gaia/results.jsonl# Secret files for docker-.container/.env\ No newline at end of file+.container/.env++# Environment variables file+.env\ No newline at end of filediff --git a/camel/toolkits/base.py b/camel/toolkits/base.pyindex 31e5d92cc..19420f9e5 100644--- a/camel/toolkits/base.py+++ b/camel/toolkits/base.py@@ -53,10 +53,13 @@ class BaseToolkit(metaclass=AgentOpsMeta):"""raise NotImplementedError("Subclasses must implement this method.")- def run_mcp_server(self, mode: Literal["stdio", "sse"]) -> None:+ def run_mcp_server(+ self, mode: Literal["stdio", "sse", "streamable-http"]+ ) -> None:r"""Run the MCP server in the specified mode.Args:- mode (Literal["stdio", "sse"]): The mode to run the MCP server in.+ mode (Literal["stdio", "sse", "streamable-http"]): The mode to run+ the MCP server in."""self.mcp.run(mode)diff --git a/camel/toolkits/mcp_toolkit.py b/camel/toolkits/mcp_toolkit.pyindex 18e0ca4cb..d285477b8 100644--- a/camel/toolkits/mcp_toolkit.py+++ b/camel/toolkits/mcp_toolkit.py@@ -42,7 +42,7 @@ logger = get_logger(__name__)class MCPClient(BaseToolkit):r"""Internal class that provides an abstraction layer to interact with- external tools using the Model Context Protocol (MCP). It supports two+ external tools using the Model Context Protocol (MCP). It supports threemodes of connection:1. stdio mode: Connects via standard input/output streams for local@@ -51,6 +51,9 @@ class MCPClient(BaseToolkit):2. SSE mode (HTTP Server-Sent Events): Connects via HTTP for persistent,event-based interactions.+ 3. streamable-http mode: Connects via HTTP for persistent, streamable+ interactions.+Attributes:command_or_url (str): URL for SSE mode or command executable for stdiomode. (default: :obj:`None`)@@ -328,8 +331,6 @@ class MCPClient(BaseToolkit):"additionalProperties": False,}- # Because certain parameters in MCP may include keywords that are not- # supported by OpenAI, it is essential to set "strict" to False.return {"type": "function","function": {diff --git a/docs/key_modules/tools.md b/docs/key_modules/tools.mdindex a54c1a88e..0e055937c 100644--- a/docs/key_modules/tools.md+++ b/docs/key_modules/tools.md@@ -220,7 +220,7 @@ if __name__ == "__main__":)parser.add_argument("--mode",- choices=["stdio", "sse"],+ choices=["stdio", "sse", "streamable-http"],default="stdio",help="MCP server mode (default: 'stdio')",)diff --git a/examples/mcp_arxiv_toolkit/arxiv_toolkit_server.py b/examples/mcp_arxiv_toolkit/arxiv_toolkit_server.pyindex c04631b90..547512816 100644--- a/examples/mcp_arxiv_toolkit/arxiv_toolkit_server.py+++ b/examples/mcp_arxiv_toolkit/arxiv_toolkit_server.py@@ -23,7 +23,7 @@ if __name__ == "__main__":)parser.add_argument("--mode",- choices=["stdio", "sse"],+ choices=["stdio", "sse", "streamable-http"],default="stdio",help="MCP server mode (default: 'stdio')",)diff --git a/test/utils/test_mcp_server.py b/test/utils/test_mcp_server.pyindex 907861f6c..6f79868a3 100644--- a/test/utils/test_mcp_server.py+++ b/test/utils/test_mcp_server.py@@ -13,7 +13,7 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========import asyncioimport sys-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, Literalimport pytestfrom mcp.server import FastMCP@@ -53,6 +53,17 @@ class TextProcessorForMCP:await asyncio.sleep(0.01)return len(text.split())+ def run_mcp_server(+ self, mode: Literal["stdio", "sse", "streamable-http"]+ ) -> None:+ r"""Run the MCP server in the specified mode.++ Args:+ mode (Literal["stdio", "sse", "streamable-http"]): The mode to run+ the MCP server in.+ """+ self.mcp.run(mode)+def test_tool_schema():processor = TextProcessorForMCP()@@ -113,4 +124,4 @@ async def test_async_word_count():if __name__ == "__main__":if "--server" in sys.argv:processor = TextProcessorForMCP()- processor.mcp.run("stdio")+ processor.run_mcp_server("stdio")