Files
editor/packages/mcp/src/tools/errors.ts
T
Adrian PerezandClaude Opus 4.7 58ad89e80b feat(mcp): implement 19 scene query and mutation tools
Scene querying: get_scene, get_node, describe_node, find_nodes, measure.
Scene mutation (undoable, atomic): apply_patch, create_level, create_wall,
place_item, cut_opening, set_zone, duplicate_level, delete_node.
Undo/redo: undo, redo.
Export: export_json, export_glb (not_implemented stub).
Validation: validate_scene, check_collisions.

Each tool has:
- Exported Zod input + output schemas
- register<Tool>(server, bridge) wiring function
- Bun test with happy-path + error-path coverage via InMemoryTransport

59 tool tests, all passing end-to-end through MCP protocol.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 17:51:08 +02:00

35 lines
907 B
TypeScript

import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js'
/**
* Throw a structured MCP error. The SDK translates `McpError` into a
* JSON-RPC error response automatically.
*/
export function throwMcpError(code: ErrorCode, message: string, data?: unknown): never {
throw new McpError(code, message, data)
}
/**
* Return a non-throwing tool error payload — used for structured failures that
* we want the client to see inline in `content` rather than as a protocol
* error. Sets `isError: true` so SDK clients treat it as a failure.
*/
export function toolError(
message: string,
data?: Record<string, unknown>,
): {
content: { type: 'text'; text: string }[]
isError: true
} {
return {
content: [
{
type: 'text',
text: JSON.stringify({ error: message, ...(data ?? {}) }),
},
],
isError: true,
}
}
export { ErrorCode, McpError }