# spanlens

> spanlens is an open-source MCP server for ai models and llm tooling. Query Spanlens LLM cost and trace data from Cursor, Claude Desktop or Continue. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, macOS, Windows, Linux, API
- **Repository:** https://github.com/spanlens/spanlens/tree/HEAD/packages/mcp-server
- **MCP Registry name:** io.github.spanlens/mcp-server
- **Categories:** [AI models and LLM tooling](https://ai-powered.com/categories/ai-and-llm), [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-11-21

## About

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.

## Features

- **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

## Install

### Claude Code (Terminal)

```sh
claude mcp add mcp-server --env SPANLENS_API_KEY='<SPANLENS_API_KEY>' -- npx -y @spanlens/mcp-server
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@spanlens/mcp-server"
      ],
      "env": {
        "SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
      }
    }
  }
}
```

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@spanlens/mcp-server"
      ],
      "env": {
        "SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
      }
    }
  }
}
```

### VS Code (.vscode/mcp.json)

```json
{
  "servers": {
    "mcp-server": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@spanlens/mcp-server"
      ],
      "env": {
        "SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
      }
    }
  }
}
```

### Windsurf (~/.codeium/windsurf/mcp_config.json)

```json
{
  "mcpServers": {
    "mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@spanlens/mcp-server"
      ],
      "env": {
        "SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
      }
    }
  }
}
```

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@spanlens/mcp-server"
      ],
      "env": {
        "SPANLENS_API_KEY": "<SPANLENS_API_KEY>"
      }
    }
  }
}
```

## Tools

- `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.

## 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.

## Alternatives

- [Mcpspend](https://ai-powered.com/mcp/mcpspend): Mcpspend is a freemium MCP server for developer tools.
- [Ai Cost Analyzer](https://ai-powered.com/mcp/ai-cost-analyzer): Ai Cost Analyzer is a paid MCP server for ai models and llm tooling.
- [warpmetrics](https://ai-powered.com/mcp/warpmetrics): warpmetrics is an open-source MCP server for developer tools.
- [MCP-Bridge](https://ai-powered.com/mcp/mcp-bridge-2): MCP-Bridge is an open-source MCP server for ai models and llm tooling.
- [MCP Trace](https://ai-powered.com/mcp/mcp-trace): MCP Trace is an open-source MCP server for developer tools.
- [Tracelane MCP](https://ai-powered.com/mcp/tracelane-mcp): Tracelane MCP is a freemium MCP server for developer tools.
- [LLM Usage](https://ai-powered.com/mcp/llm-usage): LLM Usage is an open-source MCP server for ai models and llm tooling.
- [Agent Cost MCP](https://ai-powered.com/mcp/agent-cost-mcp): Agent Cost MCP is an open-source MCP server for developer tools.

---
Source: https://ai-powered.com/mcp/spanlens
