Skip to main content
Mastra 1.0 is available 🎉 Read announcement

Server Routes

Server adapters register these routes when you call server.init(). All routes are prefixed with the prefix option if configured.

Agents
Direct link to Agents

MethodPathDescription
GET/api/agentsList all agents
GET/api/agents/:agentIdGet agent by ID
POST/api/agents/:agentId/generateGenerate agent response
POST/api/agents/:agentId/streamStream agent response
GET/api/agents/:agentId/toolsList agent tools
POST/api/agents/:agentId/tools/:toolId/executeExecute agent tool

Generate request body
Direct link to Generate request body

{
messages: CoreMessage[] | string; // Required
instructions?: string; // System instructions
system?: string; // System prompt
context?: CoreMessage[]; // Additional context
memory?: { key: string } | boolean; // Memory config
resourceId?: string; // Resource identifier
threadId?: string; // Thread identifier
runId?: string; // Run identifier
maxSteps?: number; // Max tool steps
activeTools?: string[]; // Tools to enable
toolChoice?: ToolChoice; // Tool selection mode
requestContext?: Record<string, unknown>; // Request context
output?: ZodSchema; // Structured output schema
}

Generate response
Direct link to Generate response

{
text: string;
toolCalls?: ToolCall[];
finishReason: string;
usage?: {
promptTokens: number;
completionTokens: number;
};
}

Workflows
Direct link to Workflows

MethodPathDescription
GET/api/workflowsList all workflows
GET/api/workflows/:workflowIdGet workflow by ID
POST/api/workflows/:workflowId/create-runCreate a new workflow run
POST/api/workflows/:workflowId/start-asyncStart workflow and await result
POST/api/workflows/:workflowId/streamStream workflow execution
POST/api/workflows/:workflowId/resumeResume suspended workflow
POST/api/workflows/:workflowId/resume-asyncResume asynchronously
GET/api/workflows/:workflowId/runsList workflow runs
GET/api/workflows/:workflowId/runs/:runIdGet specific run

Create run request body
Direct link to Create run request body

{
resourceId?: string; // Associate run with a resource (e.g., user ID)
disableScorers?: boolean; // Disable scorers for this run
}

Start-async request body
Direct link to Start-async request body

{
resourceId?: string; // Associate run with a resource (e.g., user ID)
inputData?: unknown;
initialState?: unknown;
requestContext?: Record<string, unknown>;
tracingOptions?: {
spanName?: string;
attributes?: Record<string, unknown>;
};
}

Stream workflow request body
Direct link to Stream workflow request body

{
resourceId?: string; // Associate run with a resource (e.g., user ID)
inputData?: unknown;
initialState?: unknown;
requestContext?: Record<string, unknown>;
closeOnSuspend?: boolean;
}

Resume request body
Direct link to Resume request body

{
step?: string | string[];
resumeData?: unknown;
requestContext?: Record<string, unknown>;
}

Tools
Direct link to Tools

MethodPathDescription
GET/api/toolsList all tools
GET/api/tools/:toolIdGet tool by ID
POST/api/tools/:toolId/executeExecute tool

Execute tool request body
Direct link to Execute tool request body

{
data: unknown; // Tool input data
requestContext?: Record<string, unknown>;
}

Memory
Direct link to Memory

MethodPathDescription
GET/api/memory/threadsList threads
GET/api/memory/threads/:threadIdGet thread
POST/api/memory/threadsCreate thread
DELETE/api/memory/threads/:threadIdDelete thread
POST/api/memory/threads/:threadId/cloneClone thread
GET/api/memory/threads/:threadId/messagesGet thread messages
POST/api/memory/threads/:threadId/messagesAdd message

Create thread request body
Direct link to Create thread request body

{
resourceId: string;
title?: string;
metadata?: Record<string, unknown>;
}

Clone thread request body
Direct link to Clone thread request body

{
newThreadId?: string; // Custom ID for cloned thread
resourceId?: string; // Override resource ID
title?: string; // Custom title for clone
metadata?: Record<string, unknown>; // Additional metadata
options?: {
messageLimit?: number; // Max messages to clone
messageFilter?: {
startDate?: Date; // Clone messages after this date
endDate?: Date; // Clone messages before this date
messageIds?: string[]; // Clone specific messages
};
};
}

Clone thread response
Direct link to Clone thread response

{
thread: {
id: string;
resourceId: string;
title: string;
createdAt: Date;
updatedAt: Date;
metadata: {
clone: {
sourceThreadId: string;
clonedAt: Date;
lastMessageId?: string;
};
// ... other metadata
};
};
clonedMessages: MastraDBMessage[];
}

Vectors
Direct link to Vectors

MethodPathDescription
POST/api/vectors/:vectorName/upsertUpsert vectors
POST/api/vectors/:vectorName/queryQuery vectors
POST/api/vectors/:vectorName/deleteDelete vectors

Upsert request body
Direct link to Upsert request body

{
vectors: Array<{
id: string;
values: number[];
metadata?: Record<string, unknown>;
}>;
}

Query request body
Direct link to Query request body

{
vector: number[];
topK?: number;
filter?: Record<string, unknown>;
includeMetadata?: boolean;
}

MCP
Direct link to MCP

MethodPathDescription
GET/api/mcp/serversList MCP servers
GET/api/mcp/servers/:serverId/toolsList server tools
POST/api/mcp/:serverIdMCP HTTP transport
GET/api/mcp/:serverId/sseMCP SSE transport

Logs
Direct link to Logs

MethodPathDescription
GET/api/logsList logs
GET/api/logs/:runIdGet logs by run ID

Query parameters
Direct link to Query parameters

{
page?: number;
perPage?: number;
transportId?: string;
}

Telemetry
Direct link to Telemetry

MethodPathDescription
GET/api/telemetry/tracesList traces
GET/api/telemetry/traces/:traceIdGet trace
GET/api/telemetry/traces/:traceId/spansGet trace spans

Common query parameters
Direct link to Common query parameters

Pagination
Direct link to Pagination

Most list endpoints support:

{
page?: number; // Page number (0-indexed)
perPage?: number; // Items per page (default: 10)
}

Filtering
Direct link to Filtering

Workflow runs support:

{
fromDate?: string; // ISO date string
toDate?: string; // ISO date string
status?: string; // Run status filter
resourceId?: string; // Filter by resource
}

Error responses
Direct link to Error responses

All routes return errors in this format:

{
error: string; // Error message
details?: unknown; // Additional details
}

Common status codes:

CodeMeaning
400Bad Request - Invalid parameters
401Unauthorized - Missing/invalid auth
403Forbidden - Insufficient permissions
404Not Found - Resource doesn't exist
500Internal Server Error