ordainer-mcp
by Tyler-CEO
README.md
# ordainer-mcp
A local [MCP](https://modelcontextprotocol.io) server for Ordainer. It lets your AI coding agent (Cursor, Claude Code, Claude Desktop and other MCP clients) set up and watch Ordainer for you: create a customer, a plan and a **test** key, check how close each key is to its cap, see who would have been denied, raise a cap, and switch a plan from shadow to enforce.
It runs on your computer over stdio and talks to the Ordainer admin API with an admin key you give it. **Test keys and test data only.** Every change shows you a preview first and needs your accept.
> Version 0.1.1. Requires Node 20 or later.
## Set up
1. In the Ordainer console, create an **admin key** (Console → Admin keys) with only the scopes you want the agent to have. `usage:read` alone makes it watch-only.
2. Install with `npx -y ordainer-mcp` (or `npm i -g ordainer-mcp`) and point your client at it. The admin key goes in the environment, never in a file the agent reads:
```json
{
"mcpServers": {
"ordainer": {
"command": "npx",
"args": ["-y", "ordainer-mcp"],
"env": { "ORDAINER_ADMIN_KEY": "ord_admin_..." }
}
}
}
```
`npx -y ordainer-mcp` starts the stdio server. After `npm i -g ordainer-mcp`, you can use `"command": "ordainer-mcp"` with no `args`.
| Variable | Meaning |
|---|---|
| `ORDAINER_ADMIN_KEY` | Required. The organization always comes from this key; there is no org argument. |
| `ORDAINER_MCP_READ_ONLY` | `true` hides every write tool. |
| `ORDAINER_BASE_URL` | Unset (or blank) means `https://api.ordainer.dev`. A blank value also writes one info line to stderr (`blank, using default`). Otherwise it must be `https://…`, or `http://` for `localhost`, `127.0.0.1` or `[::1]` only, with no `?`, `#` or control character. Any other value (a typo such as `htp:/x`, `localhost:3000`, `ftp://…`, a trailing `?` or `#`) is a configuration error: every tool answers `config_invalid` and no request is made. It never falls back to production. |
| `ORDAINER_CONSOLE_URL` | Only for the link in key results. Unset (or blank) means it is derived from the API URL. The default keeps the scheme and port and drops the path: when the API host starts with `api.` followed by a name (for example `api.ordainer.dev`), that prefix is replaced with `console.` and `/console` is appended (so the default is `https://console.ordainer.dev/console`, and `https://api.example.test:8443/ordainer` gives `https://console.example.test:8443/console`). Any other host, including `localhost`, `127.0.0.1` and `[::1]`, keeps the API origin and appends `/console`. If you set it, it must be `https://…`, or `http://` for `localhost`, `127.0.0.1` or `[::1]` only, with no user name, password, `?`, `#`, space, backslash, invisible or control character, and at most 2,048 characters (a path such as `/console` is fine, and trailing slashes are removed). The link uses the address as parsed, so case and a default `:443` are normalised. Any other value is a configuration error, handled like a bad `ORDAINER_BASE_URL`: it is logged at start, every tool answers `config_invalid` and no request is made. It never falls back to the default. |
If `ORDAINER_ADMIN_KEY` is missing the server still starts and every tool answers `auth_failed` with the fix.
## Tools
Reads (no confirm): `list_customers`, `list_plans`, `list_keys`, `get_key_usage`, `list_decisions`, `list_changes`.
Writes (preview, then you accept): `create_customer`, `create_plan`, `set_cap`, `set_mode`, `create_key`, `rotate_key`.
`list_decisions` shows **would-denies** (shadow-mode denies) by default. Pass `request_id` to look up one decision of any kind.
Resources: `ordainer://docs/concepts`, `ordainer://org/summary`. Prompts: `onboard_integration`, `shadow_to_enforce_review`, `investigate_deny`.
## How a change is confirmed
A write tool never changes anything on the model's say-so. It shows **you** a preview through your client's confirm form (MCP elicitation) and makes exactly one admin call only if you accept. Declining, closing the form, an expired form (15 minutes), or a form that has been used before changes nothing. Both MCP protocol revisions (2025-11-25 and 2026-07-28) are supported.
A client that cannot show the form still lists the write tools; they answer `confirm_unsupported` and change nothing. There is no weaker "type this code" fallback.
## Keys never reach the model
`create_key` and `rotate_key` write the new secret to a local env file (mode 0600), as `ORDAINER_KEY` (the variable the Ordainer SDKs read) or `ORDAINER_KEY_<LABEL>` with `env_label`. The agent only gets the file path, the masked key (`ord_test_…last4`) and the key id.
- A file that already has the variable is never overwritten by `create_key` (`env_key_exists`); name another variable or file.
- `rotate_key` replaces a line only if it holds the key being rotated; otherwise `env_key_mismatch`.
- The file is checked before any admin call (path, name, symlinks, an existing variable, write access), and a problem there creates nothing.
- If the write still fails **after** the admin call (for example the folder became read-only in between), the key **exists**: the result is `env_write_failed` with the key id and the secret is discarded, never shown. Revoke that key in the console or run `rotate_key` on it. On `rotate_key` the old key is **already revoked** and its replacement's secret is lost, so rotate the new key again.
- An existing env file keeps its other lines, quotes and comments, but its line endings are normalised to LF and its mode is forced to 0600.
- The file must be inside the folder the server runs in and be named `.env`, `.env.*` or `*.env`. The result warns if `.gitignore` does not cover it.
- Anything that looks like a full key is masked in every result and log.
## Limits you should know
- Live keys are never listed, created, rotated or changed. A plan that has a live key can't be changed here (`live_key_refused`).
- No delete tool. Revoke an admin key in the console to cut the agent off at once; the next call answers `auth_failed`.
- Lists return at most 100 rows per call with a `next_cursor`.
- Text in names, labels and reasons is data from your account, not instructions; results say so. Names, labels and env file paths are shown to you quoted, with line breaks, control characters and invisible characters escaped, so a hostile name cannot fake a line in a preview.
- A plan that has a live key can't be changed, but the admin API only says so when the change is attempted: you see the preview first, and the refusal comes after you accept (nothing changes).
- Error results are plain text (`code: message Fix: …` and the same body as JSON on the last line) with no `structuredContent`, so clients that validate results against a tool's output schema show the refusal instead of a schema error.
- The packages `@modelcontextprotocol/server` and `zod` are pinned to the versions tested here (the SDK is a new 2.x line).
## Development
```
npm ci
npm test # unit + in-process tests against a fake admin API, both protocol eras, stdio e2e
```
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues