devbox/examples/mcpd/README.md
shoemoney 36690ee292
Some checks are pending
CI / vet-build-test (push) Waiting to run
docs: ship native Mozilla Go SDK plugin setup and v2.3.0 notes
2026-11-27 23:01:43 -06:00

183 lines
7.8 KiB
Markdown

# Mozilla AI mcpd + devbox
Use Mozilla AI's **Go daemon** to manage the Go `devbox mcp` server. This
example was exercised with **mcpd v0.7.0** and **devbox v2.2.0** on Linux.
It discovered all five inspection tools and called status and authenticated
snapshot history through mcpd's HTTP API.
## How the pieces fit
- `devbox mcp` implements the sync tools and speaks MCP over stdio.
- [mcpd](https://github.com/mozilla-ai/mcpd) starts and manages the server and
exposes its tools through REST endpoints.
- Mozilla's [Go plugin SDK](https://github.com/mozilla-ai/mcpd-plugins-sdk-go)
extends mcpd with middleware: authentication, observability, rate limiting,
and request/response processing.
- The community [PHP plugin SDK](https://github.com/shoemoney/mcpd-plugins-sdk-php)
serves that same middleware role. `status.php` here is a plain HTTP consumer;
it does not require a plugin SDK.
The plugin SDK and the MCP tool server are separate integration points. Basic
mcpd management works without a plugin. **v2.3.0 also ships an optional native
`devbox-mcpd-plugin` built with Mozilla's official Go plugin SDK.**
## 1. Install the prerequisites
Install mcpd from [Mozilla's releases](https://github.com/mozilla-ai/mcpd/releases)
and Docker. Download a **Linux** devbox binary matching Docker's architecture
from the [devbox release](https://github.com/shoemoney/devbox/releases/tag/v2.2.0),
check its SHA256SUMS entry, and make it executable. A macOS/Windows binary
cannot run inside the Linux Alpine container.
mcpd v0.7.0 supports `uvx`, `npx`, and Docker runtimes; it has no general native
binary launcher. This example uses its Docker runtime, which starts the released
static Go binary in Alpine. No Node.js or Python server runtime is involved.
## 2. Select the devbox configuration
Copy `runtime.example.toml` to an untracked local runtime file and replace:
- `binary`: absolute path to the Linux devbox binary.
- `config`: absolute path to the **devbox config directory itself**, such as
`/home/alice/.config/devbox`, containing the existing enrollment.
- `certificates`: the Linux host's CA certificate directory, usually
`/etc/ssl/certs`.
For a fresh configuration, create the config directory first. Enroll using the
normal CLI before expecting authenticated tools to work. The config directory
and binary are mounted read-only. No tokens belong in `mcpd.toml` or the example
runtime file. Keep the actual enrollment directory private.
mcpd's Docker runtime uses host networking in v0.7.0. On Linux this gives the
client the host's network routes, including its regular Tailscale connection.
The hub can continue using embedded Tailscale. This is a Linux host example;
Docker Desktop networking, certificate paths, and filesystem mounts need their
own configuration on macOS and Windows.
## 3. Start mcpd
Run from this directory, substituting your local runtime file:
```bash
mcpd daemon \
--config-file ./mcpd.toml \
--runtime-file /absolute/path/to/runtime.local.toml \
--addr 127.0.0.1:8090 \
--timeout-mcp-request 150s
```
The daemon request timeout is longer than devbox's default two-minute command
timeout. The tool allowlist is explicit: status, doctor, conflicts, history, and
memberships. Only inspection tools are enabled.
## 4. Call devbox through the daemon
```bash
curl -fsS http://127.0.0.1:8090/api/v1/servers/devbox/tools
curl -fsS -X POST \
http://127.0.0.1:8090/api/v1/servers/devbox/tools/devbox_status \
-H 'Content-Type: application/json' \
-d '{}'
curl -fsS -X POST \
http://127.0.0.1:8090/api/v1/servers/devbox/tools/devbox_history \
-H 'Content-Type: application/json' \
-d '{"share":"projects","limit":5}'
```
mcpd v0.7.0 returns devbox's JSON text result as a JSON string. Decode the HTTP
JSON, then decode that string to get devbox's result envelope. `status.php`
handles this and also accepts an already-decoded envelope:
```bash
MCPD_URL=http://127.0.0.1:8090 php status.php
```
**These are REST endpoints.** They are not Streamable HTTP MCP endpoints. For
an MCP-only agent, use Mozilla's
[mcpd-proxy](https://github.com/mozilla-ai/mcpd-client#manual-integration) adapter,
or connect the agent directly to `devbox mcp` as in the
[built-in MCP guide](../../docs/MCP.md). The proxy configuration is documented
upstream; the REST path above is the integration exercised here.
## Workspace paths and tool visibility
If the enrolled configuration contains mounts, add matching workspace volumes
to both files before using conflict/doctor tools. Each workspace must appear
inside the container at the **same absolute path** used by `daemon.toml`.
For example, if the real mount lives at `/home/alice/Projects`:
```toml
# Add to mcpd.toml
[servers.volumes.workspace]
path = "/home/alice/Projects:ro"
required = true
```
```toml
# Add under [servers.devbox.volumes] in the local runtime file
workspace = "/home/alice/Projects"
```
Without workspace mounts, status/history/membership queries can still use the
config and hub, but filesystem diagnostics cannot inspect the actual files.
This example does not enable mutation tools. Enabling them also requires writable
mounts, appropriate container ownership, and an updated mcpd tool allowlist.
Use the [native MCP guide](../../docs/MCP.md) for the tool permission model.
## Use the native Mozilla Go SDK plugin (v2.3.0)
Install the optional plugin along with the client:
```bash
curl -fsSL https://git.shoemoney.ai/shoemoney/devbox-dist/releases/download/latest/install.sh -o install.sh
sh install.sh --mcpd-plugin --no-service
```
On Windows the PowerShell installer supports `-McpdPlugin`. Select the plugin
binary matching the machine running **mcpd**, which may be different from
Docker's Linux architecture. The Linux binary requirement above applies to the
MCP server inside the container, not the native middleware process.
Create a dedicated plugin directory and place the executable inside it:
```bash
mkdir -p ./plugins
cp /absolute/path/to/devbox-mcpd-plugin ./plugins/devbox-mcpd-plugin
chmod 755 ./plugins/devbox-mcpd-plugin
```
Copy `mcpd-with-plugin.toml` and set `[plugins].dir` to that directory's absolute
path. The configured plugin name must match the executable filename. Start the
daemon with that configuration and your existing runtime file:
```bash
mcpd daemon --config-file ./mcpd-with-plugin.toml --runtime-file /absolute/path/to/runtime.local.toml --addr 127.0.0.1:8090 --timeout-mcp-request 150s --log-level INFO --log-path ./mcpd.log
```
mcpd launches the native plugin over its standard gRPC socket protocol. The
plugin is written against `mozilla-ai/mcpd-plugins-sdk-go`; it is a separate
native executable included in devbox releases, not a replacement for
`devbox mcp`.
The plugin records **request metadata only** for recognized devbox tool-call
routes: the event, plugin version, HTTP method, and tool name. It leaves the
request unchanged. Audit records exclude arguments, request/response bodies,
headers, query strings, user identities, network addresses, filenames, and file
contents. It does not change tool permissions or authorize a write. The
observability category is optional; these records are operational telemetry,
not a durable transaction history or proof an operation completed.
Only the request flow is advertised. Other daemon routes pass through without
a devbox audit event. mcpd captures the plugin's stderr and forwards it into its
logs. Its normal startup/lifecycle logs are separate from the audit records.
### Verified behavior
The v2.3.0 plugin was exercised in a real mcpd v0.7.0 process. It registered,
received tool requests, emitted `devbox.tool.request` records, and left
header/query/body sentinels out of those records. An unlisted write tool still
received HTTP 403. On daemon shutdown the native plugin exited without a
forced-kill warning. Unit tests also exercise the official SDK's metadata,
capability, health, readiness, request, and Stop RPCs over real gRPC.