AgentHub MCP服务器运行时
MCP 服务器 通过协议展示AgentHub的功能(技能,知识库,提示) 模型上下文协议允许Claude Desktop、IDE和其他代理等外部系统消耗平台的功能。
概览
Claude Desktop / IDE / Agente externo
│ (stdio ou HTTP)
▼
agenthub-mcp-server-runtime
│
├── GET /api/skills?status=ACTIVE ───► agenthub-backend:8080
├── GET /api/knowledge-bases ─────────► agenthub-backend:8080
└── POST /api/v1/skills/invoke ───────► agenthub-skill-runtime:8082展示的能力
| MCP 类型 | AgentHub 来源 | 描述 |
|---|---|---|
| 工具 | 活跃技能 | 每个技能变成一个MCP工具 inputSchema |
| 资源 | 知识库 | URI: agenthub://kb/{id} |
| 提示 | 硬编码 | 常见操作模板 |
可用提示
pesquisar-conhecimento知识库中的语义搜索executar-skill使用JSON参数运行技能
配置
所有设置都是通过环境变量进行的:
| 变量 | 描述 | 标准 |
|---|---|---|
AGENTHUB_TENANT_ID | 这是强制性的。 UUID做租户 | -- |
AGENTHUB_BACKEND_URL | URL做代理中心后端 | http://agenthub-backend:8080 |
AGENTHUB_SKILL_RUNTIME_URL | URL做代理中心技能运行时 | http://agenthub-skill-runtime:8082 |
AGENTHUB_API_TOKEN | Bearer token 用于身份验证 | — |
STDIO_MODE 以 stdio 模式启动 true | ||
HTTP_PORT | HTTP服务器端口(0=禁用) | — |
运输方式
标准模式( 默认 - Claude Desktop)
服务器从stdin中读取JSON-RPC请求,并将响应写入stdout。 非常适合与 Claude Desktop 集成,它将服务器作为子进程启动。
// ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"agenthub": {
"command": "/caminho/para/mcp-server-runtime",
"env": {
"AGENTHUB_TENANT_ID": "seu-tenant-uuid",
"AGENTHUB_BACKEND_URL": "http://localhost:8080",
"AGENTHUB_SKILL_RUNTIME_URL": "http://localhost:8082",
"AGENTHUB_API_TOKEN": "seu-token",
"STDIO_MODE": "true"
}
}
}
}HTTP 模式( 容器化环境)
当......的时候 HTTP_PORT 设置后,服务器还会暴露HTTP端点:
# Iniciar em modo HTTP puro
AGENTHUB_TENANT_ID=uuid STDIO_MODE=false HTTP_PORT=8080 ./mcp-server-runtime
# Health check
curl http://localhost:8080/health
# Enviar requisição JSON-RPC
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'使用范例
启动握手
// Requisição
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude","version":"1.0"}}}
// Resposta
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{},"resources":{},"prompts":{}},"serverInfo":{"name":"agenthub-mcp-server-runtime","version":"1.0.0","protocolVersion":"2024-11-05"}}}Listar工具(技能)
// Requisição
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
// Resposta
{"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"document-search","description":"Busca semântica em documentos","inputSchema":{"type":"object","properties":{"query":{"type":"string"},"limit":{"type":"integer"}},"required":["query"]}}]}}调用工具(技能)
// Requisição
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"document-search","arguments":{"query":"arquitetura do AgentHub","limit":5}}}
// Resposta
{"jsonrpc":"2.0","id":3,"result":{"content":[{"type":"text","text":"{\"documents\":[...]}"}],"isError":false}}列表资源(知识库)
// Requisição
{"jsonrpc":"2.0","id":4,"method":"resources/list","params":{}}
// Resposta
{"jsonrpc":"2.0","id":4,"result":{"resources":[{"uri":"agenthub://kb/123e4567-e89b-12d3-a456-426614174000","name":"Base de Documentação","description":"Documentação técnica do AgentHub","mimeType":"application/json"}]}}构建
# Baixar dependências
make deps
# Compilar
make build
# Executar testes
make test
# Build Docker
make docker-build
# Executar Docker (definir variáveis primeiro)
TENANT_ID=uuid BACKEND_URL=http://localhost:8080 SKILL_RUNTIME_URL=http://localhost:8082 make docker-run室内 建筑
cmd/server/main.go # Entry point, config, shutdown graceful
internal/
├── mcp/
│ ├── tipos.go # Tipos JSON-RPC 2.0 e MCP (em pt-BR)
│ ├── protocolo.go # Loop de leitura/escrita stdio
│ └── servidor.go # Dispatcher central de métodos MCP
├── backend/
│ ├── tipos.go # DTOs do agenthub-backend
│ └── cliente.go # HTTP client para o backend
├── skill_runtime/
│ └── cliente.go # HTTP client para o skill-runtime
├── handler/
│ ├── ferramentas.go # tools/list + tools/call
│ ├── recursos.go # resources/list + resources/read
│ └── prompts.go # prompts/list + prompts/get
└── api/
└── http.go # Servidor HTTP Gin (transporte alternativo)支持的 MCP 方法
| 方法 | 描述 |
|---|---|
initialize | 初始握手与能力谈判 |
notifications/initialized 客户确认(无回复) | |
tools/list 列出活动技能,如MCP工具。 | |
tools/call | 通过技能运行库调用技能 |
resources/list | 列出MCP资源的知识库 |
resources/read 从知识库中读取元数据 | |
prompts/list 治愈的提示列表。 | |
prompts/get | 获取带有参数的渲染提示符 |
技术栈
- 转到1.24
- Gin v1.9.1 HTTP 服务器
- net/http --客户端HTTP准后端e技能运行时
- 通过 stdio 或 HTTP 的 JSON-RPC 2.0 MCP 协议
MIT许可证
