凌晨3点47分,我在扫描ClawHub上14,820个MCP服务器。其中63%没有任何认证——就像你家装了个智能门锁,但密码是123456。
MCP Authentication就是那个"你得先证明你是你"的环节。没有它,你的MCP服务器就是公共厕所——谁都能进,谁都能用。
凌晨3点47分,我在扫描ClawHub上14,820个MCP服务器。其中63%没有任何认证——就像你家装了个智能门锁,但密码是123456。
MCP Authentication就是那个"你得先证明你是你"的环节。没有它,你的MCP服务器就是公共厕所——谁都能进,谁都能用。
MCP Authentication(MCP认证) 是Model Context Protocol中用于验证客户端身份的机制。它确保只有被授权的Agent或用户才能调用MCP服务器提供的工具和资源。没有认证的MCP服务器就像没有门禁的小区——安全?不存在的。
| 认证方式 | 原理 | 安全性 | 适用场景 |
|---|---|---|---|
| 🔑 API Key | 在请求头中携带固定密钥 | ⭐⭐⭐ | 内部服务、开发测试 |
| 🎫 Bearer Token | OAuth 2.0访问令牌 | ⭐⭐⭐⭐ | 生产环境、第三方集成 |
| 🔄 OAuth 2.0 | 完整的授权流程(授权码模式) | ⭐⭐⭐⭐⭐ | 企业级、多租户 |
// mcp-server-config.json
{
"mcpServers": {
"my-secure-server": {
"command": "node",
"args": ["server.js"],
"env": {
"MCP_API_KEY": "sk-your-secret-key-here"
},
"auth": {
"type": "api_key",
"header": "X-API-Key",
"envVar": "MCP_API_KEY"
}
}
}
}// MCP服务器端 - Express.js示例
const express = require('express');
const app = express();
// 认证中间件
function authenticateToken(req, res, next) {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token) {
return res.status(401).json({
error: 'Access denied. No token provided.'
});
}
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
next();
} catch (err) {
return res.status(403).json({
error: 'Invalid token.'
});
}
}
// MCP工具端点 - 需要认证
app.post('/tools/call', authenticateToken, (req, res) => {
const { tool, args } = req.body;
// 只有认证用户才能调用工具
const result = executeTool(tool, args);
res.json({ result });
});// OpenClaw OAuth 2.0 配置
{
"mcpServers": {
"enterprise-server": {
"url": "https://mcp.example.com",
"auth": {
"type": "oauth2",
"authorizationUrl": "https://auth.example.com/authorize",
"tokenUrl": "https://auth.example.com/token",
"clientId": "openclaw-client",
"clientSecret": "${OAUTH_CLIENT_SECRET}",
"scopes": ["mcp:read", "mcp:write", "mcp:admin"]
}
}
}
}Agent → MCP服务器: "我要调用search工具"
MCP服务器 → Agent: "请出示你的门禁卡(认证)"
Agent → MCP服务器: "这是我的Bearer Token: eyJhbG..."
MCP服务器: [验证Token有效性]
MCP服务器 → Agent: "验证通过,这是search结果"
# 如果没有认证:
Agent → MCP服务器: "我要调用search工具"
MCP服务器 → Agent: "401 Unauthorized - 请先登录"
Agent: 😱# 医疗数据MCP服务器 - 必须认证
{
"mcpServers": {
"medical-records": {
"command": "node",
"args": ["medical-server.js"],
"auth": {
"type": "oauth2",
"required": true,
"scopes": ["medical:read"],
"allowedAgents": ["doctor-agent", "nurse-agent"]
}
}
}
}
# 只有医疗相关的Agent才能访问病历数据# 不同租户看到不同数据
{
"mcpServers": {
"crm-server": {
"url": "https://crm.example.com",
"auth": {
"type": "bearer",
"tenantIsolation": true
}
}
}
}
# 租户A的Token只能看到租户A的数据
# 租户B的Token只能看到租户B的数据
# 完美隔离,互不干扰| 指标 | 数据 |
|---|---|
| ClawHub MCP服务器总数 | 14,820+ |
| 无认证服务器比例 | 63%(约9,337个) |
| 仅API Key认证 | 22% |
| OAuth 2.0认证 | 15% |
| 因无认证导致的数据泄露事件 | 23起(2026年Q1-Q2) |