使用说明
MCP指令服务器
分享了克劳德对团队的指导。编辑 instructions.yaml,每个人都会得到更新。
快速开始
选项1:Docker(推荐)
docker compose up -d
# Server runs at http://localhost:8080/mcp
选项2:Python
# macOS / Linux
./setup.sh
python server.py
# Windows
python -m venv .venv && .venv\Scripts\activate && pip install -r requirements.txt
python server.py
选项3:云(铁路)
设置环境变量:
MCP_TRANSPORT=streamable-http
PORT=8080
选项4:Azure容器实例
./deploy.sh
要求:Azure CLI(az)并安装了Docker。
脚本创建:
- 资源组
- Azure容器注册表
- 具有公共URL的容器实例
更改后重新部署:
# Set your ACR name (check Azure portal or use: az acr list -g rg-mcp-server --query "[0].name" -o tsv)
ACR=your-acr-name
# Build, push and restart
az acr login -n $ACR
docker build -t $ACR.azurecr.io/mcp-server:latest .
docker push $ACR.azurecr.io/mcp-server:latest
az container restart -g rg-mcp-server -n mcp-server
有用的命令:
az container logs -g rg-mcp-server -n mcp-server # View logs
az container restart -g rg-mcp-server -n mcp-server # Restart
az group delete -n rg-mcp-server --yes # Delete all
选择哪个选项?
| 模式 | 最佳选择 | 成本 | 延迟 |
|---|---|---|---|
| 标准 (本地Python) | 个人使用 | 免费 | ~0ms |
| 码头工人 | 本地开发/测试 | 免费 | ~10ms |
| 铁路 | 快速部署 | 按次付费 | ~100ms+ |
| Azure ACI | 团队共享,Azure用户 | ~1-2/月 | ~100ms+ |
注: 只有当您调用提示符时,服务器才会被调用(/team-instructions:production等等)。正常的克劳德消息不会到达服务器。指令一次加载到对话上下文中。
连接克劳德代码
创建配置文件:
- 全球 (所有项目):
~/.claude/mcp.json - 每次回购 (仅此项目):
.mcp.json在repo根目录中
远程服务器(Docker/铁路/云)
{
"mcpServers": {
"team-instructions": {
"type": "streamable-http",
"url": "https://your-server-url/mcp"
}
}
}
本地Python(STDIO)
macOS/Linux:
{
"mcpServers": {
"team-instructions": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["/absolute/path/to/server.py"]
}
}
}
窗户:
{
"mcpServers": {
"team-instructions": {
"command": "C:\\path\\to\\.venv\\Scripts\\python.exe",
"args": ["C:\\path\\to\\server.py"]
}
}
}
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
MCP_TRANSPORT |
stdio |
运输: stdio, streamable-http,或 sse |
PORT |
8080 |
服务器端口(用于HTTP传输) |
MCP_PORT |
8080 |
替代端口变量 |
可用命令
提示
| 提示 | 描述 |
|---|---|
production |
严格模式,团队标准 |
freestyle |
没有规则,完全自由 |
code_review |
用标准审查代码 |
工具
| 工具 | 说明 |
|---|---|
help |
列出所有命令 |
refresh |
从文件中重新加载指令 |
资源
| 资源 | 描述 |
|---|---|
instructions://core |
核心原则 |
instructions://production |
生产指南 |
instructions://checklist |
交货清单 |
instructions://all |
所有部分合并 |
编辑说明
- 编辑
instructions.yaml - 呼叫
refresh工具(或重新启动服务器) - 完成-所有连接的客户端都会收到更新
运输
| 传输 | 用例 | 端点 |
|---|---|---|
streamable-http |
远程/云(推荐) | /mcp |
sse |
远程/云(传统) | /sse |
stdio |
本地Python执行 | 不适用 |
故障排除
| 问题 | 修复 |
|---|---|
| 找不到服务器 | 使用绝对路径,检查JSON语法 |
| Python错误 | 需要Python 3.10+,运行 pip install -r requirements.txt |
| 连接被拒绝 | 检查 MCP_TRANSPORT 和端口设置 |
| 主机标头无效 | 服务器需要 MCP_TRANSPORT=streamable-http 或 sse |
测试服务器
# Health check (SSE transport only - not available in streamable-http)
curl http://localhost:8080/health
# Test streamable-http endpoint
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
注: 这 /health 端点仅在使用SSE传输时存在。对于可流式传输的http,请使用上面的MCP端点测试。