docs: add tested Mozilla AI mcpd integration and PHP example
Some checks are pending
CI / vet-build-test (push) Waiting to run
Some checks are pending
CI / vet-build-test (push) Waiting to run
This commit is contained in:
parent
0664591b57
commit
70054e68e6
7 changed files with 211 additions and 0 deletions
|
|
@ -91,6 +91,9 @@ flowchart LR
|
|||
Client -->|"regular Tailscale app"| Hub["Hub with embedded Tailscale"]
|
||||
```
|
||||
|
||||
**Mozilla AI mcpd supported:** use the [tested daemon configuration](examples/mcpd/README.md)
|
||||
to manage devbox through mcpd, with optional Go or PHP middleware plugins.
|
||||
|
||||
Read the [MCP setup guide](docs/MCP.md) for tool names, configuration, execution
|
||||
limits, and errors, or the [implementation plan](docs/MCP-PLAN.md) for scope.
|
||||
|
||||
|
|
|
|||
13
docs/MCP.md
13
docs/MCP.md
|
|
@ -61,6 +61,19 @@ Use the MCP configuration location supported by your agent. On Windows, select
|
|||
the absolute path to `devbox.exe`. Restart or reconnect the agent after adding
|
||||
the server.
|
||||
|
||||
## Use Mozilla AI mcpd
|
||||
|
||||
Mozilla AI's Go-based **mcpd** can manage `devbox mcp` and expose its tools through
|
||||
its HTTP API. The [tested mcpd example](../examples/mcpd/README.md) includes a
|
||||
Docker-runtime configuration, read-only enrollment mounts, explicit tool
|
||||
allowlisting, timeout settings, and a PHP HTTP example. It was verified with
|
||||
mcpd v0.7.0 and devbox v2.2.0 on Linux, including authenticated snapshot history.
|
||||
|
||||
Mozilla's [Go plugin SDK](https://github.com/mozilla-ai/mcpd-plugins-sdk-go) and
|
||||
the community [PHP plugin SDK](https://github.com/shoemoney/mcpd-plugins-sdk-php)
|
||||
provide optional middleware around daemon requests/responses. Devbox's native
|
||||
MCP tools work through mcpd without adding a plugin dependency.
|
||||
|
||||
## Available tools
|
||||
|
||||
The default server exposes inspection tools only:
|
||||
|
|
|
|||
1
examples/mcpd/.gitignore
vendored
Normal file
1
examples/mcpd/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
runtime.local.toml
|
||||
126
examples/mcpd/README.md
Normal file
126
examples/mcpd/README.md
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
# 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. No new
|
||||
Go dependency is required in devbox for mcpd to manage it.
|
||||
|
||||
## 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.
|
||||
13
examples/mcpd/mcpd.toml
Normal file
13
examples/mcpd/mcpd.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[[servers]]
|
||||
name = "devbox"
|
||||
package = "docker::alpine@3.22"
|
||||
tools = ["devbox_status", "devbox_doctor", "devbox_conflicts", "devbox_history", "devbox_members"]
|
||||
[servers.volumes.binary]
|
||||
path = "/opt/devbox/devbox:ro"
|
||||
required = true
|
||||
[servers.volumes.config]
|
||||
path = "/config/devbox:ro"
|
||||
required = true
|
||||
[servers.volumes.certificates]
|
||||
path = "/etc/ssl/certs:ro"
|
||||
required = true
|
||||
10
examples/mcpd/runtime.example.toml
Normal file
10
examples/mcpd/runtime.example.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Local execution context: replace these paths before starting mcpd.
|
||||
# The binary must be a Linux binary matching Docker's architecture.
|
||||
[servers.devbox]
|
||||
args = ["/opt/devbox/devbox", "mcp"]
|
||||
[servers.devbox.env]
|
||||
XDG_CONFIG_HOME = "/config"
|
||||
[servers.devbox.volumes]
|
||||
binary = "/absolute/path/to/linux/devbox"
|
||||
config = "/absolute/path/to/config-base/devbox"
|
||||
certificates = "/etc/ssl/certs"
|
||||
45
examples/mcpd/status.php
Normal file
45
examples/mcpd/status.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// Plain HTTP example for mcpd's REST API. Plugin SDKs are a separate layer.
|
||||
$base = rtrim(getenv('MCPD_URL') ?: 'http://127.0.0.1:8090', '/');
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/json\r\nAccept: application/json\r\n",
|
||||
'content' => '{}',
|
||||
'timeout' => 10,
|
||||
'ignore_errors' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = file_get_contents($base . '/api/v1/servers/devbox/tools/devbox_status', false, $context);
|
||||
if ($response === false) {
|
||||
throw new RuntimeException('Could not reach mcpd; check MCPD_URL and daemon status.');
|
||||
}
|
||||
$headers = $http_response_header ?? [];
|
||||
$status = 0;
|
||||
foreach ($headers as $header) {
|
||||
if (preg_match('~^HTTP/\S+\s+(\d{3})~', $header, $matches)) {
|
||||
$status = (int) $matches[1];
|
||||
}
|
||||
}
|
||||
if ($status < 200 || $status >= 300) {
|
||||
throw new RuntimeException('mcpd returned HTTP ' . $status . ': ' . $response);
|
||||
}
|
||||
$result = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
|
||||
// mcpd v0.7.0 returns a JSON string containing devbox's text envelope.
|
||||
if (is_string($result)) {
|
||||
$result = json_decode($result, true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
if (!is_array($result) || !array_key_exists('exit_code', $result)) {
|
||||
throw new RuntimeException('Unexpected mcpd response shape.');
|
||||
}
|
||||
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR), PHP_EOL;
|
||||
exit($result['exit_code'] === 0 && empty($result['error']) ? 0 : 1);
|
||||
} catch (Throwable $error) {
|
||||
fwrite(STDERR, $error->getMessage() . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
Loading…
Reference in a new issue