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

# Run in Docker

> Run magpie-server with Docker, Docker Compose or Kubernetes, and open it to other machines with keys and TLS.

```sh theme={null}
docker run --rm -p 127.0.0.1:4318:4318 -p 127.0.0.1:4317:4317 -v magpie-data:/data ghcr.io/intojhanurag/magpie-server:0.1.0
```

The store is in the volume `/data`. In the container the server listens on `0.0.0.0`, so the published ports reach it; `-p 127.0.0.1:...` keeps it on this machine. `docker stop` sends SIGTERM, and the server closes the store.

To build the same image from the sources (some minutes), run `docker build -t magpie-server .` in the repo root, then `docker run ... magpie-server`. What the image holds and which flags it sets: [Server flags, "Docker"](https://docs.magpiedb.com/reference/server.md#docker).

## Open it to other machines

Add API keys and TLS. Arguments after the image name are added to the server's flags:

```sh theme={null}
docker run -p 4318:4318 -p 4317:4317 -v magpie-data:/data ghcr.io/intojhanurag/magpie-server:0.1.0 \
  --auth keys --keys-file /data/keys.jsonl --tls-cert /data/cert.pem --tls-key /data/key.pem
```

How to make the key file and the certificate: [Secure the server](https://docs.magpiedb.com/operations/keys-tls.md).

## Give the service name

With no keys, the image's host check is on: `localhost` and IP addresses pass, and a service name must be given with `--allowed-host`. With keys there is no host check ([Host names](https://docs.magpiedb.com/reference/server.md#host-names)).

> [tab] Docker Compose
>
> An app in the same file sends to the service name `magpie`:
>
> ```yaml theme={null}
> services:
>   magpie:
>     image: ghcr.io/intojhanurag/magpie-server:0.1.0   # or: build: . (from this repo)
>     command: ["--allowed-host", "magpie"]   # added to the image's own flags
>     ports: ["127.0.0.1:4318:4318", "127.0.0.1:4317:4317"]
>     volumes: ["magpie-data:/data"]
>   app:
>     environment:
>       OTEL_EXPORTER_OTLP_ENDPOINT: http://magpie:4318
> volumes:
>   magpie-data:
> ```

> [tab] Kubernetes
>
> A Service `magpie` in the namespace `observability`. The probe sends the pod's IP, which passes:
>
> ```yaml theme={null}
> containers:
>   - name: magpie
>     image: ghcr.io/intojhanurag/magpie-server:0.1.0
>     args: ["--allowed-host", "magpie", "--allowed-host", "magpie.observability",
>            "--allowed-host", "magpie.observability.svc.cluster.local"]
>     ports: [{containerPort: 4318}, {containerPort: 4317}]
>     readinessProbe:
>       httpGet: {path: /healthz, port: 4318}
> ```
>
> The image gives its user as numbers (uid and gid 10001), so `runAsNonRoot: true` accepts it. Give a new volume `securityContext: {fsGroup: 10001}` in the pod.

These two files were not run (no Docker or Kubernetes on the test machine). The host rule they need is tested on the binary (`tests/hardening.rs`).

> [!WARNING]
>
> On a network that other people reach, use `--auth keys` and TLS, not the host check alone.

## Settings that matter

| setting | why |
| - | - |
| a volume on `/data` | The store. A bind mount instead must be writable by uid 10001. |
| `--allowed-host <service name>` | With no keys, the service name of the clients. |
| a pids limit of 4,096 or more | With tenants (100 open stores by default), each open store holds threads. See [Memory and threads](https://docs.magpiedb.com/operations/errors-memory.md#memory-and-threads). |
| 1 GB of memory or less | Lower the SDK's batch with `--max-body-bytes` and `--max-mapped-bytes`. See [Memory and threads](https://docs.magpiedb.com/operations/errors-memory.md#memory-and-threads). |

> [card] [Secure the server](https://docs.magpiedb.com/operations/keys-tls.md)
>
> Turn on API keys and TLS.

> [card] [Tenants](https://docs.magpiedb.com/operations/tenants.md)
>
> One store per customer.

> [card] [Store on S3](https://docs.magpiedb.com/operations/s3.md)
>
> Keep the store in a bucket too.


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