Simple Auth Example to use shttp in addition to sse (#695)
This commit is contained in:
parent
1cb740745d
commit
fdb538bc28
2 changed files with 36 additions and 3 deletions
|
|
@ -44,6 +44,31 @@ uv run mcp-simple-auth
|
||||||
|
|
||||||
The server will start on `http://localhost:8000`.
|
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
|
## Available Tool
|
||||||
|
|
||||||
### get_user_profile
|
### 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
|
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`
|
2. The GitHub OAuth app callback URL matches `http://localhost:8000/github/callback`
|
||||||
3. No other service is using port 8000
|
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
|
You can use [Inspector](https://github.com/modelcontextprotocol/inspector) to test Auth
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
import logging
|
import logging
|
||||||
import secrets
|
import secrets
|
||||||
import time
|
import time
|
||||||
from typing import Any
|
from typing import Any, Literal
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from pydantic import AnyHttpUrl
|
from pydantic import AnyHttpUrl
|
||||||
|
|
@ -347,7 +347,13 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--port", default=8000, help="Port to listen on")
|
@click.option("--port", default=8000, help="Port to listen on")
|
||||||
@click.option("--host", default="localhost", help="Host to bind to")
|
@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."""
|
"""Run the simple GitHub MCP server."""
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
@ -364,5 +370,6 @@ def main(port: int, host: str) -> int:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
mcp_server = create_simple_mcp_server(settings)
|
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
|
return 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue