mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 20:44:17 +02:00
Add "http" as an alias for streamable-http
This commit is contained in:
parent
9b85d492e8
commit
76e3df1bc1
7 changed files with 34 additions and 11 deletions
|
|
@ -736,11 +736,11 @@ class MCPConfigTransport(ClientTransport):
|
|||
"mcpServers": {
|
||||
"weather": {
|
||||
"url": "https://weather-api.example.com/mcp",
|
||||
"transport": "streamable-http"
|
||||
"transport": "http"
|
||||
},
|
||||
"calendar": {
|
||||
"url": "https://calendar-api.example.com/mcp",
|
||||
"transport": "streamable-http"
|
||||
"transport": "http"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ def mcp_server_url(rsa_key_pair: RSAKeyPair) -> Generator[str]:
|
|||
with run_server_in_process(
|
||||
run_mcp_server,
|
||||
public_key=rsa_key_pair.public_key,
|
||||
run_kwargs=dict(transport="streamable-http"),
|
||||
run_kwargs=dict(transport="http"),
|
||||
) as url:
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
|
|
@ -696,7 +696,7 @@ class TestFastMCPBearerAuth:
|
|||
run_mcp_server,
|
||||
public_key=rsa_key_pair.public_key,
|
||||
auth_kwargs=dict(required_scopes=["read", "write"]),
|
||||
run_kwargs=dict(transport="streamable-http"),
|
||||
run_kwargs=dict(transport="http"),
|
||||
) as url:
|
||||
mcp_server_url = f"{url}/mcp/"
|
||||
with pytest.raises(httpx.HTTPStatusError) as exc_info:
|
||||
|
|
@ -719,7 +719,7 @@ class TestFastMCPBearerAuth:
|
|||
run_mcp_server,
|
||||
public_key=rsa_key_pair.public_key,
|
||||
auth_kwargs=dict(required_scopes=["read", "write"]),
|
||||
run_kwargs=dict(transport="streamable-http"),
|
||||
run_kwargs=dict(transport="http"),
|
||||
) as url:
|
||||
mcp_server_url = f"{url}/mcp/"
|
||||
async with Client(mcp_server_url, auth=BearerAuth(token)) as client:
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ def run_server(host: str, port: int, **kwargs) -> None:
|
|||
|
||||
@pytest.fixture(scope="module")
|
||||
def streamable_http_server() -> Generator[str, None, None]:
|
||||
with run_server_in_process(run_server, transport="streamable-http") as url:
|
||||
with run_server_in_process(run_server, transport="http") as url:
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ def run_proxy_server(host: str, port: int, shttp_url: str, **kwargs) -> None:
|
|||
class TestClientHeaders:
|
||||
@pytest.fixture(scope="class")
|
||||
def shttp_server(self) -> Generator[str, None, None]:
|
||||
with run_server_in_process(run_server, transport="streamable-http") as url:
|
||||
with run_server_in_process(run_server, transport="http") as url:
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
|
|
@ -69,7 +69,7 @@ class TestClientHeaders:
|
|||
with run_server_in_process(
|
||||
run_proxy_server,
|
||||
shttp_url=shttp_server,
|
||||
transport="streamable-http",
|
||||
transport="http",
|
||||
) as url:
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
|
|
|
|||
|
|
@ -103,13 +103,23 @@ async def streamable_http_server(
|
|||
stateless_http: bool = False,
|
||||
) -> AsyncGenerator[str, None]:
|
||||
with run_server_in_process(
|
||||
run_server, stateless_http=stateless_http, transport="streamable-http"
|
||||
run_server, stateless_http=stateless_http, transport="http"
|
||||
) as url:
|
||||
async with Client(transport=StreamableHttpTransport(f"{url}/mcp/")) as client:
|
||||
assert await client.ping()
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
|
||||
async def streamable_http_server_with_streamable_http_alias() -> AsyncGenerator[
|
||||
str, None
|
||||
]:
|
||||
"""Test that the "streamable-http" transport alias works."""
|
||||
with run_server_in_process(run_server, transport="streamable-http") as url:
|
||||
async with Client(transport=StreamableHttpTransport(f"{url}/mcp/")) as client:
|
||||
assert await client.ping()
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
|
||||
async def test_ping(streamable_http_server: str):
|
||||
"""Test pinging the server."""
|
||||
async with Client(
|
||||
|
|
@ -119,6 +129,19 @@ async def test_ping(streamable_http_server: str):
|
|||
assert result is True
|
||||
|
||||
|
||||
async def test_ping_with_streamable_http_alias(
|
||||
streamable_http_server_with_streamable_http_alias: str,
|
||||
):
|
||||
"""Test pinging the server."""
|
||||
async with Client(
|
||||
transport=StreamableHttpTransport(
|
||||
streamable_http_server_with_streamable_http_alias
|
||||
)
|
||||
) as client:
|
||||
result = await client.ping()
|
||||
assert result is True
|
||||
|
||||
|
||||
async def test_http_headers(streamable_http_server: str):
|
||||
"""Test getting HTTP headers from the server."""
|
||||
async with Client(
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def run_server(host: str, port: int, **kwargs) -> None:
|
|||
|
||||
@pytest.fixture(autouse=True, scope="module")
|
||||
def shttp_server() -> Generator[str, None, None]:
|
||||
with run_server_in_process(run_server, transport="streamable-http") as url:
|
||||
with run_server_in_process(run_server, transport="http") as url:
|
||||
yield f"{url}/mcp/"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ async def test_streamable_http_app_with_custom_middleware():
|
|||
server._additional_http_routes = routes
|
||||
|
||||
# Create the app with custom middleware
|
||||
app = server.http_app(transport="streamable-http", middleware=custom_middleware)
|
||||
app = server.http_app(transport="http", middleware=custom_middleware)
|
||||
|
||||
# Create a test client
|
||||
transport = ASGITransport(app=app)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue