From 4a7669f9bc245ceb94892251e4a0df17ad329940 Mon Sep 17 00:00:00 2001 From: ihrpr Date: Mon, 12 May 2025 18:10:24 +0100 Subject: [PATCH 1/2] Simple Auth to use shttp in addition to sse --- examples/servers/simple-auth/README.md | 31 +++++++++++++++++++ .../simple-auth/mcp_simple_auth/server.py | 13 ++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/examples/servers/simple-auth/README.md b/examples/servers/simple-auth/README.md index 1d0979d97..0da4876c1 100644 --- a/examples/servers/simple-auth/README.md +++ b/examples/servers/simple-auth/README.md @@ -44,6 +44,36 @@ uv run mcp-simple-auth The server will start on `http://localhost:8000`. +### Transport Options + +This server supports multiple transport protocols that can run on the same port: + +#### SSE (Server-Sent Events) - Default +```bash +uv run mcp-simple-auth +# or explicitly: +uv run mcp-simple-auth --transport sse +``` + +SSE transport provides endpoint: +- `/sse` + +#### Streamable HTTP +```bash +uv run mcp-simple-auth --transport streamable-http +``` + +Streamable HTTP transport provides endpoint: +- `/mcp` + +### Compatibility Guide for Supporting Older Clients + +When using Streamable HTTP transport (`--transport streamable-http`), the server automatically supports both endpoints: +- Newer clients use `/mcp` endpoint +- Older clients use `/sse` endpoint + +This ensures backward compatibility without needing multiple server instances. When using SSE transport (`--transport sse`), only the `/sse` endpoint is available. + ## Available Tool ### get_user_profile @@ -61,5 +91,6 @@ If the server fails to start, check: 1. Environment variables `MCP_GITHUB_GITHUB_CLIENT_ID` and `MCP_GITHUB_GITHUB_CLIENT_SECRET` are set 2. The GitHub OAuth app callback URL matches `http://localhost:8000/github/callback` 3. No other service is using port 8000 +4. The transport specified is valid (`sse` or `streamable-http`) You can use [Inspector](https://github.com/modelcontextprotocol/inspector) to test Auth \ No newline at end of file diff --git a/examples/servers/simple-auth/mcp_simple_auth/server.py b/examples/servers/simple-auth/mcp_simple_auth/server.py index 2f1e4086f..51f449113 100644 --- a/examples/servers/simple-auth/mcp_simple_auth/server.py +++ b/examples/servers/simple-auth/mcp_simple_auth/server.py @@ -3,7 +3,7 @@ import logging import secrets import time -from typing import Any +from typing import Any, Literal import click from pydantic import AnyHttpUrl @@ -347,7 +347,13 @@ async def get_user_profile() -> dict[str, Any]: @click.command() @click.option("--port", default=8000, help="Port to listen on") @click.option("--host", default="localhost", help="Host to bind to") -def main(port: int, host: str) -> int: +@click.option( + "--transport", + default="sse", + type=click.Choice(["sse", "streamable-http"]), + help="Transport protocol to use ('sse' or 'streamable-http')", +) +def main(port: int, host: str, transport: Literal["sse", "streamable-http"]) -> int: """Run the simple GitHub MCP server.""" logging.basicConfig(level=logging.INFO) @@ -364,5 +370,6 @@ def main(port: int, host: str) -> int: return 1 mcp_server = create_simple_mcp_server(settings) - mcp_server.run(transport="sse") + logger.info(f"Starting server with {transport} transport") + mcp_server.run(transport=transport) return 0 From 2d5d6e906eddf21812f4662d146f41593a3e6899 Mon Sep 17 00:00:00 2001 From: ihrpr Date: Mon, 12 May 2025 18:37:11 +0100 Subject: [PATCH 2/2] docs --- examples/servers/simple-auth/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/servers/simple-auth/README.md b/examples/servers/simple-auth/README.md index 0da4876c1..9906c4d36 100644 --- a/examples/servers/simple-auth/README.md +++ b/examples/servers/simple-auth/README.md @@ -66,11 +66,6 @@ uv run mcp-simple-auth --transport streamable-http Streamable HTTP transport provides endpoint: - `/mcp` -### Compatibility Guide for Supporting Older Clients - -When using Streamable HTTP transport (`--transport streamable-http`), the server automatically supports both endpoints: -- Newer clients use `/mcp` endpoint -- Older clients use `/sse` endpoint This ensures backward compatibility without needing multiple server instances. When using SSE transport (`--transport sse`), only the `/sse` endpoint is available.