Skip to content

HTTP API

The UI talks to the Moka server over a small JSON API. You can use it too — for scripted demos, CI smoke tests or your own front end.

Auth: send the token printed at startup as x-moka-token: <token> (or ?token=). GET /api/health needs no token.

Terminal window
TOKEN=... # from the startup URL
curl -s -H "x-moka-token: $TOKEN" localhost:4000/api/bootstrap | jq .config.llms

POST /api/chat streams NDJSON — one JSON object per line.

Terminal window
curl -N -H "x-moka-token: $TOKEN" -H 'content-type: application/json' \
-d '{"messages":[{"role":"user","content":"What time is it in Tokyo?"}]}' \
localhost:4000/api/chat
Body field
messagesAI SDK ModelMessage[] — the full history
workspaceIdOptional; defaults to the active workspace
llmIdOptional; override the workspace’s model
agentIdOptional; talk to this remote agent instead
forkOfOptional; time-travel: {step, edit, tool?, label?, runId?} labels this run as a fork in the inspector. If messages ends with tool calls that have no results, Moka runs them first

File parts the model can’t take (a PDF for an OpenAI-compatible model, a Word file for any model) are replaced by text before the request: the part’s providerOptions.moka.text if it has one, otherwise a note that the model can’t read the file. The web UI puts the text it read from PDFs and Word files there.

Chunk typeFields
startrunId, model, profileId, tools (count)
text / reasoningtext (delta)
tool-callid, name, tool, source, serverId (MCP tools), input
tool-resultid, output, isError, durationMs, ui?, raw?, edited? (arguments or result, changed at a breakpoint), input? (the arguments it ran with)
stepusage, finishReason
finishusage, durationMs, messages — append these to your history for the next turn; with replacesLast, the first one replaces the last message you sent (a fork’s tool results)
errormessage

ui is one of {kind:"mcp-app", serverId, resourceUri}, {kind:"mcp-ui", …} or {kind:"a2ui", messages}.

Method & pathDescription
GET /api/health{ ok, version }
GET /api/bootstrapConfig, provider presets, detected env keys, MCP states, skills
PUT /api/configReplace the whole config (validated; 400 with details if invalid)
GET /api/config/export?redact=1Config with secrets redacted
POST /api/export{target: "ai-sdk"|"langgraph"|"mcp-json"|"moka", workspaceId} → {code}
POST /api/llm/test{profile} → {ok, latencyMs, text?, error?}
POST /api/llm/models{profile} → {models, error?}
GET /api/mcpAll server states. HTTP/SSE servers include http: the last request with masked headers
POST /api/mcp/test{server} → connect a draft config and report capabilities
POST /api/mcp/import{json} → parsed servers from Claude/Cursor/VS Code JSON
POST /api/mcp/:id/connect{force?} → connect or reconnect
POST /api/mcp/:id/disconnect
POST /api/mcp/:id/call{tool, args} → {result, durationMs}
POST /api/mcp/:id/resource{uri} → resources/read result
POST /api/mcp/:id/subscribe{uri, subscribe?: false} → {subscriptions}: subscribe to (or unsubscribe from) resource updates
POST /api/mcp/:id/signoutForget OAuth tokens and reconnect
POST /api/improve{llmIds, workspaceId?, runs?, toolMode?, improverId?, proposals?, baseline?} → NDJSON stream of Improve events (start, phase, result, diagnosis, holdout, proposals, verdict, done, error)
GET /api/improve/improver{improverId}: the model Improve would pick to write proposals
POST /api/improve/code{changes, workspaceId?, before?, after?} → {ts, python, markdown}
GET /api/studioStudio servers (projects with serverId, name, dir, files), templates, and whether this Node runs TypeScript
GET /api/studio/file?dir=&path= · PUT /api/studio/fileRead or save a file of a Studio server ({dir, path, content}); saving restarts it
POST /api/studio/create{name, template?, dir?} → {serverId, dir}: a new server from a template, added to the active workspace
POST /api/studio/open{dir, name?} → {serverId, dir}: add a folder with a server.ts
GET /api/studio/export?dir=The server as a .zip with package.json, tsconfig.json and a README
GET /api/recordings{dir, recordings: [{server, name, file, size, at}]}
DELETE /api/recordings?file=Delete a recording
GET /oauth/callbackOAuth redirect target (no token needed)
POST /api/agents/test{agent} → {ok, latencyMs, card?, events?, text?, error?}
POST /api/mcp/:id/prompt{name, args} → prompts/get result
POST /api/skills/preview{skill} → loaded skill (body, files, errors)
POST /api/skills/discover{path} → skill folders under a path
GET /api/catalogsThe standard catalog plus every configured catalog (loaded)
POST /api/catalogs/preview{catalog} → load a draft catalog config and report errors
GET /api/ui/tool?workspaceId=The render tool a workspace sends: name, description, inputSchema, components
POST /api/ui/preview{input, workspaceId} → {messages, problems} (validated and expanded A2UI), or {component: {catalogId, name}} for a component preview
POST /api/ui/generate{prompt, workspaceId?, llmId?} → ask a model for UI with only the render tool
GET /api/interactionsPending approvals / elicitation / sampling requests
POST /api/interactions/:id{response}: {approved, remember?: "session"|"always"} for approvals and sampling, {action: "accept"|"decline"|"cancel", content?} for elicitation
GET /api/eventsNDJSON stream: buffered history, then live events (15 s heartbeats)
POST /api/events/uiReport ui.rpc / ui.action events
DELETE /api/eventsClear the buffer
GET /api/sessions · GET/PUT/DELETE /api/sessions/:idChat history
GET /api/budget?workspaceId={total, items, notConnected}: estimated tokens the model reads before every message (system prompt, skills, instructions, each tool)
GET /api/security?workspaceId={servers}: the security check of each connected server: findings and changes
POST /api/security/:id/trustTrust a server’s tools as they are now
POST /api/tests/run{llmIds, workspaceId?, runs?, toolMode?: "run"|"read-only"|"none", testIds?} → NDJSON stream of test results
POST /api/tests/suggest{workspaceId?, count?} → {tests} proposed by the workspace’s model
GET /api/local-models{ollama, lmstudio}: models of local servers running now