Skip to content

Commit 9c90e4c

Browse files
committed
Restore old example directories; fix typing.TypedDict on Python < 3.12
- Revert removal of examples/{clients,servers/simple-*,servers/sse-polling-demo} so the old examples remain alongside stories/ for now. - schema_validators: use typing_extensions.TypedDict so pydantic accepts it as a tool parameter on Python 3.10/3.11. - pyright: add explicit extraPaths for examples/servers/simple-auth — the mcp-example-stories editable install puts examples/ on sys.path, which defeats pyright's package-root auto-detection for that one example.
1 parent b03943a commit 9c90e4c

69 files changed

Lines changed: 4464 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Simple Auth Client Example
2+
3+
A demonstration of how to use the MCP Python SDK with OAuth authentication over streamable HTTP or SSE transport.
4+
5+
## Features
6+
7+
- OAuth 2.0 authentication with PKCE
8+
- Support for both StreamableHTTP and SSE transports
9+
- Interactive command-line interface
10+
11+
## Installation
12+
13+
```bash
14+
cd examples/clients/simple-auth-client
15+
uv sync --reinstall
16+
```
17+
18+
## Usage
19+
20+
### 1. Start an MCP server with OAuth support
21+
22+
The simple-auth server example provides three server configurations. See [examples/servers/simple-auth/README.md](../../servers/simple-auth/README.md) for full details.
23+
24+
#### Option A: New Architecture (Recommended)
25+
26+
Separate Authorization Server and Resource Server:
27+
28+
```bash
29+
# Terminal 1: Start Authorization Server on port 9000
30+
cd examples/servers/simple-auth
31+
uv run mcp-simple-auth-as --port=9000
32+
33+
# Terminal 2: Start Resource Server on port 8001
34+
cd examples/servers/simple-auth
35+
uv run mcp-simple-auth-rs --port=8001 --auth-server=http://localhost:9000 --transport=streamable-http
36+
```
37+
38+
#### Option B: Legacy Server (Backwards Compatibility)
39+
40+
```bash
41+
# Single server that acts as both AS and RS (port 8000)
42+
cd examples/servers/simple-auth
43+
uv run mcp-simple-auth-legacy --port=8000 --transport=streamable-http
44+
```
45+
46+
### 2. Run the client
47+
48+
```bash
49+
# Connect to Resource Server (new architecture, default port 8001)
50+
MCP_SERVER_PORT=8001 uv run mcp-simple-auth-client
51+
52+
# Connect to Legacy Server (port 8000)
53+
uv run mcp-simple-auth-client
54+
55+
# Use SSE transport
56+
MCP_SERVER_PORT=8001 MCP_TRANSPORT_TYPE=sse uv run mcp-simple-auth-client
57+
```
58+
59+
### 3. Complete OAuth flow
60+
61+
The client will open your browser for authentication. After completing OAuth, you can use commands:
62+
63+
- `list` - List available tools
64+
- `call <tool_name> [args]` - Call a tool with optional JSON arguments
65+
- `quit` - Exit
66+
67+
## Example
68+
69+
```markdown
70+
🚀 Simple MCP Auth Client
71+
Connecting to: http://localhost:8001/mcp
72+
Transport type: streamable-http
73+
74+
🔗 Attempting to connect to http://localhost:8001/mcp...
75+
📡 Opening StreamableHTTP transport connection with auth...
76+
Opening browser for authorization: http://localhost:9000/authorize?...
77+
78+
✅ Connected to MCP server at http://localhost:8001/mcp
79+
80+
mcp> list
81+
📋 Available tools:
82+
1. get_time
83+
Description: Get the current server time.
84+
85+
mcp> call get_time
86+
🔧 Tool 'get_time' result:
87+
{"current_time": "2024-01-15T10:30:00", "timezone": "UTC", ...}
88+
89+
mcp> quit
90+
```
91+
92+
## Configuration
93+
94+
| Environment Variable | Description | Default |
95+
|---------------------|-------------|---------|
96+
| `MCP_SERVER_PORT` | Port number of the MCP server | `8000` |
97+
| `MCP_TRANSPORT_TYPE` | Transport type: `streamable-http` or `sse` | `streamable-http` |
98+
| `MCP_CLIENT_METADATA_URL` | Optional URL for client metadata (CIMD) | None |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Simple OAuth client for MCP simple-auth server."""

0 commit comments

Comments
 (0)