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>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
import type { AnyNodeId } from '@pascal-app/core/schema'
|
|
import { WallNode } from '@pascal-app/core/schema'
|
|
import { z } from 'zod'
|
|
import type { SceneBridge } from '../bridge/scene-bridge'
|
|
import { ErrorCode, throwMcpError } from './errors'
|
|
import { NodeIdSchema, Vec2Schema } from './schemas'
|
|
|
|
export const createWallInput = {
|
|
levelId: NodeIdSchema,
|
|
start: Vec2Schema,
|
|
end: Vec2Schema,
|
|
thickness: z.number().positive().optional(),
|
|
height: z.number().positive().optional(),
|
|
}
|
|
|
|
export const createWallOutput = {
|
|
wallId: z.string(),
|
|
}
|
|
|
|
export function registerCreateWall(server: McpServer, bridge: SceneBridge): void {
|
|
server.registerTool(
|
|
'create_wall',
|
|
{
|
|
title: 'Create wall',
|
|
description:
|
|
'Create a new wall on the given level between two 2D points. Thickness and height default to the core library defaults when omitted.',
|
|
inputSchema: createWallInput,
|
|
outputSchema: createWallOutput,
|
|
},
|
|
async ({ levelId, start, end, thickness, height }) => {
|
|
const parent = bridge.getNode(levelId as AnyNodeId)
|
|
if (!parent) {
|
|
throwMcpError(ErrorCode.InvalidParams, `Level not found: ${levelId}`)
|
|
}
|
|
if (parent.type !== 'level') {
|
|
throwMcpError(
|
|
ErrorCode.InvalidParams,
|
|
`Node ${levelId} is a ${parent.type}, expected level`,
|
|
)
|
|
}
|
|
|
|
const wall = WallNode.parse({
|
|
start,
|
|
end,
|
|
...(thickness !== undefined ? { thickness } : {}),
|
|
...(height !== undefined ? { height } : {}),
|
|
})
|
|
const id = bridge.createNode(wall, levelId as AnyNodeId)
|
|
const payload = { wallId: id as string }
|
|
return {
|
|
content: [{ type: 'text' as const, text: JSON.stringify(payload) }],
|
|
structuredContent: payload,
|
|
}
|
|
},
|
|
)
|
|
}
|