Spyglass AI MCP 服务器
Spyglass AI MCP服务器为大型语言模型(LLMs)提供了一个简单的接口,用于查询Spyglass AI代理。该代理会分析您的遥测数据,并提供有关应用程序性能、错误和瓶颈的智能见解。
要安装Cursor的MCP服务器,请点击下面的按钮。它应该会打开Cursor并提示您添加您的API密钥。

或者,在您的(内容/程序等)中添加以下内容: ~/.cursor/mcp.json 文件(如需创建)并替换为您的Spyglass API密钥。然后重启Cursor以应用更改。
{
"mcpServers": {
"spyglass-ai": {
"command": "uvx",
"args": ["spyglass-mcp"],
"env": {
"SPYGLASS_API_KEY": "your-key-here"
}
}
}
}请注意,您需要拥有 uv 先安装,详见相关文档 这里
可用工具
call_spyglass_agent
使用自然语言查询您的遥测数据,调用Spyglass AI代理。
参数:
query(字符串,必填):关于您应用程序遥测数据的自然语言查询
示例查询:
- “过去一小时中,哪些终端点(或服务端点)响应最慢?”
- “显示结账服务中的所有错误”
- “哪些服务的错误率最高?”
- “我的API为何会出现高延迟?”
- “我的应用在过去一天里收到了多少请求?”
返回值:
- 遥测数据的自然语言分析
配置
环境变量
| 变量 | 必需 | 默认值 | 描述 |
|---|---|---|---|
SPYGLASS_API_KEY 是的 | 不适用 | 用于与Spyglass代理进行身份验证的API密钥 | |
SPYGLASS_AGENT_ENDPOINT | 不(编号) | https://agent.spyglass-ai.com | 代理端点URL(用于本地测试) |
命令行参数
| 参数 | 必需 | 默认值 | 描述 |
|---|---|---|---|
--endpoint | 编号 | https://agent.spyglass-ai.com | Spyglass 代理终端 URL |
--transport | 编号 | stdio | 传输类型(stdio 或 http) |
--port | 不 | 8000 | 用于HTTP传输的端口 |
示例:与MCP客户端一起使用
import asyncio
from fastmcp import Client
client = Client("http://localhost:8000/mcp")
async def analyze():
async with client:
result = await client.call_tool("call_spyglass_agent", {
"query": "What are the slowest endpoints?"
})
print(result)
asyncio.run(analyze())记录(日志)
MCP 服务器将日志同时记录到标准错误输出(由 Cursor 捕获)和一个文件中,以便调试:
日志文件位置:
~/.spyglass/logs/mcp-server-YYYYMMDD.log实时查看日志:
tail -f ~/.spyglass/logs/mcp-server-$(date +%Y%m%d).log日志包括:
- 服务器启动与配置
- 传入的查询和响应
- API调用详情(为安全起见,已截断部分令牌)
- 错误消息和堆栈跟踪
发展
先决条件
- Python 3.11或更高版本
- 紫外线 包管理器
设置
- 克隆仓库并导航到项目目录:
cd spyglass-mcp- 安装依赖项:
uv sync这将创建一个虚拟环境并安装所有必需的依赖项。
- 复制示例环境文件并配置您的API密钥:
cp env.example .env
# Edit .env and add your SPYGLASS_API_KEY本地运行
以标准输入输出模式(默认)运行MCP服务器:
uv run spyglass-mcp使用自定义终端节点运行(对于测试本地代理非常有用):
uv run spyglass-mcp --endpoint http://localhost:8080以HTTP传输模式运行:
uv run spyglass-mcp --transport http --port 8000运行测试
运行所有测试:
uv run pytest运行带有详细输出的测试:
uv run pytest -v运行特定的测试文件:
uv run pytest tests/test_mcp_server.py运行带覆盖率的测试:
uv run pytest --cov=spyglass_mcp --cov-report=term-missing建筑
构建分发包:
uv build这将在(当前目录/指定位置)生成wheel包和源代码分发文件 dist/ 目录。
项目结构
spyglass-mcp/
├── .github/
│ └── workflows/
│ └── publish.yaml
├── src/
│ └── spyglass_mcp/
│ ├── __init__.py
│ └── main.py
├── tests/
│ ├── __init__.py
│ ├── conftest.py
│ └── test_mcp_server.py
├── CHANGELOG.md
├── env.example
├── LICENSE
├── pyproject.toml
├── README.md
└── uv.lock