观察仪器mcp
一个MCP服务器,自动为Python AI代理插入 ioa观察sdk --添加基于OpenTetry的跟踪、指标和日志,无需手动操作。
可与任何兼容MCP的AI编码助手配合使用:Claude Desktop、Cursor、Windsurf等。
它做什么
两个工具:
instrument_agent --读取Python代理文件,应用完整的observation SDK插装,将其写回,并返回更改摘要。创建一个 .bak 修改前备份。
check_instrumentation --在不修改文件的情况下审核文件是否缺少检测。
支持的框架:LlamaIndex、LangGraph、CrewAI、原始OpenAI SDK。
安装
pip install observe-instrument-mcp
# or
uv add observe-instrument-mcp需要所选LLM提供程序的API密钥。默认为Claude(ANTHROPIC_API_KEY).看 支持的提供商 在......下面
配置
克劳德桌面版
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"observe-instrument": {
"command": "uvx",
"args": ["observe-instrument-mcp"],
"env": {
"ANTHROPIC_API_KEY": "sk-ant-..."
}
}
}
}光标
添加 .cursor/mcp.json 在您的项目中:
{
"mcpServers": {
"observe-instrument": {
"command": "uvx",
"args": ["observe-instrument-mcp"],
"env": {
"ANTHROPIC_API_KEY": "sk-ant-..."
}
}
}
}帆板运动
添加 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"observe-instrument": {
"command": "uvx",
"args": ["observe-instrument-mcp"],
"env": {
"ANTHROPIC_API_KEY": "sk-ant-..."
}
}
}
}示例
即用型未配置的代理文件包含在 examples/ 文件夹:
examples/
single-agent/
openai-sdk-example.py # OpenAI SDK customer support agent
langgraph-example.py # LangGraph currency converter
llama-index-example.py # LlamaIndex math agent
crewai-example.py # CrewAI research crew
multi-agent/
openai-sdk-multi-agent-example.py # OpenAI SDK orchestrator pipeline
langgraph-multi-agent-example.py # LangGraph supervisor pattern
llama-index-multi-agent-example.py # LlamaIndex research + writing pipeline
crewai-multi-agent-example.py # CrewAI research + publishing crews用法
配置后,询问您的AI助手:
Instrument my agent with the observe SDK: path/to/my_agent.pyCheck what observe SDK instrumentation is missing from path/to/my_agent.py环境变量
| 变量 | 描述 |
|---|---|
LLM_MODEL | 要使用的模型(默认值: claude-sonnet-4-6).请参阅下面的供应商表。 |
ANTHROPIC_API_KEY | Anthropic模型所需 |
OPENAI_API_KEY | OpenAI模型需要 |
GEMINI_API_KEY | Google Gemini型号需要 |
GROQ_API_KEY | Groq型号需要 |
支持的提供商
| 提供者 | 密钥变量 | LLM_MODEL 示例 |
|---|---|---|
| 人类学 | ANTHROPIC_API_KEY | claude-sonnet-4-6 |
| OpenAI | OPENAI_API_KEY | gpt-4o |
| 谷歌双子座 | GEMINI_API_KEY | gemini/gemini-2.0-flash |
| Groq | GROQ_API_KEY | groq/llama-3.3-70b |
| Ollama(本地,免费) | 无 | ollama/llama3.2 |
仪器安装后
在项目中安装SDK:
pip install ioa-observe-sdk
# or
uv add ioa-observe-sdk启动可观察性堆栈(OTel收集器+ClickHouse):
cd path/to/observe/deploy
docker compose up -d运行您的代理:
OPENAI_API_KEY=sk-... OTLP_HTTP_ENDPOINT=http://localhost:4318 python my_agent.py查询跟踪:
docker exec -it clickhouse-server clickhouse-client --user admin --password adminSELECT SpanName, ServiceName, Duration / 1000000. AS ms, Timestamp
FROM otel_traces
ORDER BY Timestamp DESC
LIMIT 20;发展
git clone https://github.com/alanzha2/observe-instrument-mcp
cd observe-instrument-mcp
pip install -e .
# Test the server locally
mcp dev observe_instrument_mcp/server.py许可证
阿帕奇-2.0
