diff --git a/examples/servers/simple-auth/README.md b/examples/servers/simple-auth/README.md index 1d0979d97..9906c4d36 100644 --- a/examples/servers/simple-auth/README.md +++ b/examples/servers/simple-auth/README.md @@ -44,6 +44,31 @@ 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` + + +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 +86,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