MCP Server OAuth Toy
A simple MCP server with OAuth 2.0 authentication for testing OAuth support in mcp-cli.
README
MCP Server OAuth Toy
A simple MCP (Model Context Protocol) server with OAuth 2.0 authentication for testing the OAuth support in mcp-cli.
Features
- Full OAuth 2.0 Authorization Code flow with PKCE
- Dynamic client registration (RFC 7591)
- In-memory session storage (for testing)
- Browser-based authorization where users enter their name
- Two tools:
whoami(returns authenticated user) andecho(echoes message with user name)
Quick Start
1. Start the Server (Docker)
# Clone the repository
git clone https://github.com/bvolpato/mcp-server-oauth-toy.git
cd mcp-server-oauth-toy
# Build and run with Docker
docker build -t mcp-server-oauth-toy .
docker run -p 8000:8000 mcp-server-oauth-toy
2. Configure mcp-cli
Add to your ~/.config/mcp/mcp_servers.json:
{
"mcpServers": {
"oauth-toy": {
"url": "http://localhost:8000/mcp",
"oauth": true
}
}
}
3. Test with mcp-cli
# Install mcp-cli (requires Bun)
bun install -g @philschmid/mcp-cli
# List available tools (will trigger OAuth flow on first run)
mcp-cli -c ~/.config/mcp/mcp_servers.json oauth-toy
# Call the whoami tool
mcp-cli -c ~/.config/mcp/mcp_servers.json oauth-toy/whoami '{}'
# Call the echo tool
mcp-cli -c ~/.config/mcp/mcp_servers.json oauth-toy/echo '{"message": "Hello!"}'
OAuth Flow
When you first connect to the server:
- mcp-cli detects the server requires OAuth (401 response)
- mcp-cli discovers OAuth endpoints via
/.well-known/oauth-authorization-server - mcp-cli registers as a client via
/register(dynamic registration) - Your browser opens to the authorization page
- You enter your name and click "Authorize"
- mcp-cli receives the authorization code and exchanges it for tokens
- Subsequent requests use the stored access token
Tools
whoami
Returns the name of the authenticated user.
mcp-cli -c ~/.config/mcp/mcp_servers.json oauth-toy/whoami '{}'
# Output: You are authenticated as: Alice
echo
Echoes back the provided message with the authenticated user's name.
mcp-cli -c ~/.config/mcp/mcp_servers.json oauth-toy/echo '{"message": "Hello!"}'
# Output: Alice says: Hello!
Local Development
Using uv
# Install dependencies
uv sync
# Run the server
uv run python -m mcp_server_oauth_toy
Using Docker Compose
docker-compose up
OAuth Endpoints
| Endpoint | Description |
|---|---|
/.well-known/oauth-authorization-server |
OAuth 2.0 Authorization Server Metadata |
/register |
Dynamic Client Registration |
/authorize |
Authorization endpoint (shows login form) |
/token |
Token endpoint |
MCP Endpoints
| Endpoint | Description |
|---|---|
/mcp |
MCP over Streamable HTTP |
/health |
Health check |
Environment Variables
| Variable | Default | Description |
|---|---|---|
HOST |
0.0.0.0 |
Server host |
PORT |
8000 |
Server port |
BASE_URL |
http://localhost:8000 |
Public base URL |
REDIS_URL |
(none) | Redis URL for persistent storage (e.g., Upstash) |
KV_URL |
(none) | Alternative Redis URL (Vercel KV) |
Persistent Storage (for Serverless)
By default, the server uses in-memory storage which doesn't persist across serverless function invocations. For production use on Vercel, set up Redis:
Using Upstash (Recommended)
- Create a free Redis database at upstash.com
- Copy the
UPSTASH_REDIS_REST_URL - Add it as
REDIS_URLin your Vercel environment variables
Using Vercel KV
- Add Vercel KV to your project from the Vercel dashboard
- The
KV_URLenvironment variable is automatically set
Testing the PR
This server was created to test mcp-cli PR #18 which adds OAuth support.
To test the OAuth implementation:
- Start this server locally
- Use mcp-cli with the
oauth: trueconfiguration - Complete the browser-based authorization
- Verify the
whoamitool returns your name
Deploy to Vercel
- Click the button above or import the repo at vercel.com/new
- Select "Other" as the framework (Vercel auto-detects Python)
- Deploy!
The BASE_URL is automatically set from VERCEL_URL.
Then update your mcp_servers.json:
{
"mcpServers": {
"oauth-toy": {
"url": "https://your-deployment.vercel.app/mcp",
"oauth": true
}
}
}
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。