mcpwatch
MCP服务器的观察性SDK。无需配置即可捕获工具调用、资源读取、提示和生命周期事件。
安装
pip install mcpwatch快速开始
import os
from mcp.server import Server
from mcpwatch import instrument
server = instrument(
Server("my-server"),
api_key=os.environ["MCPWATCH_API_KEY"],
endpoint="https://api.mcpwatch.dev",
)
# Define tools as usual — they're automatically instrumented
@server.tool("get_weather")
async def get_weather(city: str) -> str:
return f"Weather in {city}: 72°F"配置
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
api_key | str | — | 必修的。 您的MCPWatch API密钥 |
endpoint | str | https://api.mcpwatch.dev | 摄入终点URL |
debug | bool | False | 启用调试日志记录 |
sample_rate | float | 1.0 | 事件采样率(0.0–1.0) |
max_batch_size | int | 50 | 每批最大事件数 |
flush_interval | float | 1.0 | 冲洗间隔(秒) |
on_quota_warning | Callable | None | 当配额接近限制时进行回调 |
例子
看 示例/ 完整工作示例的目录。
需求
- Python 3.10+
