MCP协议中工具服务器的身份验证机制
OpenClaw在MCP服务器配置中支持多种认证方式。HTTP传输的服务器通过headers传递认证信息,敏感凭证使用环境变量(${VAR})引用,避免硬编码。
```json
{{
"mcpServers": {{
"authenticated-api": {{
"url": "https://api.example.com/mcp",
"transport": "http",
"auth": {{
"type": "oauth2",
"clientId": "${{CLIENT_ID}}",
"clientSecret": "${{CLIENT_SECRET}}",
"tokenUrl": "https://auth.example.com/token",
"scopes": ["read", "write"]
}}
}},
"api-key-service": {{
"url": "https://service.example.com/mcp",
"transport": "http",
"headers": {{
"X-API-Key": "${{API_KEY}}"
}}
}}
}}
}}
```