Skip to content

Commit fdb538b

Browse files
authored
Simple Auth Example to use shttp in addition to sse (#695)
1 parent 1cb7407 commit fdb538b

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

examples/servers/simple-auth/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ uv run mcp-simple-auth
4444

4545
The server will start on `http://localhost:8000`.
4646

47+
### Transport Options
48+
49+
This server supports multiple transport protocols that can run on the same port:
50+
51+
#### SSE (Server-Sent Events) - Default
52+
```bash
53+
uv run mcp-simple-auth
54+
# or explicitly:
55+
uv run mcp-simple-auth --transport sse
56+
```
57+
58+
SSE transport provides endpoint:
59+
- `/sse`
60+
61+
#### Streamable HTTP
62+
```bash
63+
uv run mcp-simple-auth --transport streamable-http
64+
```
65+
66+
Streamable HTTP transport provides endpoint:
67+
- `/mcp`
68+
69+
70+
This ensures backward compatibility without needing multiple server instances. When using SSE transport (`--transport sse`), only the `/sse` endpoint is available.
71+
4772
## Available Tool
4873

4974
### get_user_profile
@@ -61,5 +86,6 @@ If the server fails to start, check:
6186
1. Environment variables `MCP_GITHUB_GITHUB_CLIENT_ID` and `MCP_GITHUB_GITHUB_CLIENT_SECRET` are set
6287
2. The GitHub OAuth app callback URL matches `http://localhost:8000/github/callback`
6388
3. No other service is using port 8000
89+
4. The transport specified is valid (`sse` or `streamable-http`)
6490

6591
You can use [Inspector](https://github.com/modelcontextprotocol/inspector) to test Auth

examples/servers/simple-auth/mcp_simple_auth/server.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import secrets
55
import time
6-
from typing import Any
6+
from typing import Any, Literal
77

88
import click
99
from pydantic import AnyHttpUrl
@@ -347,7 +347,13 @@ async def get_user_profile() -> dict[str, Any]:
347347
@click.command()
348348
@click.option("--port", default=8000, help="Port to listen on")
349349
@click.option("--host", default="localhost", help="Host to bind to")
350-
def main(port: int, host: str) -> int:
350+
@click.option(
351+
"--transport",
352+
default="sse",
353+
type=click.Choice(["sse", "streamable-http"]),
354+
help="Transport protocol to use ('sse' or 'streamable-http')",
355+
)
356+
def main(port: int, host: str, transport: Literal["sse", "streamable-http"]) -> int:
351357
"""Run the simple GitHub MCP server."""
352358
logging.basicConfig(level=logging.INFO)
353359

@@ -364,5 +370,6 @@ def main(port: int, host: str) -> int:
364370
return 1
365371

366372
mcp_server = create_simple_mcp_server(settings)
367-
mcp_server.run(transport="sse")
373+
logger.info(f"Starting server with {transport} transport")
374+
mcp_server.run(transport=transport)
368375
return 0

0 commit comments

Comments
 (0)