Control plane API
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
The control plane (api.mzpanel.com) serves three things: a REST API on /v1 (the
dashboard uses it, and so does any automation with an API token), the MCP server
(mcp.mzpanel.com), and the WebSocket the on-VPS agents dial into. This page
orients you on all three. For a hands-on start, see the
REST API quickstart.
| Caller | Credential |
|---|---|
| Dashboard → API | A session cookie (httpOnly, SameSite=Lax, Secure), set at sign-in, plus a CSRF token on mutations. |
| Your automation / AI → API or MCP | An API token: Authorization: Bearer mzmcp_…, minted at Advanced → Developer (/developer). It is scoped by access level, opt-in scopes, a server allowlist and an optional client IP allowlist (403 token_ip_denied from other addresses), and capped by the minting user’s role. Available on every plan. See Tokens, levels & scopes. |
| Agent → API (WebSocket) | A long-lived agent token, obtained at registration by exchanging a one-time install token (1-hour TTL). |
The full management API
Section titled “The full management API”API tokens call the same /v1 routes the dashboard uses. A bearer bridge in front
of them looks the request up in an operation table, then checks the token’s level, the
opt-in scope, the server allowlist and the plan. It then runs the exact same handler as
the token’s user. Requests are strict (unknown body keys are rejected with a hint) and
every non-GET call is audited as api.<operation id>.
- Discovery:
GET /v1/api/operationslists every callable operation (about 350), every job kind with its risk class, and the opt-in scopes, each markedallowed_for_this_token. It is the source of truth for what’s callable. - Job body schemas:
GET /v1/api/job-kinds/{type}. - Deny by default: a
/v1route that isn’t in the table answers403 not_exposedfor Bearer requests. - MCP projection: each operation is also an MCP tool named after its id
(
dns.records_create→dns_records_create).
Shortcuts under /v1/api
Section titled “Shortcuts under /v1/api”A handful of synchronous convenience endpoints authenticate the token themselves and return results inline. They predate the full API:
| Method and path | Purpose |
|---|---|
GET /v1/api/whoami | Token name, access_level, org_id, server_scope, role |
GET /v1/api/servers · GET /v1/api/servers/{id} | Servers visible to the token; one server with its last metrics |
GET /v1/api/servers/{id}/{sites,services,php,databases,updates,cron,docker} | Cached inventory |
GET /v1/api/servers/{id}/sites/{domain} | Live site info |
GET /v1/api/servers/{id}/metrics | Last heartbeat metrics |
GET /v1/api/servers/{id}/logs?source=&lines= | Live log tail (nginx-error, nginx-access, php-fpm, mariadb, syslog, auth) |
GET /v1/api/servers/{id}/ssl | Live certificate list |
POST /v1/api/servers/{id}/services/{name}/{start,stop,restart} | Service control |
POST /v1/api/servers/{id}/ssl/renew[?domain=] | Renew certificates |
POST /v1/api/servers/{id}/sites/{domain}/cache/purge | Purge a site cache |
POST /v1/api/servers/{id}/updates/apply | Apply OS updates ({"scope":"security"|"all"}) |
GET /v1/openapi.json | The OpenAPI 3.1 document of the whole API (every operation, the shortcuts and every job kind); ?tag=<area> for one area. See Import the API |
Route groups
Section titled “Route groups”| Group | Purpose | Token-callable |
|---|---|---|
/v1/servers | Servers, enrolment, provisioning, inventory, metrics, sites, Docker views, agent updates, file manager (/fs), backup jobs | Yes (most) |
/v1/servers/{id}/jobs, /v1/jobs | Dispatch any on-box job kind, poll, stream | Yes |
/v1/backups | Destinations, snapshots, restore | Yes |
/v1/dns, /v1/domains | DNS provider connections and records, wildcard, Origin and custom certs, CDN purge; domain registry | Yes |
/v1/mail | Mail host settings, sending providers, Cloudflare routing, mailbox messages | Yes (message ops need mail scopes) |
/v1/uptime, /v1/notify, /v1/notifications | Monitors, channels, status page; alert routing; in-app inbox | Yes |
/v1/projects, /v1/env-vars, /v1/moves | Projects and environments, shared variables, app/stack moves and clones | Yes |
/v1/load-balancers, /v1/network | Load balancers, private WireGuard mesh | Yes (Pro) |
/v1/git, /v1/registry-connections | Git provider and container registry connections | Yes |
/v1/templates, /v1/notes, /v1/server-tags, /v1/site-tags, /v1/install-tokens | Templates, notes, tags, pending install tokens | Yes |
/v1/team, /v1/orgs | Members, invites, activity; workspace rename | Yes (member changes need team:admin) |
/v1/dev | Developer webhooks | Yes (Pro) |
/v1/wp, /v1/links, /v1/ai | WordPress directory, link manager, AI runtime overview | Yes |
/v1/api/metrics/prometheus | Fleet server metrics and uptime-monitor state in the Prometheus text format (setup) | Yes (any level) |
/v1/billing, /v1/account, /v1/auth | Subscription and wallet; profile, sessions, 2FA; sign-in | No (session only) |
/v1/admin | Staff console | No |
/v1/agent/* | Agent registration, binary, WebSocket upgrade | Agent token only |
/health | Liveness (GET https://api.mzpanel.com/health) | Public |
Error shape
Section titled “Error shape”Every error uses one envelope, never a stack trace:
{ "error": { "code": "scope_required", "message": "human readable", "details": { "required_scope": "sites:delete" } } }Clients should switch on error.code (stable), not message, and ignore fields they
don’t know. The /v1/api shortcuts may add error.status. The codes an agent meets most
often are unauthorized, not_exposed, access_level, scope_required, fleet_wide,
tier_required, forbidden, not_found, bad_request, server_limit (402),
server_offline (409) and rate_limited (429, with Retry-After). Each one is
explained, with the right reaction, in the
REST API quickstart error table.
Rate limits are per API token per minute: Free 60, Plus 120, Pro 300, Max 600. MCP and REST share the budget.
Agent WebSocket protocol
Section titled “Agent WebSocket protocol”The agent dials outbound to wss://ws.mzpanel.com/v1/agent and holds one persistent
connection, so the VPS opens no inbound ports. Messages are JSON envelopes:
type Envelope = { v: 1; // protocol version id: string; // message UUID ts: number; // unix ms type: string; // hello, welcome, heartbeat, cmd, log, job_done, event, … ref?: string; // optional reference to another message's id payload: unknown;};- The agent connects and sends
hello(agent version, hostname, OS, sealed-credential public key). The API replieswelcome. - The agent sends a
heartbeatevery 10 s with a metrics snapshot, and pushesinventoryfor the cached read model. - The API sends
cmdenvelopes (a job’s argv for the native engine). The agent streamsloglines and ends withjob_done(exit code and duration).cmd.cancelaborts a run. - The agent pushes
eventenvelopes for out-of-band happenings (backup done, certificate renewed, service down).
The same connection carries pty.* (web terminal), fs.* / xfer.* (file manager and
cross-server transfer) and binary upload/download frames. Wire types live in the shared
Go module pkg/protocol.
Gotchas
Section titled “Gotchas”- CORS is locked to the dashboard. Browser calls from other origins are rejected. Server-side clients with a Bearer token are not affected.
- Agent routes bypass the cookie.
/v1/agent/*is bearer-authed with the agent token. A browser session can’t call it, and an agent token can’t call the cookie routes. - Cross-org and out-of-scope ids answer 404, not 403, so the API never confirms that a resource exists.