Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

enhancement: support type:sse in MCP client argument (#2781)

Xiaotian Jincb3a5009ae4e
diff --git a/camel/utils/mcp_client.py b/camel/utils/mcp_client.py
index 5f1f6911a..7df3d861c 100644
--- a/camel/utils/mcp_client.py
+++ b/camel/utils/mcp_client.py
@@ -113,7 +113,11 @@ class ServerConfig(BaseModel):
# Advanced options
sse_read_timeout: float = 300.0 # 5 minutes
terminate_on_close: bool = True
- # For HTTP URLs, prefer SSE over StreamableHTTP
+
+ # New transport type parameter
+ type: Optional[str] = None
+
+ # Legacy parameter for backward compatibility
prefer_sse: bool = False
@model_validator(mode='after')
@@ -128,11 +132,43 @@ class ServerConfig(BaseModel):
if self.command and self.url:
raise ValueError("Cannot specify both 'command' and 'url'")
+ # Validate type if provided
+ if self.type is not None:
+ valid_types = {"stdio", "sse", "streamable_http", "websocket"}
+ if self.type not in valid_types:
+ raise ValueError(
+ f"Invalid type: "
+ f"'{self.type}'. "
+ f"Valid options: {valid_types}"
+ )
+
+ # Issue deprecation warning if prefer_sse is used
+ if self.prefer_sse and self.type is None:
+ import warnings
+
+ warnings.warn(
+ "The 'prefer_sse' parameter is deprecated. "
+ "Use 'type=\"sse\"' instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+
return self
@property
def transport_type(self) -> TransportType:
r"""Automatically detect transport type based on configuration."""
+ # Use explicit transport type if provided
+ if self.type is not None:
+ transport_map = {
+ "stdio": TransportType.STDIO,
+ "sse": TransportType.SSE,
+ "streamable_http": TransportType.STREAMABLE_HTTP,
+ "websocket": TransportType.WEBSOCKET,
+ }
+ return transport_map[self.type]
+
+ # If no type is provided, fall back to automatic detection
if self.command:
return TransportType.STDIO
elif self.url: