mastra-ai/mastra · error · MastraError
MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS
MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS
Error message
Invalid options for route "${path}", missing "method" property What it means
Mastra validates every API route registered via registerApiRoute before mounting it on the Hono server. This error is thrown when the route options object omits the required 'method' property, which tells the server which HTTP verb the route handles. It fails fast at registration time so misconfigured routes never reach the running server.
Solutions
- Add a 'method' property to the route options with a valid HTTP verb (e.g. method: 'GET').
- If routes come from external config, validate/transform the config into RegisterApiRouteOptions before calling registerApiRoute.
- Check for typos such as 'methods' or 'httpMethod' instead of 'method'.
Example fix
// before
registerApiRoute('/users', {
handler: async (c) => c.json({ ok: true }),
});
// after
registerApiRoute('/users', {
method: 'GET',
handler: async (c) => c.json({ ok: true }),
}); Defensive patterns
Strategy: validation
Validate before calling
function assertRouteHasMethod(path, options) {
if (options == null || options.method === undefined) {
throw new TypeError(`Route "${path}" is missing required "method" property`);
}
}
// call before registerApiRoute(path, options) Type guard
function hasMethod(o) {
return typeof o === 'object' && o !== null && 'method' in o && typeof o.method === 'string';
} Try / catch
try {
registerApiRoute(path, options);
} catch (e) {
if (String(e?.message).includes('missing "method" property')) {
console.error(`Route ${path} config invalid: add a method`);
} else throw e;
} Prevention
- Type route configs as RegisterApiRouteOptions so TypeScript flags a missing method at compile time.
- Never build route options as untyped plain objects from JSON configs without a validation step.
- Define a factory helper that always fills in method with a default (e.g. 'GET').
When it happens
Trigger: Calling registerApiRoute(path, {...}) with an options object that lacks a 'method' field entirely — e.g. registerApiRoute('/my-route', { handler: async (c) => c.json({}) }).
Common situations: Hand-writing route configs instead of using the typed RegisterApiRouteOptions helper; building routes dynamically from a plain object (e.g. from JSON config) where the method key was never set; refactoring away from an older route definition style that inferred the method elsewhere.
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- AGENT_FS_ROUTING_SUBAGENT_DESCRIPTION_REQUIRED
- Cannot delete the active version. Activate a different…
- Cannot set both `model` and `observation.model`. Use…
- Cannot set both `model` and `reflection.model`. Use `model`…
- conversation_id and previous_response_id must reference the…
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/b44bd4ceffdfda15.
Report an issue: GitHub.
Appendix: source
Thrown at packages/core/src/server/index.ts:98
*/
cors?: CorsOptions;
/**
* When false, skips Mastra auth for this route (defaults to true)
*/
requiresAuth?: boolean;
/**
* Explicit RBAC permission for the route.
*/
requiresPermission?: ApiRoute['requiresPermission'];
/**
* Optional FGA configuration for resource-level authorization.
*/
fga?: ApiRoute['fga'];
};
function validateOptions<P extends string>(path: P, options: RegisterApiRouteOptions<P>): void {
if (options.method === undefined) {
throw new MastraError({
id: 'MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS',
text: `Invalid options for route "${path}", missing "method" property`,
domain: ErrorDomain.MASTRA_SERVER,
category: ErrorCategory.USER,
});
}
if (options.handler === undefined && options.createHandler === undefined) {
throw new MastraError({
id: 'MASTRA_SERVER_API_INVALID_ROUTE_OPTIONS',
text: `Invalid options for route "${path}", you must define a "handler" or "createHandler" property`,
domain: ErrorDomain.MASTRA_SERVER,
category: ErrorCategory.USER,
});
}
if (options.handler !== undefined && options.createHandler !== undefined) {
throw new MastraError({View on GitHub (pinned to 75dd419e61)