Postkub MCP server
Give MCP clients scoped access to Postkub through a local stdio server that calls the same REST API as the CLI.
Updated
On this page
The Postkub MCP server (package @postkub/mcp, command postkub-mcp) is a thin Model Context Protocol client of the Postkub REST API. Each tool call performs exactly one authorized REST request with the same scoped key, idempotency, and record lifecycle as the CLI — the host AI never gets a broader channel than the key allows.
Warning
The Postkub MCP server is in preview and is not yet installable from npm. Today it runs as a local stdio process from a Postkub source checkout against a local or development API. This page describes the planned public interface; tool names and inputs may still change before release.
How it works
The server is a local stdio process, not a hosted endpoint. Your MCP client launches it, hands it a scoped API key through environment variables, and speaks the standard MCP stdio protocol with it. On every tool call the server builds the same REST request the CLI would build and sends it to POSTKUB_API_URL.
- It never touches your Postkub database, job queue, provider OAuth credentials, local files, or social networks directly. Everything goes through server-side authorization and tenant checks with the key's scopes.
- There is no media byte-upload or filesystem tool. Posts attach ordered, publicly accessible HTTPS media URLs (
mediaUrls), following the hosted media contract; humans upload files through the web UI. - Tool schemas are not hard-coded. At startup the server fetches the API's OpenAPI document and derives every tool's request and response schema from it, so the served document stays the single source of truth.
Note
At startup the server reads GET <POSTKUB_API_URL>/api/docs-json. That document is served by local and development API instances only — production does not serve it yet — so the MCP server currently works against a local or development API only.
Environment
| Variable | Required | Purpose |
|---|---|---|
POSTKUB_API_URL | no | Base URL of the Postkub API. Defaults to http://127.0.0.1:4000. HTTPS is enforced for non-loopback hosts; plain HTTP is allowed for local development. |
POSTKUB_API_KEY | yes | A scoped API key. Startup fails without it. |
POSTKUB_TIMEOUT_MS | no | Per-request REST deadline in milliseconds, 1–900000. Default 30000. |
Client configuration
Run the server from a Postkub checkout (dependencies installed) and point your MCP client at it as a local stdio server:
POSTKUB_API_URL=http://localhost:4000 POSTKUB_API_KEY=<API_KEY> \
pnpm --filter @postkub/mcp exec tsx src/main.ts
An MCP client configuration then looks like this:
{
"mcpServers": {
"postkub": {
"command": "pnpm",
"args": ["--filter", "@postkub/mcp", "exec", "tsx", "src/main.ts"],
"env": {
"POSTKUB_API_URL": "http://localhost:4000",
"POSTKUB_API_KEY": "<API_KEY>"
}
}
}
}
The command and args run inside the checkout directory — if your client supports a working-directory option, set it to the Postkub checkout; otherwise wrap the command in a shell that changes directory first. Inject the key through the client's environment mechanism, never into files inside the repository.
Warning
Planned: the registry install form (npx -y @postkub/mcp, launched as the postkub-mcp binary) will be documented here once the package passes testing and is published. It does not work today.
Tool catalog
Every REST tool maps to exactly one v1 operation, with the same scope the key needs for the equivalent CLI command:
| Tool | REST operation | Scope | Purpose |
|---|---|---|---|
whoami | GET /api/v1/me | any valid key | Inspect the principal, workspace, target IDs, and granted actions. |
brands_list | GET /api/v1/brands | brand:read | List Brands visible to the key. |
accounts_list | GET /api/v1/accounts | account:read | List connected social accounts. |
accounts_schedule_get | GET /api/v1/accounts/{id}/schedule-settings | account:read | Read an account's timezone and weekly queue slots. |
accounts_schedule_update | PATCH /api/v1/accounts/{id}/schedule-settings | account:schedule | Update the timezone and/or weekly slots. |
capabilities_get | GET /api/v1/accounts/{id}/capabilities | account:read | Read allowed actions and reasons for one account. |
posts_list | GET /api/v1/posts | post:read | List posts with Brand, account, status, and time filters. |
posts_get | GET /api/v1/posts/{id} | post:read | Read one post projection. |
posts_create | POST /api/v1/posts | post:create | Create a draft with hosted mediaUrls. |
posts_update | PATCH /api/v1/posts/{id} | post:update | Edit a draft (revision-guarded). |
posts_delete | DELETE /api/v1/posts/{id} | post:delete | Delete an unaccepted local draft. |
posts_publish | POST /api/v1/posts/{id}/publish | post:publish | Accept publish-now for selected accounts (202). |
posts_schedule | POST /api/v1/posts/{id}/schedule | post:schedule | Accept explicit schedules or the next queue slot (202). |
posts_cancel | POST /api/v1/posts/{id}/cancel | post:cancel | Cancel unstarted work for selected accounts. |
posts_retry | POST /api/v1/posts/{id}/retry | post:publish | Retry proven-no-effect failures. |
posts_cover-retry | POST /api/v1/posts/{id}/cover-retry | post:publish | Retry a failed video cover without re-uploading. |
threads_list | GET /api/v1/threads | comment:read | List inbox threads. |
threads_get | GET /api/v1/threads/{id} | comment:read | Read one thread with its comments. |
threads_update | PATCH /api/v1/threads/{id} | thread:update / thread:resolve | Update unread and/or handled state. |
comments_list | GET /api/v1/comments | comment:read | List comments. |
comments_reply | POST /api/v1/comments/{id}/replies | comment:reply | Accept a durable reply (202). |
insights_account | GET /api/v1/accounts/{id}/insights | insight:read | Read saved account metrics. |
insights_post | GET /api/v1/posts/{id}/insights | insight:read | Read saved post metrics. |
activity_list | GET /api/v1/activity | activity:read | List scoped activity and sanitized failures. |
replies_get | GET /api/v1/replies/{id} | comment:read | Read reply execution status. |
requests_get | GET /api/v1/requests/{requestId} | any valid key | Recover a mutation receipt. |
Four discovery tools complete the surface:
| Tool | Purpose |
|---|---|
threads_resolve | Mark a thread handled — a convenience wrapper over threads_update that sends handled: true (needs thread:resolve). |
list_schemas | List every derived REST tool with its operation, method, path, and required action. |
describe_schema | Return one operation's input parameters, request body, responses, and error schemas from the served OpenAPI document. |
get_context | Return Postkub's canonical agent guidance topics (the same topics as postkub context), one topic at a time or all at once. |
Field projection
Read tools accept an optional fields string with the same syntax as the CLI's --fields: comma-separated dot paths (items.id), brace expansion (items.{id,status}), or all. The projection is validated against the served response schemas before any request is sent, so an unknown path fails fast with an INVALID_FIELDS error instead of shrinking the response silently.
Results and errors
Every tool returns machine-readable structuredContent of the form { "status": <HTTP status>, "body": <response JSON>, "idempotencyKey": "<uuid, writes only>" }, plus the same payload as text content.
- Success: the HTTP status is 2xx and
isErroris absent. A 202 means Postkub accepted the intent — not that a social network completed the work. - REST rejection: HTTP 400–499 sets
isError: trueand carries the normalized error envelope inbody. See errors. - Transport failure: status 0 with
isError: trueand codeREQUEST_FAILED. The outcome is unknown — the result still echoes theidempotencyKeythat was sent, so the host can callrequests_getand replay the identical request with the same key. Never retry an uncertain write with a new key (idempotency). - Local validation: input that does not match the served operation schema fails before any network call with
isError: trueand codesINVALID_TOOL_INPUT,VALIDATION_ERROR, orINVALID_FIELDS.
For writes, the server generates a UUID Idempotency-Key when the tool input omits idempotencyKey, and always returns the key it used in structuredContent.
Example prompts
Ask the host AI naturally; it selects the tool:
Call whoami and summarize the Brand IDs, account IDs, and actions my key can use.
Create a draft with posts_create: brandId "brd_9x2k", text "Launch recap",
socialAccountIds ["acc_2gf8xh"], and mediaUrls ["https://cdn.example.com/recap.jpg"].
Schedule that draft into the next free queue slot for each account, then show me
the post ID, revision, and the exact fireAtUtc the API reserved.
The publish call returned status 0. Keep its idempotencyKey, call requests_get with
it, and tell me what happened before doing anything else.
Media must be a direct, public HTTPS URL that stays readable until publication completes — never a local path, a file upload, or a viewer/share page.
Troubleshooting
| Symptom | What to do |
|---|---|
postkub-mcp startup failed: POSTKUB_API_KEY is required | Inject a scoped key through the client's environment settings; the server refuses to start without one. |
| Startup fails with an OpenAPI fetch error | Check POSTKUB_API_URL and that <POSTKUB_API_URL>/api/docs-json responds. The startup fetch deadline is 5 seconds, and only local/development API instances serve the document today. |
INVALID_TOOL_INPUT | Call describe_schema for the tool's operation and match the served field names. |
INVALID_FIELDS | Remove the unknown projection path or inspect the response schema with describe_schema. |
| Status 0 on a write | Keep the returned idempotencyKey, call requests_get with it, and only then decide whether to replay with the same key. |
| Provider capability error on an accepted-shaped call | Call capabilities_get; the operation exists but that account cannot perform the action yet. |
| Media rejected | Use ordered, direct, public HTTPS URLs in mediaUrls; see hosted media. |
