Skip to content

Commit 7b0e378

Browse files
committed
renamed to proxy-oauth
Signed-off-by: Jesse Sanford <108698+jessesanford@users.noreply.github.com>
1 parent e072708 commit 7b0e378

File tree

11 files changed

+130
-227
lines changed

11 files changed

+130
-227
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# OAuth Proxy Server
2+
3+
This is a minimal OAuth proxy server example for the MCP Python SDK that demonstrates how to create a transparent OAuth proxy for existing OAuth providers.
4+
5+
## Installation
6+
7+
```bash
8+
# Navigate to the proxy-auth directory
9+
cd examples/servers/proxy-auth
10+
11+
# Install the package in development mode
12+
uv add -e .
13+
```
14+
15+
## Configuration
16+
17+
The servers can be configured using either:
18+
19+
1. **Command-line arguments** (take precedence when provided)
20+
2. **Environment variables** (loaded from `.env` file when present)
21+
22+
Example `.env` file:
23+
```
24+
# Auth Server Configuration
25+
AUTH_SERVER_HOST=localhost
26+
AUTH_SERVER_PORT=9000
27+
AUTH_SERVER_URL=http://localhost:9000
28+
29+
# Resource Server Configuration
30+
RESOURCE_SERVER_HOST=localhost
31+
RESOURCE_SERVER_PORT=8001
32+
RESOURCE_SERVER_URL=http://localhost:8001
33+
34+
# Combo Server Configuration
35+
COMBO_SERVER_HOST=localhost
36+
COMBO_SERVER_PORT=8000
37+
38+
# OAuth Provider Configuration
39+
UPSTREAM_AUTHORIZE=https://github.com/login/oauth/authorize
40+
UPSTREAM_TOKEN=https://github.com/login/oauth/access_token
41+
CLIENT_ID=your-client-id
42+
CLIENT_SECRET=your-client-secret
43+
DEFAULT_SCOPE=openid
44+
```
45+
46+
## Running the Servers
47+
48+
The example consists of three server components that can be run using the project scripts defined in pyproject.toml:
49+
50+
### Step 1: Start Authorization Server
51+
52+
```bash
53+
# Start Authorization Server on port 9000
54+
uv run mcp-proxy-auth-as --port=9000
55+
56+
# Or rely on environment variables from .env file
57+
uv run mcp-proxy-auth-as
58+
```
59+
60+
**What it provides:**
61+
- OAuth 2.0 flows (authorization, token exchange)
62+
- Token introspection endpoint for Resource Servers (`/introspect`)
63+
- Client registration endpoint (`/register`)
64+
65+
### Step 2: Start Resource Server (MCP Server)
66+
67+
```bash
68+
# In another terminal, start Resource Server on port 8001
69+
uv run mcp-proxy-auth-rs --port=8001 --auth-server=http://localhost:9000 --transport=streamable-http
70+
71+
# Or rely on environment variables from .env file
72+
uv run mcp-proxy-auth-rs
73+
```
74+
75+
### Step 3: Alternatively, Run Combined Server
76+
77+
For simpler testing, you can run a combined proxy server that handles both authentication and resource access:
78+
79+
```bash
80+
# Run the combined proxy server on port 8000
81+
uv run mcp-proxy-auth-combo --port=8000 --transport=streamable-http
82+
83+
# Or rely on environment variables from .env file
84+
uv run mcp-proxy-auth-combo
85+
```
86+
87+
## How It Works
88+
89+
The proxy OAuth server acts as a transparent proxy between:
90+
1. Client applications requesting OAuth tokens
91+
2. Upstream OAuth providers (like GitHub, Google, etc.)
92+
93+
This allows MCP servers to leverage existing OAuth providers without implementing their own authentication systems.
94+
95+
The server code is organized in the `proxy_auth` package for better modularity.

examples/servers/proxy-auth/proxy_auth/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__version__ = "0.1.0"
44

55
# Import key components for easier access
6+
<<<<<<< HEAD
67
from .auth_server import auth_server as auth_server
78
from .auth_server import main as auth_server_main
89
from .combo_server import combo_server as combo_server
@@ -15,6 +16,20 @@
1516
"auth_server",
1617
"resource_server",
1718
"combo_server",
19+
=======
20+
from .auth_server import main as auth_server_main
21+
from .auth_server import run_server as run_auth_server
22+
from .combo_server import main as combo_server_main
23+
from .combo_server import mcp as proxy_server
24+
from .resource_server import main as resource_server_main
25+
from .resource_server import mcp as resource_server
26+
from .token_verifier import IntrospectionTokenVerifier
27+
28+
__all__ = [
29+
"run_auth_server",
30+
"resource_server",
31+
"proxy_server",
32+
>>>>>>> 37d81fe (renamed to proxy-oauth)
1833
"IntrospectionTokenVerifier",
1934
"auth_server_main",
2035
"resource_server_main",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Main entry point for Combo Proxy OAuth Resource+Auth MCP server."""
2+
3+
import sys
4+
5+
from .combo_server import main
6+
7+
sys.exit(main()) # type: ignore[call-arg]

examples/servers/proxy_oauth/resource_server.py renamed to examples/servers/proxy-auth/proxy_auth/resource_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# pyright: reportMissingImports=false
2+
import argparse
23
import base64
34
import json
45
import logging
@@ -321,4 +322,4 @@ def main():
321322
resource_server.run(transport=args.transport)
322323

323324
if __name__ == "__main__":
324-
resource_server.run(transport="streamable-http")
325+
resource_server.run(transport="streamable-http")
File renamed without changes.

examples/servers/proxy_oauth/pyproject.toml renamed to examples/servers/proxy-auth/pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
name = "proxy_oauth"
2+
name = "proxy_auth"
33
version = "0.1.0"
44
description = "OAuth Proxy Server"
55
authors = [{ name = "Your Name" }]
@@ -14,15 +14,20 @@ dev = [
1414
"pytest>=6.0",
1515
]
1616

17+
[project.scripts]
18+
mcp-proxy-auth-rs = "proxy_auth.resource_server:main"
19+
mcp-proxy-auth-as = "proxy_auth.auth_server:main"
20+
mcp-proxy-auth-combo = "proxy_auth.combo_server:main"
21+
1722
[build-system]
1823
requires = ["hatchling"]
1924
build-backend = "hatchling.build"
2025

2126
[tool.hatch.build.targets.wheel]
22-
packages = ["proxy_oauth"]
27+
packages = ["proxy_auth"]
2328

2429
[tool.pyright]
25-
include = ["proxy_oauth"]
30+
include = ["proxy_auth"]
2631
venvPath = "."
2732
venv = ".venv"
2833

examples/servers/proxy_oauth/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/servers/proxy_oauth/auth_server.py

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)