# Spanlens MCP server

> Query LLM observability data, cost metrics, and agent traces directly from your IDE using Spanlens workspace data.

- Repository: https://github.com/spanlens/Spanlens
- Page: https://hostedmcp.org/servers/spanlens/mcp-server
- Transport: stdio
- Stars: 13
- License: MIT
- Latest version: 0.3.0

## Install

### Claude Code

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

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

```json
{
  "mcpServers": {
    "mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@spanlens/mcp-server"
      ],
      "env": {
        "SPANLENS_API_KEY": "<YOUR_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": "<YOUR_SPANLENS_API_KEY>"
      }
    }
  }
}
```

### VS Code CLI

```sh
code --add-mcp '{"name":"mcp-server","type":"stdio","command":"npx","args":["-y","@spanlens/mcp-server"],"env":{"SPANLENS_API_KEY":"<YOUR_SPANLENS_API_KEY>"}}'
```

### Claude Desktop (`claude_desktop_config.json`)

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

### Codex

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

### Codex config.toml (`~/.codex/config.toml`)

```toml
[mcp_servers.mcp-server]
command = "npx"
args = ["-y", "@spanlens/mcp-server"]

[mcp_servers.mcp-server.env]
SPANLENS_API_KEY = "<YOUR_SPANLENS_API_KEY>"
```

### Gemini CLI

```sh
gemini mcp add -s user -e 'SPANLENS_API_KEY=<YOUR_SPANLENS_API_KEY>' mcp-server npx -- -y @spanlens/mcp-server
```

### Gemini settings.json (`~/.gemini/settings.json`)

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

## Environment variables

| Name | Required | Secret | Description |
|---|---|---|---|
| `SPANLENS_API_KEY` | yes | yes | Spanlens 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. |
| `SPANLENS_BASE_URL` | no | no | Override the API endpoint for self-hosted Spanlens. Default: https://api.spanlens.io |

## Tools (7)

- `get_stats`
- `query_requests`
- `list_traces`
- `get_trace`
- `get_anomalies`
- `get_savings`
- `get_user_analytics`

## FAQ

### What kind of questions can I ask the agent?

You can ask about LLM spending, cost anomalies, expensive traces, model breakdowns, and recent error calls.

### Is it safe to use my API key in my IDE configuration?

Yes, because the server requires public-scope keys which are read-only and cannot trigger LLM proxy spend.

### What happens if I use a full-access API key?

The server will refuse to start to prevent security risks associated with plaintext credentials in IDE config files.
