fix: Add streamable MCP server support (#468)

* fix: Add streamable MCP server support(#349)

* “Revert-timeout”

* fix lint and test check

* modify streamable error notify

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
suntp
2025-07-29 14:04:04 +08:00
committed by GitHub
parent bedf7d4af2
commit e178483971
6 changed files with 27 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ from fastapi import HTTPException
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from mcp.client.sse import sse_client
from mcp.client.streamable_http import streamablehttp_client
logger = logging.getLogger(__name__)
@@ -29,7 +30,7 @@ async def _get_tools_from_client_session(
Raises:
Exception: If there's an error during the process
"""
async with client_context_manager as (read, write):
async with client_context_manager as (read, write, _):
async with ClientSession(
read, write, read_timeout_seconds=timedelta(seconds=timeout_seconds)
) as session:
@@ -92,6 +93,16 @@ async def load_mcp_tools(
sse_client(url=url), timeout_seconds
)
elif server_type == "streamable_http":
if not url:
raise HTTPException(
status_code=400, detail="URL is required for streamable_http type"
)
return await _get_tools_from_client_session(
streamablehttp_client(url=url), timeout_seconds
)
else:
raise HTTPException(
status_code=400, detail=f"Unsupported server type: {server_type}"