使用说明
opsorch mcp
opsorch-mcp是OpsArch的模型上下文协议(mcp)服务器。它将OpsArch Core HTTP API公开为LLM和代理运行时的安全、只读MCP工具。
入门
本地开发
npm install
npm run dev # runs via ts-node over stdio
# or
npm run build && npm start
服务器默认使用stdio传输;从指向编译的MCP客户端(例如,Claude Code、MCP Inspector、Cursor)生成它 dist/index.js.
码头工人
每次发布时,Docker镜像都会自动构建并发布到GitHub容器注册表。您可以使用Docker运行MCP服务器:
# Pull the latest version
docker pull ghcr.io/opsorch/opsorch-mcp:latest
# Run with environment variables
docker run -d \
--name opsorch-mcp \
-p 7070:7070 \
-e OPSORCH_CORE_URL=http://localhost:8080 \
-e OPSORCH_CORE_TOKEN=changeme \
-e MCP_HTTP_PORT=7070 \
ghcr.io/opsorch/opsorch-mcp:latest
# Or run a specific version
docker pull ghcr.io/opsorch/opsorch-mcp:v1.0.0
# Using Docker Compose
cat > docker-compose.yml << EOF
version: '3.8'
services:
opsorch-mcp:
image: ghcr.io/opsorch/opsorch-mcp:latest
ports:
- "7070:7070"
environment:
- OPSORCH_CORE_URL=http://localhost:8080
- OPSORCH_CORE_TOKEN=changeme
- OPSORCH_LOG_LEVEL=info
- MCP_HTTP_PORT=7070
restart: unless-stopped
EOF
docker-compose up -d
可用的Docker标签:
latest-最新稳定版本v{version}-特定版本标签(例如。,v1.0.0,v1.1.0)
Docker镜像以非root用户身份运行,默认情况下暴露端口7070(可通过以下方式配置 MCP_HTTP_PORT 环境变量)。该映像支持MCP通信的stdio和HTTP传输。
配置访问OpsArch Core的位置:
OPSORCH_CORE_URL=http://localhost:8080 \
OPSORCH_CORE_TOKEN=changeme # Bearer token (default 'demo' if unset)
OPSORCH_CORE_TIMEOUT_MS=15000 # optional
OPSORCH_LOG_LEVEL=debug # optional (debug, info, warn, error)
MCP_HTTP_PORT=7070 # optional HTTP transport (set 0 to disable)
MCP_HTTP_ALLOW_ORIGINS=https://app.local # optional CORS allow-list (comma-separated)
MCP_HTTP_ALLOW_HOSTS=app.local # optional host header allow-list (comma-separated)
npm run dev
运输
服务器始终为MCP本机客户端绑定stdio传输。默认情况下,它还公开了一个HTTP端点 http://localhost:7070/mcp 因此,您可以运行无状态JSON-RPC调用(请参阅下面的curl示例)。集 MCP_HTTP_PORT=0 完全跳过HTTP或将其更改为另一个正整数以在其他地方监听。在为远程客户端提供服务时,配置 MCP_HTTP_ALLOW_ORIGINS (CORS)和 MCP_HTTP_ALLOW_HOSTS (主机标头允许列表),值以逗号分隔。
快速HTTP MCP检查(curl)
这里的HTTP传输无状态运行:您可以在每次调用时发出一个POST(不需要会话或初始化)。包含Accept标头:
# list tools
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
# query incidents
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"query-incidents","arguments":{"query":"error","limit":5}}}'
# query tickets
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"query-tickets","arguments":{"query":"outage","limit":5}}}'
# query deployments
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"query-deployments","arguments":{"statuses":["success"],"environments":["production"],"limit":10}}}'
# get deployment
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"get-deployment","arguments":{"id":"deploy-123"}}}'
# query teams
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"query-teams","arguments":{"name":"velocity","limit":5}}}'
# get team
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"get-team","arguments":{"id":"team-velocity"}}}'
# get team members
curl -s http://localhost:7070/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":9,"method":"tools/call","params":{"name":"get-team-members","arguments":{"id":"team-velocity"}}}'
工具(OpsArch核心)
此服务器当前公开 只读 用于查询和检索数据的工具。没有可用的突变工具。
query-incidents–POST/事件/查询get-incident–GET/事件/{id}get-incident-timeline–GET/事件/{id}/时间线query-alerts–POST/警报/查询query-logs–POST/日志/查询query-metrics–POST/指标/查询describe-metrics–POST/指标/描述query-tickets–POST/票务/查询get-ticket–获取/门票/{id}query-deployments–POST/部署/查询get-deployment–GET/部署/{id}query-services–POST/服务/查询query-teams–POST/团队/查询get-team–GET/团队/{id}get-team-members–GET/团队/{id}/成员query-orchestration-plans–POST/编排/计划/查询get-orchestration-plan–GET/编排/计划/{id}list-providers–GET/提供者/{能力}其中capability是其中之一incident,alert,log,metric,ticket,service,deployment,team,或orchestration
日志记录
OPSORCH_LOG_LEVEL控制冗长(debug,info,warn,error).- 每个OpsArch Core HTTP调用都会记录方法、路径、持续时间和状态。
debug添加请求/响应有效负载,以便您可以端到端地跟踪代理决策。
工具输入字段类型
下面有文档记录,以便代理可以快速查看字段应该是字符串、整数还是结构化有效载荷,以及适用哪些范围。
- 查询/列表限制:每
limit参数是一个可选的正整数(> 0).保持请求的行精简(数十行,而不是数百行),除非有人明确批准更广泛的获取。 - 范围:
scope.service,scope.team,以及scope.environment是可选字符串,用于缩小每个查询的范围,并且在已知时应始终设置。 - 事故查询(
query-incidents):query是一个自由文本字符串;statuses/severities是字符串数组;metadata是一个具有提供程序特定密钥的对象。 - 警报查询(
query-alerts):query是一个自由文本字符串;statuses/severities是字符串数组。 - 日志查询(
query-logs):start/end是ISO-8601时间戳;limit是最大条目数;providers是一个可选的字符串数组,因此您可以强制使用连接器。在要求批准昂贵的扫描之前,始终限制时间范围。 - 度量查询(
query-metrics):expression是提供者本机查询字符串;step是提供商接受的持续时间字符串(例如。,30s,5m).时间戳遵循ISO-8601。 - 描述指标(
describe-metrics):scope是标准查询范围。 - 服务查询(
query-services):ids是一个可选的字符串数组;tags是字符串键/值过滤器的映射。 - 团队查询(
query-teams):name是用于基于名称的过滤的可选字符串;tags是团队属性的字符串键/值过滤器的映射。 - 票务查询(
query-tickets):query是一个自由文本字符串;statuses/assignees是字符串数组。 - 部署查询(
query-deployments):query是一个自由文本字符串;statuses/environments是字符串数组;支持针对目标部署搜索的标准范围过滤。
资源
opsorch://docs/agents-architecture–服务AGENTS.md因此客户端可以直接检索OpsArch代理架构内容。
项目脚本
npm run dev–使用ts节点运行TypeScript入口点。npm run build–将编译好的JS发送到dist/.npm start–从以下位置运行编译后的服务器dist/.
填写 AGENTS.md 根据需要;所有工具都已针对Opsarch核心HTTP API表面。
发布
该项目通过GitHub Actions使用自动发布。发布是手动触发的,包括:
- 语义版本控制 具有可配置的版本凸起(主要、次要、补丁)
- 自动化测试 释放前要脱衣服
- Git标记 具有正确的版本格式(
v{major}.{minor}.{patch}) - 变更日志生成 从提交历史
- Docker镜像发布 转到GitHub容器注册表
- GitHub发布 附发行说明
创建发布
维护人员可以通过以下方式创建新版本:
- 去 操作选项卡
- 选择“发布”工作流
- 点击“运行工作流”
- 选择版本凹凸类型:
- 补丁 -Bug修复和小更新(1.0.0→1.0.1)
- 次要的 -新功能,向后兼容(1.0.0→1.1.0)
- 主要的 -重大更改(1.0.0→2.0.0)
- 点击“运行工作流”
发布过程将自动:
- 运行所有测试和linting
- 计算下一个版本号
- 创建并推送一个git标签
- 为多种架构(linux/amd64、linux/arm64)构建和发布Docker镜像
- 使用changelog创建GitHub版本
安装选项
Docker:
docker pull ghcr.io/opsorch/opsorch-mcp:latest
GitHub发布: 从下载发布工件 发布页面.