> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magpiedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Magpie is a trace store for AI agents, used as a library (crate `magpiedb`, npm `magpiedb`, PyPI `magpiedb`) or as `magpie-server`, which takes OpenTelemetry (OTLP over HTTP on 127.0.0.1:4318 and gRPC on 127.0.0.1:4317 by default).
> Use only the commands, flags, routes and JSON shapes that these pages show. Do not guess a flag or a query field: if a page does not show it, say that the docs do not show it.
> Install the library with `cargo add magpiedb`, `npm install magpiedb` or `pip install magpiedb`. Get the server from the GitHub Releases download or the Docker image `ghcr.io/intojhanurag/magpie-server`, as the quick start shows.
> Only one process may write to a store folder at a time. For many apps, send traces to one `magpie-server`.
> `magpie-server doctor` checks a running server. An AI agent can query the traces over MCP at `/mcp` on the HTTP port (page guides/mcp).

# Query traces from an AI agent (MCP)

> Connect Claude Code, Cursor or Codex to magpie-server over MCP. The agent gets six read-only tools: find traces, search spans, read a trace or a span, sessions and sums.

`magpie-server` serves an MCP server at `POST /mcp` on its HTTP port. An AI agent connects to it and searches and reads your traces with six read-only tools. It is on by default and uses the same API keys and tenants as the [query API](https://docs.magpiedb.com/queries/overview.md).

## Connect your agent

> [tab] Claude Code
>
> ```sh theme={null}
> claude mcp add --transport http magpie http://127.0.0.1:4318/mcp
> ```
>
> With API keys, add a key that has the `read` right:
>
> ```sh theme={null}
> claude mcp add --transport http magpie http://127.0.0.1:4318/mcp --header "Authorization: Bearer $MAGPIE_KEY"
> ```

> [tab] Cursor
>
> In `.cursor/mcp.json` of the project, or `~/.cursor/mcp.json`:
>
> ```json theme={null}
> {"mcpServers": {"magpie": {"url": "http://127.0.0.1:4318/mcp", "headers": {"Authorization": "Bearer ${env:MAGPIE_KEY}"}}}}
> ```

> [tab] Codex
>
> In `~/.codex/config.toml`:
>
> ```toml theme={null}
> [mcp_servers.magpie]
> url = "http://127.0.0.1:4318/mcp"
> bearer_token_env_var = "MAGPIE_KEY"
> ```

With TLS, use `https://`. With tenants and `--auth trusted-header`, the client also sends the header `x-magpie-tenant`.

Then ask the agent a question, for example: "Find the runs of the last hour with a failed tool call, and tell me why the tool failed."

## The tools

| Tool | What it does | Same as |
| - | - | - |
| `find_traces` | Finds runs by their spans, root or scores. Gives totals and previews. With no arguments: the newest runs. | `POST /v1/traces/find` |
| `search_spans` | Finds spans by text (`words`, `phrase`, `contains`, `prefix`) and filters. | `POST /v1/search` |
| `get_trace` | One run: its spans in start order, the first characters of each text, and its scores. | `GET /v1/traces/:id/spans` |
| `get_span` | One span, with its full texts read in parts (`textChars`, `textOffset`). | `GET /v1/traces/:id/spans/:spanId` |
| `find_sessions` | Sessions of a user or a time range. | `POST /v1/sessions/find` |
| `aggregate` | Sums: tokens, cost, counts, percentiles, by a field. | `POST /v1/aggregate` |

The arguments are the bodies of the query routes. An unknown field is refused. Tokens and cost per model: `aggregate` with `{"groupBy": {"field": "model"}, "metrics": ["inputTokens", "outputTokens", "costNanos"]}`.

## Limits

The limits keep each answer small enough for an agent's context.

| | Default | At most |
| - | - | - |
| Rows (`find_traces`, `find_sessions`) | 20 | 50 |
| Spans (`search_spans`) | 20 | 100 |
| Spans of `get_trace` | 25 | 50 |
| Groups of `aggregate` | 50 | 200 |
| Preview characters (`previewChars`) | 200 | 1,000 |
| Text characters of `get_trace` | 500 | 5,000 |
| Text characters of `get_span` | 10,000 | 40,000 |
| One answer | | 40,000 characters of JSON |

When an answer would be longer, long texts are cut and end with `…[cut: N more characters]`. The field `cut` says what to ask for to get less. Ids and cursors are never cut, and every row comes.

A bad argument, a value over a limit, or a trace that is not there gives a tool error that says why. The agent can then ask again.

> [accordion] Keys, tenants and safety
>
> * With `--auth keys`, `/mcp` needs a key with the `read` right: `401` with no key or an unknown key, `403` for a key with only `write`.
> * With tenants, the tools read the key's tenant.
> * Nothing the tools do writes. `/mcp` gives a key only what the query API on the same port gives it.
> * A request from a web page of another site is refused (`403`). Clients in a browser page are not supported. Use a client that is a program.
> * To turn MCP off, start the server with `--no-mcp`.

> [accordion] Protocol
>
> * Streamable HTTP with no session. Each POST is one JSON-RPC message and gets one JSON answer.
> * Both protocol eras on one endpoint: 2025 clients (`initialize`; 2025-03-26, 2025-06-18, 2025-11-25) and 2026-07-28 clients.
> * A request body is at most 1 MiB. A batch (a JSON array) is refused with `400`.
> * OAuth is not built: the clients above send a fixed key in a header.

> [card] [Check the server](https://docs.magpiedb.com/reference/doctor-setup.md)
>
> `magpie-server doctor` checks that the server answers, takes your key and finds a test span.

> [card] [Query API](https://docs.magpiedb.com/queries/overview.md)
>
> The routes behind the tools, with every field.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.