使用说明
MCP服务器收集示例
一组示例模型上下文协议(MCP)服务器,展示了不同的身份验证模式和传输实现。
可用服务器
1.WeatherFlow(无身份验证)
位置: 天气mcp/
实时天气数据服务,提供当前状况、预报和恶劣天气警报。
特性:
- 无需身份验证(公共访问)
- 3000港SSE运输
- 端口3001上的HTTP传输
- 5天气工具
- 2资源
- 3个提示
用例:
- 开发和测试
- 公共天气仪表盘
- 教育目的
- 开放数据应用程序
2.MetricsHub(API密钥认证)
位置: 度量mcp/
分析仪表板平台,具有全面的API密钥身份验证和基于角色的访问控制。
特性:
- API密钥验证 (表头或查询参数)
- 基于角色的访问控制 (观众/分析师/管理员)
- 4000号港口的SSE运输
- 端口4001上的HTTP传输
- 7个分析工具
- 3个具有权限控制的资源
- 3个提示
认证:
Viewer: mh_viewer_demo123 (read-only)
Analyst: mh_analyst_demo456 (read+write)
Admin: mh_admin_demo789 (full access)
用例:
- 私人分析平台
- 工具
- 多租户SaaS应用程序
- 需要访问控制的系统
3.SupportDesk(基本身份验证)
位置: 支持mcp/
具有基本身份验证(用户名/密码)和基于角色的访问控制的客户支持和帮助台系统。
特性:
- 基本认证 (HTTP基本认证-RFC 7617)
- 基于角色的访问控制 (代理人/主管/管理员)
- 5000号港口的SSE运输
- 端口5001上的HTTP传输
- 10个支持工具
- 5个具有权限控制的资源
- 3个提示
凭证:
Agent: agent1 / pass123 (basic support)
Supervisor: supervisor1 / super123 (+ assignment, stats)
Admin: admin / admin123 (full access)
用例:
- 客户支持系统
- 帮助台平台
- 票务系统
- 需要用户身份验证的系统
4.银行流程(OAuth 2.0和PKCE)
位置: 银行业mcp/
具有OAuth 2.0授权码授予+PKCE和动态客户端注册(RFC 7591)的综合银行平台。
特性:
- OAuth 2.0授权码授予+PKCE (RFC 7636)
- 动态客户端注册 (RFC 7591)
- 令牌撤销 (RFC 7009)
- 基于范围的权限 (账户:读取,交易:读取,付款:写入,个人资料:读取)
- 多种客户端身份验证方法 (基本身份验证、POST主体、公共客户端)
- JWT访问令牌 带有刷新令牌
- 整合架构 -端口6001上的OAuth+MCP
- 6000号港口的SSE运输
- 端口6001上的HTTP传输(包括OAuth端点)
- 6银行工具
- 3个具有基于范围的权限的资源
- 3个提示
演示用户:
user_basic: accounts:read, profile:read
user_transactions: accounts:read, transactions:read, profile:read
user_full: All scopes (full access)
OAuth流:
1. Register client via /oauth/register
2. Get authorization code via /oauth/authorize
3. Exchange code for access token via /oauth/token
4. Use Bearer token to access banking APIs
用例:
- 银行和金融应用
- OAuth 2.0服务器实现
- 需要动态客户端注册的应用程序
- 基于范围的许可系统
- 安全的第三方API访问
快速开始
WeatherFlow(无授权)
cd weather-mcp
npm install
npm run build
# Start SSE server
npm run start
# Or start HTTP server
node dist/streamable-http.js
测试一下:
curl -X POST http://localhost:3001/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_current_weather",
"arguments": {"location": "Tokyo"}
}
}'
MetricsHub(API密钥授权)
cd metrics-mcp
npm install
npm run build
# Start SSE server
npm run start
# Or start HTTP server
npm run start:http
测试一下:
curl -X POST http://localhost:4001/mcp \
-H "Content-Type: application/json" \
-H "X-API-Key: mh_viewer_demo123" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_metrics",
"arguments": {"metricId": "revenue_mrr"}
}
}'
支持台(基本授权)
cd support-mcp
npm install
npm run build
# Start SSE server
npm run start
# Or start HTTP server
npm run start:http
测试一下:
curl -u agent1:pass123 -X POST http://localhost:5001/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_tickets",
"arguments": {}
}
}'
银行流程(OAuth 2.0)
cd banking-mcp
npm install
npm run build
# Start HTTP server (includes OAuth endpoints)
npm run start:http
# Or start SSE server
npm run start
测试OAuth流程:
# 1. Register a client
curl -X POST http://localhost:6001/oauth/register \
-H "Content-Type: application/json" \
-d '{
"client_name": "Test App",
"redirect_uris": ["http://localhost:8080/callback"]
}'
# 2. Get authorization (open in browser, select user_full)
# http://localhost:6001/oauth/authorize?client_id=CLIENT_ID&redirect_uri=http://localhost:8080/callback&response_type=code&scope=accounts:read&state=test&code_challenge=CHALLENGE&code_challenge_method=S256
# 3. Exchange code for token
curl -X POST http://localhost:6001/oauth/token \
-u "CLIENT_ID:CLIENT_SECRET" \
-d "grant_type=authorization_code&code=CODE&redirect_uri=http://localhost:8080/callback&code_verifier=VERIFIER"
# 4. Use the access token
curl -X POST http://localhost:6001/mcp \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_accounts",
"arguments": {}
}
}'
服务器比较
| 功能 | WeatherFlow | MetricsHub | SupportDesk | BankingFlow |
|---|---|---|---|---|
| 认证 | 无 | API密钥 | 基本身份验证 | OAuth 2.0+PKCE |
| 授权 | N/A | RBAC(3层) | RBAC(三层) | 基于范围 |
| SSE港口 | 3000 | 4000 | 5000 | 6000 |
| http端口 | 3001 | 4001 | 5001 | 6001(+OAuth) |
| 工具 | 5 | 7 | 10 | 6 |
| 资源 | 2 | 3 | 5 | 3 |
| 提示 | 3 | 3 | 3 | 3 |
| 访问控制 | 公共 | RBAC | RBAC | 基于作用域 |
| 令牌类型 | N/A | 静态 | N/A | JWT(访问+刷新) |
| 动态注册 | N/A | N/A | N/A | ✅ RFC 7591 |
| 错误代码 | 500 | 401, 403, 500 | 401, 403, 500 | 400, 401, 403, 500 |
| 用例 | 公共API | 分析/BI | 支持/帮助台 | 银行/金融 |
运输支持
所有服务器支持:
- SSE(服务器发送事件) -与实时更新的持续连接
- HTTP(流式HTTP) -标准请求/响应
- 工作室 -用于本地CLI测试
演示身份验证模式
WeatherFlow-无身份验证
- 开放公众访问
- 无需凭据
- 无权限检查
- 公共数据和开发的理想选择
MetricsHub-API密钥验证
- 所有操作所需的API密钥
- 支持两个标头(
X-API-Key)和查询参数(?apiKey=)auth - 三层基于角色的访问控制(查看器/分析师/管理员)
- 工具和资源级别的权限检查
- 详细的错误响应(401 vs 403)
SupportDesk-基本身份验证
- HTTP基本身份验证(用户名:密码)
- 符合RFC 7617
- 三层基于角色的访问控制(代理/主管/管理员)
- 授权标头:
Authorization: Basic base64(username:password) - 401响应中的WWW-Authenticate标头
- 用户身份跟踪
BankingFlow-使用PKCE的OAuth 2.0
- 使用PKCE授予OAuth 2.0授权码(RFC 7636)
- 动态客户端注册(RFC 7591)
- 令牌撤销(RFC 7009)
- 带有刷新令牌的JWT访问令牌
- 基于范围的权限(帐户:读取,交易:读取,付款:写入,配置文件:读取)
- 多种客户端身份验证方法(基本身份验证、POST主体、公共客户端)
- 类似OIDC的发现端点(
.well-known/oauth-protected-resource) - 授权标头:
Authorization: Bearer <jwt_token> - 在单端口上整合OAuth+MCP服务器
测试
每台服务器都包含全面的测试脚本:
天气流量
cd weather-mcp
# Manual curl tests documented in README
MetricsHub
cd metrics-mcp
# Test different roles
./test-viewer.sh # Read-only access
./test-analyst.sh # Read+write access
./test-admin.sh # Full access
./test-unauthorized.sh # Auth failure scenarios
支持台
cd support-mcp
# Test different roles
./test-agent.sh # Basic support access
./test-supervisor.sh # + assignment, stats
./test-admin.sh # Full access
./test-unauthorized.sh # Auth failure scenarios
银行业务流程
cd banking-mcp
# Test OAuth 2.0 flow
# 1. Discovery
curl http://localhost:6001/.well-known/oauth-protected-resource | jq .
# 2. Register client
curl -X POST http://localhost:6001/oauth/register \
-H "Content-Type: application/json" \
-d '{"client_name":"Test","redirect_uris":["http://localhost:8080/callback"]}'
# 3. Full OAuth flow with PKCE (see README for complete examples)
# - Generate PKCE challenge
# - Authorization request (browser)
# - Token exchange
# - API calls with Bearer token
建筑
所有服务器都遵循一致的架构:
server-name/
├── src/
│ ├── index.ts # SSE server
│ ├── streamable-http.ts # HTTP server
│ ├── data.ts # Mock data layer
│ ├── auth.ts # Auth layer (MetricsHub, SupportDesk)
│ └── types.ts # TypeScript types (MetricsHub, SupportDesk)
├── dist/ # Compiled JavaScript
├── test-*.sh # Test scripts (MetricsHub, SupportDesk)
├── package.json
├── tsconfig.json
├── README.md
└── TESTING.md
已完成的服务器
✅ 天气流量 -无身份验证(公共访问) ✅ MetricsHub -基于RBAC的API密钥认证 ✅ 支持台 -基于RBAC的基本身份验证 ✅ 银行业务流程 -OAuth 2.0+PKCE与动态客户端注册