feat: add --mcp-type option for remote MCP servers

Auto-detects connection type from URL (/sse -> sse, /mcp -> streamable_http)
or allows manual specification. Updates goose plugin to use actual MCP type
instead of hardcoded sse.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-12 18:59:52 -06:00
parent 672b8a8e31
commit d41faf6b30
5 changed files with 28 additions and 4 deletions

View File

@@ -1573,6 +1573,11 @@ def add_mcp(
def add_remote_mcp( def add_remote_mcp(
name: str = typer.Argument(..., help="MCP server name"), name: str = typer.Argument(..., help="MCP server name"),
url: str = typer.Argument(..., help="URL of the remote MCP server"), url: str = typer.Argument(..., help="URL of the remote MCP server"),
mcp_type: str = typer.Option(
"auto",
"--mcp-type",
help="MCP connection type: sse, streamable_http, stdio, or auto (default: auto)",
),
header: List[str] = typer.Option( header: List[str] = typer.Option(
[], "--header", "-H", help="HTTP headers (format: KEY=VALUE)" [], "--header", "-H", help="HTTP headers (format: KEY=VALUE)"
), ),
@@ -1581,6 +1586,22 @@ def add_remote_mcp(
), ),
) -> None: ) -> None:
"""Add a remote MCP server""" """Add a remote MCP server"""
if mcp_type == "auto":
if url.endswith("/sse"):
mcp_type = "sse"
elif url.endswith("/mcp"):
mcp_type = "streamable_http"
else:
console.print(
f"[red]Cannot auto-detect MCP type from URL '{url}'. Please specify --mcp-type (sse, streamable_http, or stdio)[/red]"
)
return
elif mcp_type not in ["sse", "streamable_http", "stdio"]:
console.print(
f"[red]Invalid MCP type '{mcp_type}'. Must be: sse, streamable_http, stdio, or auto[/red]"
)
return
# Parse headers # Parse headers
headers = {} headers = {}
for h in header: for h in header:
@@ -1595,7 +1616,7 @@ def add_remote_mcp(
try: try:
with console.status(f"Adding remote MCP server '{name}'..."): with console.status(f"Adding remote MCP server '{name}'..."):
mcp_manager.add_remote_mcp( mcp_manager.add_remote_mcp(
name, url, headers, add_as_default=not no_default name, url, headers, mcp_type=mcp_type, add_as_default=not no_default
) )
console.print(f"[green]Added remote MCP server '{name}'[/green]") console.print(f"[green]Added remote MCP server '{name}'[/green]")

View File

@@ -443,7 +443,7 @@ class ContainerManager:
) )
# Set type-specific information # Set type-specific information
env_vars[f"MCP_{idx}_TYPE"] = "remote" env_vars[f"MCP_{idx}_TYPE"] = mcp_config.get("mcp_type", "sse")
env_vars[f"MCP_{idx}_NAME"] = mcp_name env_vars[f"MCP_{idx}_NAME"] = mcp_name
# Set environment variables for MCP count if we have any # Set environment variables for MCP count if we have any

View File

@@ -171,7 +171,7 @@ class GoosePlugin(ToolPlugin):
"enabled": True, "enabled": True,
"name": server_name, "name": server_name,
"timeout": 60, "timeout": 60,
"type": "sse", "type": server.get("type", "sse"),
"uri": mcp_url, "uri": mcp_url,
"envs": {}, "envs": {},
} }
@@ -184,7 +184,7 @@ class GoosePlugin(ToolPlugin):
"enabled": True, "enabled": True,
"name": server_name, "name": server_name,
"timeout": 60, "timeout": 60,
"type": "sse", "type": server.get("type", "sse"),
"uri": server_url, "uri": server_url,
"envs": {}, "envs": {},
} }

View File

@@ -79,6 +79,7 @@ class MCPManager:
name: str, name: str,
url: str, url: str,
headers: Dict[str, str] = None, headers: Dict[str, str] = None,
mcp_type: Optional[str] = None,
add_as_default: bool = True, add_as_default: bool = True,
) -> Dict[str, Any]: ) -> Dict[str, Any]:
"""Add a remote MCP server. """Add a remote MCP server.
@@ -97,6 +98,7 @@ class MCPManager:
name=name, name=name,
url=url, url=url,
headers=headers or {}, headers=headers or {},
mcp_type=mcp_type,
) )
# Add to the configuration # Add to the configuration

View File

@@ -61,6 +61,7 @@ class RemoteMCP(BaseModel):
type: str = "remote" type: str = "remote"
url: str url: str
headers: Dict[str, str] = Field(default_factory=dict) headers: Dict[str, str] = Field(default_factory=dict)
mcp_type: Optional[str] = None
class DockerMCP(BaseModel): class DockerMCP(BaseModel):