Function: error()
ts
function error(message, code?): ToolResponse;Defined in: packages/core/src/core/response.ts:161
Create an error response.
Sets isError: true so the MCP client and LLM recognize the failure. The LLM will typically retry or ask the user for clarification.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | string | Human-readable error description |
code? | ErrorCode | - |
Returns
A ToolResponse with isError: true
Example
typescript
// Simple error
return error('Project not found');
// Contextual error
return error(`User "${userId}" does not have access to workspace "${wsId}"`);
// In a handler with early return
handler: async (ctx, args) => {
const project = await ctx.db.projects.findUnique(args.id);
if (!project) return error(`Project "${args.id}" not found`);
return success(project);
}