mastra-cli-api
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Use the mastra CLI to develop, build, start, lint, and migrate a Mastra project, and use mastra api to inspect and call a running server: list and run agents, start and resume workflows, execute tools and MCP tools, manage memory threads, and query traces, spans, logs, metrics, scores, datasets, and experiments on a local, self-hosted, or Mastra Platform target. Use this skill whenever the user wants to run mastra dev, check what a server exposes, call an agent from the terminal, find failing tool calls or slow traces, compute error rates or token cost per agent, or script Mastra checks in CI. Triggers on mastra dev, mastra build, mastra start, mastra studio, mastra lint, mastra migrate, mastra worker, mastra api, agent run, workflow run start, tool execute, trace query, trace aggregate, span query, metric aggregate, --schema, localhost:4111, swagger-ui. Also triggers when the user asks why an agent failed in production and traces are the evidence.
- Reads credentials
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-deploymentSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Run the Mastra project lifecycle from the terminal, and call or inspect any running Mastra server with compact, JSON-in, JSON-out commands.
- Very specific: line 48
Never request secret values in chat.
- Very specific: line 92
Verify the API: Run mastra --version, mastra api --help, and mastra api <resource> <action> --help.
- Very specific: line 94
Read before you write: Use list and get with small pages (perPage 1 to 10) and project with jq immediately.
- Very specific: line 95
Get the input shape: Run the leaf command with --schema before any mutating call (agent run, workflow run start, tool execute, thread …
- Very specific: line 131
MISSING_INPUTorMISSING_ARGUMENT: Run the same command with --schema or --help and supply the field or positional. - Very specific: line 132
HTTP_ERROR401 on a custom server: Add --header "Authorization: Bearer $TOKEN". - Distinctive: line 134
Passing a file path or stdin: Not supported. Inline the JSON.
- Very specific: line 138
--schemaagainst Mastra Platform observability: Not exposed there. Use the canonical query reference.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra CLI and mastra api
Run the Mastra project lifecycle from the terminal, and call or inspect any running Mastra server with compact, JSON-in, JSON-out commands.
When to use
- Starting the dev server and Studio, building, and serving the build
- Linting a project or running deploy preflight checks
- Running storage migrations after an upgrade (
mastra migrate) - Listing or calling agents, workflows, tools, and MCP tools on a running server
- Reading memory threads and working memory
- Finding traces or spans by condition, and aggregating error rate, latency, tokens, or cost
- Reading logs, metrics, scores, datasets, and experiments
- Scripting smoke tests against a deployment in CI
When NOT to use
- Creating a new project from scratch (use
mastra-project-setup) - Deploying to Mastra Platform, environments, databases, tokens (use
mastra-platform) - Hosting on other clouds and Docker (use
mastra-deployment) - Calling a server from application code with
MastraClient(usemastra-client-sdk) - Configuring tracing exporters and span processors (use
mastra-observability) - Building datasets and experiments in code (use
mastra-datasets-experiments) - Diagnosing a specific error message (use
mastra-troubleshooting)
Required inputs
- The target: local dev server, a deployed URL, or a Mastra Platform project (
.mastra-project.json) - Authentication for that target: none (localhost), a bearer token header, or platform credentials
- The resource and action (for example
agent run,trace query) - For observability queries: a time range that holds the data, and the region (US or EU)
Never request secret values in chat. For custom servers, the user sets up auth outside the conversation and passes it through an env var in --header.
The framework: lifecycle commands and one API client
Lifecycle
| Command | What it does |
mastra dev | Dev server and Studio on http://localhost:4111; Swagger at /swagger-ui |
mastra build [--studio] | Bundle to .mastra/output |
mastra start | Serve the build; loads .env.production and .env |
mastra studio | Standalone Studio on port 3000 pointing at a server |
mastra lint [--preflight] | Project checks; --preflight runs deploy checks on the build |
mastra migrate | Storage schema migrations |
mastra worker build / worker start <name> | Worker bundle and processes |
mastra init, mastra create | Add Mastra to a project, or create one |
mastra scorers add / list | Scorer templates |
mastra traces import langfuse | Import Langfuse traces into a platform project |
mastra api
One inline JSON argument in, JSON out. Success goes to stdout as { "data": ... } (lists add page). Errors go to stderr as { "error": { code, message, details } } with a non-zero exit code.
mastra api agent list
mastra api agent run weather-agent '{"messages":"What is the weather in London?"}'
mastra api tool execute get-weather '{"location":"San Francisco"}'
mastra api trace list '{"page":0,"perPage":20}'Target resolution for runtime commands (agent, workflow, tool, mcp, thread, memory, dataset, experiment):
--url <url>http://localhost:4111.mastra-project.json(platform project, automatic credentials)
Observability commands (trace, span, log, score, metric) default to https://observability.mastra.ai with MASTRA_PLATFORM_ACCESS_TOKEN and MASTRA_PROJECT_ID. Pass --url https://observability.eu.mastra.ai for EU data, or --url http://localhost:4111 for a local server.
Workflow
- Verify the API. Run
mastra --version,mastra api --help, andmastra api <resource> <action> --help. Ifnode_modules/@mastra/exists, readnode_modules/@mastra/core/dist/docs/. Otherwise fetchhttps://mastra.ai/reference/cli/mastra.md. Trust these over memory. - Confirm the target. For local, check
curl -fsS http://localhost:4111/api/system/api-schema. For remote, ask for the URL. For EU platform data, use the EU host. - Read before you write. Use
listandgetwith small pages (perPage1 to 10) and project withjqimmediately. - Get the input shape. Run the leaf command with
--schemabefore any mutating call (agent run,workflow run start,tool execute,thread create,score create). - Call. Pass exactly one JSON object. Raise
--timeoutfor long workflow runs (default 30000 ms, workflow start and resume 120000 ms). - Escalate queries only when needed.
trace listfor browsing,trace queryfor predicates,trace aggregatefor counts and measures,span queryandspan aggregatefor nested spans. - Drill into evidence.
trace get <traceId>for the timeline,trace span <traceId> <spanId>for one full span. - Report. Summarize the projected fields, not raw JSON. Treat empty lists as "no stored data yet", not as an error.
Deep dive: querying traces and spans
trace query and span query take a required timeRange (from inclusive, to exclusive, ISO strings) and an optional recursive where predicate.
npx mastra api trace query \
'{"timeRange":{"from":"2026-08-01T00:00:00.000Z","to":"2026-08-08T00:00:00.000Z"},"where":{"spans":{"some":{"op":"and","args":[{"op":"eq","left":{"path":"spanType"},"right":{"literal":"tool_call"}},{"op":"exists","path":"error"}]}}},"page":{"limit":25}}' \
| jq '{traces: [.data.traces[] | {traceId, entityName, status, startedAt}], next: .data.page.next}'Rules that prevent wrong answers:
- Conditions that must hold on the same span go in one
spans.someclause. span queryfilters span fields directly. Do not wrap its predicates inspans.some.- Pass
data.page.nextback unchanged aspage.afterwith the identical query. Changing the query returns409. - Aggregations are not paginated. When
truncatedistrue, narrow the selection. - Tokens and cost sit on the span that recorded them (usually
model_generation). Usetrace aggregatefor per-trace totals. - Report a
nullcost as unknown, not zero. 501means the store does not support the operation. Report it instead of approximating client-side.
See references/trace-query.md for fields, operators, measures, and limits.
Failure patterns
SERVER_UNREACHABLE. Nothing onlocalhost:4111. Startmastra devor pass--url.INVALID_JSON. Shell quoting broke the JSON. Wrap it in single quotes; input is one object.MISSING_INPUTorMISSING_ARGUMENT. Run the same command with--schemaor--helpand supply the field or positional.HTTP_ERROR401 on a custom server. Add--header "Authorization: Bearer $TOKEN". Localhost and arbitrary URLs get no automatic credentials.REQUEST_TIMEOUTon workflows. Raise--timeout. For EU projects on old CLIs, pass the EU--url.- Passing a file path or stdin. Not supported. Inline the JSON.
- Using
mastra api agent generate. The command isagent run. workflow run resumefails. The run is not suspended. Checkworkflow run getfirst.memory current updatefails. Working memory is not enabled on the agent's memory.--schemaagainst Mastra Platform observability. Not exposed there. Use the canonical query reference.- Huge output. Unfiltered
--prettyor--verbose. Project withjqand keep pages small. mastra dev --port. Removed. Setserver.porton the Mastra instance.mastra devexits with a duplicate server error.mastra factory devor another dev server holds the lock.
Output format
A finished CLI task delivers:
- The exact commands run, with the target (
--url) and no secret values - Compact results: projected fields, counts, and IDs for follow-up (
traceId,runId) - For queries: the time range, predicate, and whether results were truncated or paginated
- For scripts: a shell or CI step that checks the exit code and parses
.data
Reference files
references/api.md- Every CLI command and flag,mastra apiresources, actions, flags, and error codes.references/trace-query.md- Trace and span query fields, operators, measures, pagination, and limits.references/examples.md- Smoke test a deployment, run a workflow, find failing tools, error rate per agent, metrics.references/checklist.md- Checklist for safe, compact CLI usage.
Live docs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

