V.A.L MCP服务器
使用官方最小Python MCP服务器 mcp SDK。
特性
- 主控程序
tool:ping - 主控程序
tool:add(a, b) - 主控程序
resource:server://info - 主控程序
prompt:summarize(topic, audience) - 基于YAML的环境配置(
config/development.yaml,config/production.yaml)
当前实施状态
现已实施:
python main.py入口点包装器src/val_mcp_server/server.py- MCP服务器
stdio/sse运输选择 - 工具:
ping - 工具:
add(a, b) - 资源:
server://info - 提示:
summarize(topic, audience) - 配置加载和合并默认值
已计划(记录如下,尚未实施):
- REST API端点(
/health,/metrics,/agents等等) - 代理注册表内部
- 沙盒和状态管理器运行时服务
- 可观察性端点和跟踪管道
API计划终点
以下端点是目标设计,当前在此存储库中未处于活动状态。
| 端点 | 方法 | 描述 |
|---|---|---|
/health | GET | 健康检查 |
/metrics | GET | 普罗米修斯指标 |
/agents | GET | 列出代理 |
/agents/register | POST | 注册新代理 |
/agents/{id} | GET | 获取代理信息 |
/agents/{id}/unregister | POST | 注销代理 |
/messages/send | POST | 发送消息 |
/messages/batch | POST | 发送批处理消息 |
/state/{key} | GET/POST/DELETE | 状态操作 |
/sandbox/execute | POST | 在沙盒中执行 |
组件详细信息(计划设计)
1.代理人登记处
目的:系统中所有代理的中心目录。
主要特点:
- 能力索引:O(1)能力查找的倒排索引
- 状态跟踪:实时代理状态(空闲、繁忙、离线、错误)
- 健康监测:具有自动清理功能的心跳跟踪
- 负载平衡支持:路由决策的请求计数器
数据结构:
RegisteredAgent {
agent_id: UUID
config: AgentConfig
status: Enum[IDLE, BUSY, OFFLINE, ERROR]
capabilities: Set[String]
metrics: {
total_requests: int
failed_requests: int
success_rate: float
}
last_heartbeat: datetime
}沙盒执行示例
result = await server.sandbox.execute(
code="print('Hello from sandbox')",
agent_id="agent-123",
timeout=30
)
# Returns: stdout, stderr, exit_code, artifacts状态管理示例
# Set state with TTL
await server.state_manager.set(
key="session:123",
value={"user": "alice", "data": [...]},
namespace="sessions",
ttl=3600 # 1 hour
)
# Subscribe to changes
await server.state_manager.subscribe(
namespace="sessions",
key_pattern="session:*",
callback=on_session_change
)运行时检查
下面的curl检查需要计划的RESTneneneba API层,并且当前不处于活动状态。
# Server health
curl http://localhost:8000/health
# Metrics
curl http://localhost:8000/metrics
# Agent status
curl http://localhost:8000/agents调试和跟踪
Unix/macOS shell:
# Enable debug logging
PYTHONPATH=src MCP_LOG_LEVEL=DEBUG python -m val_mcp_server.server
# Enable tracing
PYTHONPATH=src MCP_ENABLE_TRACING=true python -m val_mcp_server.serverPowerShell:
# Enable debug logging
$env:PYTHONPATH = "src"; $env:MCP_LOG_LEVEL = "DEBUG"; python -m val_mcp_server.server
# Enable tracing
$env:PYTHONPATH = "src"; $env:MCP_ENABLE_TRACING = "true"; python -m val_mcp_server.server设置
pip install -r requirements.txt跑
运行开发服务器(启动MCP服务器并保持运行):
python main.py使用自定义配置运行:
python main.py --config config/production.yaml可选的模拟运行(在不启动服务器的情况下验证配置):
python main.py --dry-run
python main.py --config config/production.yaml --dry-run明确覆盖传输:
python main.py --transport stdio测试
pytest tests/ -v客户端示例
python example_usage.py示例客户端运行 main.py 在 --dry-run 验证有效配置输出的模式。
