Spanlens

io.github.spanlens由 GitHub 账号 spanlens 发布v0.3.0更新于 Oct 27, 2026

Query Spanlens LLM observability from Cursor, Claude Desktop, or Continue via MCP.

概览

AI 生成的概览

Spanlens MCP 服务器让助手查询你的 Spanlens LLM 可观测性工作区,获取花费、请求、追踪、异常与节省建议。

可以做什么
  • 获取总花费、请求数、token 用量、延迟与错误率,可按模型或供应商分组
  • 按模型、供应商、状态、用户、时间范围和条数筛选单条 LLM 请求
  • 列出智能体追踪摘要,并获取单条追踪的完整 span 树
  • 查询平台检测到的花费、延迟与错误率异常,可调整观察窗口与灵敏度
  • 获取模型替换的节省建议,以及按终端用户的使用明细
适用场景
适合已将 LLM 使用数据接入 Spanlens,并希望在 Cursor、Claude Desktop 或 Continue 中直接询问花费、延迟、错误、追踪或成本异常,而不必打开仪表盘的用户。
运行要求
通过 npx 从 npm 包以 stdio 在本地运行,需要 Node.js。需要在 SPANLENS_API_KEY 中提供 Spanlens 公共作用域 API 密钥,缺少密钥或使用完全访问密钥时服务器会拒绝启动。需要访问 Spanlens API 的网络;SPANLENS_BASE_URL 可指向自建实例,SPANLENS_TIMEOUT_MS 设置每次调用超时。
安装前请注意
API 密钥以明文保存在 IDE 配置文件中,可能因 dotfile 同步、屏幕共享或误提交而泄露;服务器只接受只读的公共作用域密钥,泄露后也无法产生代理花费。服务器会读取工作区中的用量与追踪数据(含终端用户用量),并发送到所配置的 API 端点。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Spanlens,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

@spanlens/mcp-server

Query your LLM observability data from inside Cursor, Continue, or Claude Desktop. Powered by Spanlens.

Ask your IDE's agent things like "what's my OpenAI spend this week?", "any cost anomalies?", or "show me the most expensive trace today" — and get real answers from your Spanlens workspace through the Model Context Protocol.

30-second setup

1. Issue a public-scope Spanlens key

Public-scope keys (sl_live_pub_*) are read-only — they can query your dashboard data but cannot trigger LLM proxy spend. This server refuses to start with a full-access key because the credential will live in a plaintext config file in your IDE.

Create one at spanlens.io/projects → the Public Keys card at the top → + New public key. Copy the sl_live_pub_… value when it's shown.

2. Add the server to your IDE

Cursor — ~/.cursor/mcp.json (or workspace .cursor/mcp.json)
json
{  "mcpServers": {    "spanlens": {      "command": "npx",      "args": ["-y", "@spanlens/mcp-server"],      "env": { "SPANLENS_API_KEY": "sl_live_pub_..." }    }  }}
Claude Desktop — ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
json
{  "mcpServers": {    "spanlens": {      "command": "npx",      "args": ["-y", "@spanlens/mcp-server"],      "env": { "SPANLENS_API_KEY": "sl_live_pub_..." }    }  }}
Continue — ~/.continue/config.yaml
yaml
mcpServers:  - name: spanlens    command: npx    args: ['-y', '@spanlens/mcp-server']    env:      SPANLENS_API_KEY: sl_live_pub_...

3. Reload your IDE and start asking

The agent will discover seven tools and use them automatically when relevant.

What you can ask

QuestionTool called
"How much have we spent on LLMs this week?"get_stats
"Break down cost by model for the last 30 days"get_stats(groupBy=model)
"Which provider is costing us the most this week?"get_stats(groupBy=provider)
"Any cost or latency anomalies?"get_anomalies
"Show me the 10 most recent error calls on gpt-4o"query_requests
"List my recent agent runs"list_traces
"Walk me through trace abc123…"get_trace
"What models could we swap to save money?"get_savings
"Which end-user is driving the most spend?"get_user_analytics

Available tools

ToolWhat it returns
get_statsAggregate cost, request count, token usage, latency, error rate. Optional groupBy for a breakdown of cost, requests, latency and error rate: model returns one row per provider and model pair, and provider rolls those rows up into one row per provider, with latency and error rate weighted by request count.
query_requestsIndividual LLM requests with cost, latency, model, error message. Filter by model, provider, status, userId, since, limit.
list_tracesAgent trace summaries (name, status, duration, span count, total tokens, total cost) for discovering trace IDs. Filter by limit, status, since, query. Pair with get_trace for the full span tree.
get_traceFull agent span tree for a trace ID — every LLM/tool/retrieval span with timing, tokens, cost.
get_anomaliesCost / latency / error-rate anomalies the platform has detected. Optional since (observation window) and sigma (sensitivity).
get_savingsModel-swap recommendations with projected monthly savings and adoption status.
get_user_analyticsPer-end-user usage breakdown — total cost, request count, models touched, recent calls.

Safety

This server is designed for the IDE-config use case, where the credential sits in a plaintext file that's easy to leak (dotfile sync, screen shares, accidental commits). Two defenses:

  1. Public-scope keys only. The server boots, calls /api/v1/me/key-info against your workspace, and verifies the key has scope=public. If you accidentally paste a full-access sl_live_* key, the server refuses to start with a clear error pointing at the correct key type.
  2. Read-only at the API layer. Even if a public key leaks, it cannot call /proxy/* or /ingest/* — the Spanlens server enforces this with a 403 + PUBLIC_KEY_WRITE_FORBIDDEN code. The blast radius of a leak is "competitor sees my usage stats", not "competitor runs up my OpenAI bill".

Configuration

Environment variableDefaultNotes
SPANLENS_API_KEYrequiredA sl_live_pub_* key from the Public Keys card on /projects. The server refuses to start without one, and refuses to start with a sl_live_* (full) key.
SPANLENS_BASE_URLhttps://api.spanlens.ioOverride for self-hosted Spanlens. Trailing slashes are normalised.
SPANLENS_TIMEOUT_MS30000How long each API call may take, in milliseconds, before it fails with a timeout error. Applies to the startup key check and to every tool call. Accepts a whole number from 1 to 600000. Any other value stops the server at startup with an error that names the variable.

Self-hosted Spanlens

json
{  "mcpServers": {    "spanlens": {      "command": "npx",      "args": ["-y", "@spanlens/mcp-server"],      "env": {        "SPANLENS_API_KEY": "sl_live_pub_...",        "SPANLENS_BASE_URL": "https://spanlens.your-company.com"      }    }  }}

Links

License

MIT — see LICENSE in the repo root.

来源:packages/mcp-server/README.md,提交 e825a7e

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.3.0最新Sep 28, 2026
  2. v0.2.1Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分