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

# Coding agents

> Let Claude Code and other coding agents see your running project through the MCP server

Localdev has a built-in MCP server. A coding agent such as Claude Code can use it to look at your running project the way you would in the UI: which services crashed and why, what they printed, which requests failed, and what the logs and metrics say. The agent can then check its own changes against the real system: edit the code, restart the service, and see whether it still fails.

Because Localdev runs the services itself, the agent also sees what an observability tool can't: crashes, exit reasons, each service's stdout and stderr, and the traces a crash cut short.

The server is at `http://localhost:2345/mcp`, on the same address as the UI. It runs whenever Localdev runs, so there's nothing to install or start. Localdev prints its address at start-up:

```
	MCP server:     http://localhost:2345/mcp
```

All its tools are read-only: none of them can change anything.

## Connect an agent

Start Localdev first: the agent can only connect while Localdev runs. If you changed the address with `-server`, change the URL to match.

### Claude Code

Run this in your project's repository:

```sh theme={null}
claude mcp add --scope project --transport http localdev http://localhost:2345/mcp
```

`--scope project` saves the server in `.mcp.json` at the root of the repository. Commit it next to your Projectfile, and everyone on the project gets the server without setting it up. Claude Code asks each person to approve it the first time.

To check the connection, run `claude mcp list`, or `/mcp` inside Claude Code:

```
localdev: http://localhost:2345/mcp (HTTP) - ✔ Connected
```

### Cursor and VS Code

> [!WARNING]
>
> Localdev hasn't been tested with Cursor or VS Code yet. These are the standard configuration files for an MCP server over HTTP.

For Cursor, create `.cursor/mcp.json` in your project, or `~/.cursor/mcp.json` for every project:

```json .cursor/mcp.json theme={null}
{
  "mcpServers": {
    "localdev": { "url": "http://localhost:2345/mcp" }
  }
}
```

For VS Code with Copilot in agent mode, create `.vscode/mcp.json`:

```json .vscode/mcp.json theme={null}
{
  "servers": {
    "localdev": { "type": "http", "url": "http://localhost:2345/mcp" }
  }
}
```

### Other clients

The server uses the Streamable HTTP transport. Clients that only support stdio can't connect to it.

To try the tools by hand, use the command line of the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):

```sh theme={null}
npx @modelcontextprotocol/inspector --cli http://localhost:2345/mcp --method tools/list
npx @modelcontextprotocol/inspector --cli http://localhost:2345/mcp \
  --method tools/call --tool-name search_logs --tool-arg level=error limit=5
```

## The tools

| Tool | Use it for | Arguments (all optional unless marked) |
| - | - | - |
| `project_status` | Start here: every service and the collector, whether each is running, stopped, crashed or failed, its PID, start and stop times, and why it stopped | none |
| `service_output` | The last lines a service wrote: panics, stack traces, and the output of services that don't use OpenTelemetry | `service` (required), `stream` (`stderr`, the default, or `stdout`), `tail` (50, at most 500) |
| `search_logs` | Errors, what happened around a failure, and everything logged in one request | `query`, `services`, `level` (the lowest level: `error` means error and fatal), `trace_id`, `since`, `limit` (50, at most 200) |
| `search_traces` | Failed or slow requests and jobs, including those cut short by a crash | `status` (`error` or `ok`), `services`, `min_duration` (e.g. `500ms`), `query` (the start of a trace ID, a root operation or a service), `since`, `limit` (20, at most 100) |
| `get_trace` | One trace as a tree of spans: where it failed or spent its time, with error messages and exceptions | `trace_id` (required), `attributes` (also show the attributes of spans that didn't fail) |
| `list_metrics` | Which metrics exist: type, unit, series, attributes and the last point | `service`, `query` |
| `get_metric` | One metric summarised per series: the latest, minimum, average and maximum of gauges, the increase and rate of counters, and the count, average, p50, p95 and p99 of histograms | `service` and `name` (both required), `since`, `attributes` (only series with these values) |

`since` takes a duration (`15m`, `2h`, `1d`) or an RFC 3339 time. Without it, the tools search everything Localdev still has in memory.

The tools point to each other, and agents follow them: from `project_status` to `service_output` for a crashed service, from `search_traces status=error` to `get_trace`, from a trace ID to `search_logs trace_id=…`, and from `list_metrics` to `get_metric`.

### What the output looks like

The tools return text written for a model, not JSON. Times are local clock times, with a date when they're not today. Each result starts with the current time, so the agent can tell how old things are.

`search_traces`:

```
now: 10:59:01 GMT
the newest 2 of 3 matching traces, oldest first (narrow with status, services, min_duration, query or since):
started       took  status  spans  root      services  trace_id
10:58:56.673  75µs  ok      2      demo GET  demo      dab01c83b909a95b4967f41c93f396e6
10:58:56.682  61µs  ok      2      demo GET  demo      3538e6fa0abca61f3ca5cc93ef8c8452
```

`get_trace`:

```
trace dab01c83b909a95b4967f41c93f396e6: started 10:58:56.673, took 75µs, 2 spans, services: demo
start  took  span
+0s    75µs  demo GET (server)
+13µs  41µs    demo roll
```

* Failed spans show `ERROR: <message>`, their attributes, and any exception with its stack trace, cut at 30 lines.
* Three or more identical sibling spans that didn't fail are folded into one line, such as `gateway SELECT product (client) ×12, each 1ms to 2ms`. That makes an N+1 query easy to spot.
* A large trace is cut at 300 lines. Failed spans after the cut are still listed.

Errors tell the agent what to do next. For example, a misspelled service name returns `no service named "wroker"; services are: demo`. An unknown metric lists the service's metrics, an attribute filter that matches nothing lists the values that exist, and an empty result names the filters that were used.

> [!TIP]
>
> Spans and logs arrive up to about 10 seconds after a request, because OpenTelemetry SDKs send them in batches. The tools tell the agent to wait and search again. Most SDKs send metrics only every 60 seconds: set `OTEL_METRIC_EXPORT_INTERVAL: "5000"` in the Projectfile's `env` to send them every 5 seconds.

## What to expect

Ask about your project the way you'd ask a colleague:

* "Checkout is failing. Find out why."
* "Why did the worker die?"
* "I fixed the handler. Is it still failing?"
* "What's slow in this request?" or "What's the p95 latency of the order endpoint?"
* "Which services call inventory, and what does inventory call?"

Agents usually start with `project_status`, then follow the tools' hints: `service_output` for a service that crashed, and `get_trace` for the IDs that `search_traces` and `search_logs` return. They often mention problems you didn't ask about, such as a crashed service while you asked about latency. When your instrumentation records `code.filepath` on spans, the agent can tell where in your code a span comes from, and read the source next.

A specific question gets a faster and cheaper answer than a vague one. Every tool call adds its result to the conversation, and a vague question takes more calls. If you know which service is involved, say so.

## What the tools can see

> [!WARNING]
>
> Whatever a tool returns goes into the model's context, and so to your model provider. That includes log messages, span attributes, exception messages and service output, which can contain passwords, tokens and personal data.

* **Never returned:** the values of environment variables (from the Projectfile or Localdev's own), and span resource attributes, such as process command lines and host details.
* **Only what's in memory:** the tools see the same telemetry as the UI, within the same limits (see [`store`](https://docs.localdev.build/configuration/introduction#store)). It's gone when Localdev stops.
* **Only from this machine:** Localdev accepts MCP requests only from the machine it runs on. With `-server 0.0.0.0:2345`, other machines can open the UI, but they can't use the MCP server.
* **Not from web pages:** a request sent from another website's page is refused, and so is a request with an unexpected `Host` header.
* **No login:** like the rest of Localdev, any program you run on this machine can call it.

## Troubleshooting

| Symptom | Cause |
| - | - |
| The agent can't connect | Localdev isn't running, or runs on another `-server` address. Start Localdev, then reconnect (in Claude Code, `/mcp`). |
| `localdev: changes are only accepted from this machine` | The agent runs on another machine, or in a container without host networking. |
| `localdev: request rejected, it came from another website` | A browser-based client sent another website's `Origin`. |
| `ldev has received no traces yet` or `no metrics yet` | The services don't send OpenTelemetry, or haven't sent anything yet (see the tip above). `service_output` still works. |
| `405 Method Not Allowed` on `GET /mcp` | Expected: the server only answers POST requests. |

## Several projects at once

Each instance of Localdev has its own MCP server on its own `-server` port. Add each one under its own name, for example `localdev-shop` on port 2345 and `localdev-billing` on port 2355:

```sh theme={null}
claude mcp add --scope project --transport http localdev-billing http://localhost:2355/mcp
```

See the [CLI reference](https://docs.localdev.build/CLI-reference.md#two-instances-at-once) for running two instances side by side.


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