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

# doctor and setup

> magpie-server doctor checks a running server with five checks and prints a fix for each failure. magpie-server setup prints the tracing setup for a project. Both have --json for agents.

Two commands for a person or a coding agent. Both print short lines, or one JSON object with `--json`, on stdout. Each has its own `--help`.

## `magpie-server doctor`

Checks a running server. It changes nothing but one test span.

```sh theme={null}
magpie-server doctor                                    # the server at http://127.0.0.1:4318
MAGPIE_KEY=mgp_... magpie-server doctor --url https://magpie-host:4318 --ca ca.pem --json
```

```text theme={null}
magpie-server doctor 0.1.0: http://127.0.0.1:4318
PASS  server   it answers, and its store does not refuse writes (GET /healthz: ok)
PASS  auth     the server takes requests with no API key
PASS  version  0.1.0, the same as this doctor (store format 14, GenAI mapping v2)
PASS  send     1 test span taken over OTLP/HTTP (protobuf): trace b564193805658d50496957d2c43bc3f0
PASS  query    the test span is found by its word, 0.6 s after it was sent
All 5 checks passed.
The test span stays in the store (trace b564193805658d50496957d2c43bc3f0, service magpie-doctor). To delete it:
  curl -sS --noproxy '*' 'http://127.0.0.1:4318/v1/traces/delete' -H 'content-type: application/json' -d '{"traceIds":["b564193805658d50496957d2c43bc3f0"]}'
```

### The checks

| Check | Passes when |
| - | - |
| `server` | `GET /healthz` answers `ok`: the server answers, and its store does not refuse writes. |
| `auth` | The server needs no API key, or it takes the key given. |
| `version` | `GET /v1/version` names the same version as the doctor. |
| `send` | The server takes one test span over OTLP/HTTP with protobuf. |
| `query` | `POST /v1/search` finds the test span within `--wait`. |

A failed check has a `fix` line that says what to do. A check that cannot run after a failed one is `skip`.

### Flags and variables

| Flag or variable | Default | What it does |
| - | - | - |
| `--url <address>` | `http://127.0.0.1:4318` | The server's HTTP address. Also takes the value of `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. Give the HTTP port, not the gRPC port. |
| `MAGPIE_KEY` or `--key-file <file>` | none | The API key. There is no `--key`: a key on the command line is seen in `ps`. |
| `MAGPIE_READ_KEY` or `--read-key-file <file>` | none | A key with `read`, when `MAGPIE_KEY` has only `write`. |
| `--tenant <id>` | none | Sends `x-magpie-tenant`, for `--auth trusted-header`. With API keys, leave it out: the tenant comes from the key. |
| `--ca <pem>` | the system's roots | For TLS with a private CA. |
| `--wait <time>` | `10s` | How long `query` looks for the test span. |
| `--json` | off | One JSON object (below). |

| Exit code | Meaning |
| - | - |
| `0` | Every check passed. |
| `1` | A check failed. |
| `2` | Wrong flags, or a `--ca` file that cannot be read. |

> [accordion] The JSON output
>
> `{"ok", "url", "doctorVersion", "server", "checks", "testSpan"}`:
>
> * `server`: the answer of `GET /v1/version`, or `null`.
> * `checks`: always the five checks in order, each `{"name", "status", "message", "fix"}`. `status` is `pass`, `fail` or `skip`; `fix` is `null` unless the check failed.
> * `testSpan`: `{"traceId", "spanId", "word", "service", "delete": {"method", "path", "body", "curl"}}` once the server took the span, else `null`.

> [accordion] Where the key and the test span go
>
> * The key and the test span go only to `magpie-server`. When `GET /v1/version` is missing or does not answer as `magpie-server` does, `send` and `query` are `skip`.
> * The test span is one span of a new trace, service `magpie-doctor`. The output gives the command that deletes it.
> * The output never shows a key.
> * A server on this machine (`localhost`, `127.0.0.0/8`, `::1`) gets the requests with no proxy. For another host the doctor uses `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` and `NO_PROXY`.

## `magpie-server setup`

Finds the language and the agent framework of a project, and prints its tracing setup. It writes no file and connects to nothing.

```sh theme={null}
magpie-server setup --dir ./my-app                      # default: the current folder
magpie-server setup --dir ./my-app --url https://magpie-host:4318 --auth keys --json
```

It reads four files of the folder, not its sub-folders:

| File | Framework, by its package |
| - | - |
| `package.json` | Vercel AI SDK: `ai`. Mastra: `@mastra/...` |
| `pyproject.toml`, `requirements.txt` | OpenAI Agents SDK: `openai-agents`. LangChain and LangGraph: `langchain`, `langgraph`, `langsmith`, `langchain-...`, `langgraph-...` |
| `Cargo.toml` | none (the plain setup) |

For each framework it prints the install line, the environment variables, the code, whether the setup was tested with Magpie, and a link to the framework's docs. A project with none of them gets the plain [OpenTelemetry](https://docs.magpiedb.com/guides/opentelemetry.md) variables. The output ends with the `doctor` command that checks the server.

| Flag | Default | What it does |
| - | - | - |
| `--dir <folder>` | `.` | The folder of the project. |
| `--url <address>` | `http://127.0.0.1:4318` | Goes into the variables and the code. An `https://` address adds `OTEL_EXPORTER_OTLP_CERTIFICATE=ca.pem`. |
| `--auth keys` | off | The server has API keys: adds `OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer%20mgp_..."`. |
| `--json` | off | One JSON object. `setups[].id` is `openai-agents`, `vercel-ai-sdk`, `langchain`, `mastra` or `opentelemetry`. |

Exit code `0`, or `2` for wrong flags or a `--dir` that is not a folder.

> [card] [Set up with a coding agent](https://docs.magpiedb.com/agent-setup.md)
>
> The steps a coding agent follows, with `doctor` as the check.

> [card] [MCP for agents](https://docs.magpiedb.com/guides/mcp.md)
>
> Let an agent query the traces.


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