带有OAuth 2.1的Grafana MCP服务器
安全 Grafana MCP 在AWS上使用OAuth 2.1身份验证的(模型上下文协议)服务器,使AI代理能够查询Grafana仪表板、指标、跟踪和日志。
此MCP服务器使AI代理能够与Grafana交互:
- 查询仪表板和指标
- 分析痕迹和日志
- 调查事件
- 提供智能故障排除
与合作 石墨烯堆叠样品 用于完整的代理可观测性演示。
安全功能
✅ 符合OAuth 2.1标准(RFC9728)\ ✅ 多层WAF保护\ ✅ VPC与私有子网隔离\ ✅ 在静止和传输过程中加密\ ✅ 非根容器\ ✅ Secrets Manager集成
建筑
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CloudFront │────│ WAF │────│ ALB │
│ CDN │ │ Protection │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
│
┌──────────────────────────┴────────┐
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Cognito │ │ ECS Fargate │
│ User Pool │ │ │
│ (OAuth 2.1) │ │ ┌──────────┐ │
└──────────────┘ │ │ OAuth │ │
│ │ │ Wrapper │ │
│ JWT Validation │ └────┬─────┘ │
└─────────────────────────┤ │ │
│ ▼ │
│ ┌──────────┐ │
│ │ Grafana │ │
│ │ MCP │ │
│ │ Server │ │
│ └──────────┘ │
└──────────────┘组件
- Cognito用户池:支持MFA的OAuth 2.1授权
- 云前端+WAF:具有多层保护的全球CDN
- ECS Fargate:无服务器容器托管
- OAuth包装器:JWT令牌验证和代理
- Grafana MCP服务器:用于Grafana集成的官方MCP服务器
部署
先决条件
- AWS CLI已配置
- 已安装AWS CDK:
npm install -g aws-cdk - Docker正在运行
- 带有服务帐户令牌的Grafana实例url:部署 石墨烯堆叠样品 自动生成此堆栈。
自动设置
scripts/complete-setup.sh从参数存储中检索Grafana配置(/workshop/grafana-url, /workshop/grafana-api-key)并部署所有堆栈。
手动部署
cdk deploy --all \
--context grafanaUrl=https://your-grafana-instance.com \
--context grafanaApiKey=your-service-account-token \
--context mcpTransport=http可选:使用现有VPC
cdk deploy --all \
--context existingVpcId=vpc-12345678 \
--context publicSubnetIds=subnet-123,subnet-456 \
--context privateSubnetIds=subnet-abc,subnet-def \
--context grafanaUrl=https://your-grafana-instance.com \
--context grafanaApiKey=your-service-account-token访问您的MCP服务器
获取CloudFront URL
aws cloudformation describe-stacks \
--stack-name MCP-Server \
--query 'Stacks[0].Outputs[?OutputKey==`CloudFrontDistributionUrl`].OutputValue' \
--output textOAuth发现端点
curl https://your-cloudfront-url/.well-known/oauth-protected-resource测试MCP端点
# Should return 401 without valid token
curl https://your-cloudfront-url/grafana/mcp/运行所有测试:
node test/test-mcp-server.js测试OAuth 2.1流和MCP端点安全性:
- OAuth发现端点验证
- 未经身份验证的请求被拒绝(401)
- Cognito授权端点
- 令牌端点功能
- 模拟令牌验证
- 所有路径上的MCP端点安全
清理
cdk destroy --all许可证
此库根据MIT-0许可证获得许可。请参阅LICENSE文件。
