spanlens
Query Spanlens LLM cost and trace data from Cursor, Claude Desktop or Continue
spanlens is an open-source MCP server for ai models and llm tooling. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, macOS, Windows
- Runs
- Locally
- Version
- 0.3.0
- Listing updated
Similar MCP servers
Install
Run in a terminal
claude mcp add mcp-server --env SPANLENS_API_KEY='<SPANLENS_API_KEY>' -- npx -y @spanlens/mcp-serverAdd to claude_desktop_config.json
{
"mcpServers": {
"mcp-server": {
"command": "npx",
"args": [
"-y",
"@spanlens/mcp-server"
],
"env": {
"SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
}
}
}
}Add to ~/.cursor/mcp.json
{
"mcpServers": {
"mcp-server": {
"command": "npx",
"args": [
"-y",
"@spanlens/mcp-server"
],
"env": {
"SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
}
}
}
}Add to .vscode/mcp.json
{
"servers": {
"mcp-server": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@spanlens/mcp-server"
],
"env": {
"SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
}
}
}
}Add to ~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"mcp-server": {
"command": "npx",
"args": [
"-y",
"@spanlens/mcp-server"
],
"env": {
"SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
}
}
}
}Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"mcp-server": {
"command": "npx",
"args": [
"-y",
"@spanlens/mcp-server"
],
"env": {
"SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
}
}
}
}Using several servers? Build one config file with the MCP config generator.
Configuration
SPANLENS_API_KEYSpanlens API key. Must be a scope=public key (sl_live_pub_*) issued from the Public Keys card at https://spanlens.io/projects — the server refuses to start with a full-access sl_live_* key.RequiredSPANLENS_BASE_URLOverride the API endpoint for self-hosted Spanlens. Default: https://api.spanlens.io
About spanlens
The README says this MCP server connects an IDE's AI agent to a Spanlens workspace so developers can ask about LLM spend, latency and errors in plain language instead of opening the dashboard. Questions such as weekly OpenAI spend, cost anomalies or the most expensive agent trace are routed to seven read-only tools.
The server runs over stdio via npx and needs a public-scope Spanlens key (sl_live_pub_*). It refuses to start with a full-access key, and the README notes that public keys cannot call the proxy or ingest endpoints. A SPANLENS_BASE_URL setting lets teams point it at a self-hosted Spanlens instance.
It suits developers and small teams already using Spanlens for LLM observability who want cost and trace checks without leaving their editor.
Tools this server provides (7)
Taken from the project documentation; the running server may differ.
- get_stats
- Aggregate cost, request count, token usage, latency and error rate, with optional groupBy.
- query_requests
- Individual LLM requests with cost, latency, model and error message, with filters.
- list_traces
- Agent trace summaries for discovering trace IDs.
- get_trace
- Full agent span tree for a trace ID.
- get_anomalies
- Detected cost, latency and error-rate anomalies.
- get_savings
- Model-swap recommendations with projected monthly savings.
- get_user_analytics
- Per-end-user usage breakdown.
What it does
- Natural-language cost queries
- Ask the IDE agent for spend, request counts, token usage and error rates over a chosen period.
- Trace and span inspection
- List agent runs and pull the full span tree for a trace ID, including timing, tokens and cost.
- Anomaly detection access
- Retrieve cost, latency and error-rate anomalies the platform has flagged, with adjustable sensitivity.
- Model-swap savings
- Review recommended model changes with projected monthly savings and adoption status.
- Per-user usage breakdown
- See cost, request count and models used for individual end users.
- Read-only public keys
- Authenticates with a scoped key that the README says cannot trigger proxy spend or write ingest data.
Good for
- Checking weekly LLM spend by model or provider from the editor
- Investigating a slow or costly agent run by walking its trace
- Reviewing recent failed calls to a specific model
- Finding which end user is driving the most LLM cost
- Looking for model swaps that could reduce spend
Pricing
Open source
MIT-licensed server; the Spanlens service it queries is a separate product.
spanlens FAQ
Which IDEs does spanlens support?
The README gives setup instructions for Cursor, Claude Desktop and Continue.
Can it send requests through Spanlens or change my data?
The README says public-scope keys are read-only and cannot call the proxy or ingest endpoints.
Can it work with a self-hosted Spanlens?
Yes. Setting SPANLENS_BASE_URL points the server at a self-hosted instance.
What license is spanlens under?
The README states the package is released under the MIT license.
Is spanlens free?
Yes. spanlens is open source, so you can use and self-host it for free.
How do I add spanlens to Claude Code?
Run this command in your terminal: claude mcp add mcp-server --env SPANLENS_API_KEY='<SPANLENS_API_KEY>' -- npx -y @spanlens/mcp-server
What are the best alternatives to spanlens?
The closest alternatives to spanlens are Mcpspend, Ai Cost Analyzer, warpmetrics, MCP-Bridge and MCP Trace.
Where this comes from
- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.
