MCP-TLS工具验证服务器
⚠️ 该项目处于早期开发阶段⚠️
一个轻量级的实用服务器,用于验证工具定义的完整性和模式正确性。此服务器旨在用作更广泛的MCP兼容工具链的一部分,但可以独立运行以测试或CI验证工具定义。
🔧 特性
- 📦 符合JSON-RPC 2.0的请求验证
- 🔐 TLS传输支持(可选mTLS强制)
- 🔍 工具模式指纹识别和校验和验证
- ⚡ 使用构建的快速HTTP API 气
- 🧪 支持Go测试的单元测试组件
📁 项目结构
.
├── .github
│ └── workflows/ # CI and release GitHub Actions
├── .gitignore
├── Dockerfile
├── README.md
├── VERSION
├── certs # Optional certs directory
├── cmd # Application entry points
│ └── server/
├── go.mod
├── go.sum
└── pkg
├── config/ # Project configurations
├── logs/ # Log output directory
├── mcp/ # Core MCP-TLS data structures
├── server/ # HTTP server, routes, and handlers
├── tls/ # TLS transport encryption support
├── util/ # JSON helpers
└── validate/ # Tool validation logic🚀 入门指南
先决条件
- 转到1.21+
- TLS证书(自签名或CA颁发)
配置
可选环境变量
| 环境变量 | 描述 | 必填 | 默认值 |
|---|---|---|---|
MCPTLS_SERVER_PORT | 服务器监听的端口 | 否 | 9090 |
MCPTLS_SERVER_ADDR | 服务器地址 | 否 | localhost:9090 |
MCPTLS_LOG_LEVEL | 日志详细程度(debug, info, warn) | 没有 | info |
构建并运行二进制文件
go build -o bin/server ./cmd/server
chmod +x ./bin/server
./bin/server使用Docker构建和运行
docker build -t mcp-tls-server .使用基本配置运行基本
docker run --name mcp-tls-server \
-p 9090:9090 \
-d \
mcp-tls-server使用运行 docker compose
docker compose up -ddocker compose downAPI终点
POST /api/tools/validate
验证单个工具定义的架构和校验和完整性。
示例
curl -X POST https://localhost:8443/api/tools/validate \
-H "Content-Type: application/json" \
-d @tool.json启用TLS的示例:
curl -X POST https://localhost:8443/api/tools/validate \
-H "Content-Type: application/json" \
--cacert certs/ca.crt \
--cert certs/client.crt \
--key certs/client.key \
-d @tool.json请求架构(tool.json)
{
"name": "example-tool",
"description": "This tool performs a sample operation.",
"arguments": {
"inputA": "value1"
},
"parameters": {
"param1": "value1",
"param2": 42,
"param3": true
},
"inputSchema": {
"type": "object",
"properties": {
"inputA": {
"type": "string"
},
"inputB": {
"type": "number"
}
},
"required": ["inputA"]
},
"outputSchema": {
"type": "object",
"properties": {
"outputA": {
"type": "boolean"
}
},
"required": ["outputA"]
},
"annotations": {
"title": "Sample Tool",
"readOnlyHint": true,
"destructiveHint": false,
"idempotentHint": true,
"openWorldHint": false
},
"secMetaData": {
"source": "trusted-registry",
"signature": "abc123signature",
"public_key_id": "key-456",
"version": "1.0.0",
"checksum": "sha256:deadbeef"
}
}🧪 测试
go test -v ./...🔐 TLS配置
默认情况下,TLS是强制性的。
支持的标志:
| 标志 | 描述 |
|---|---|
--cert | TLS证书文件的路径(PEM格式) |
--key | TLS私钥路径(PEM格式) |
--ca | 用于验证客户端的CA证书路径 |
--require-mtls | 需要客户端证书验证 |
--addr | 监听地址(默认值: :8443) |
