Adversarial-review follow-ups to the lingo measurement() field:
- Add a `positive` option (strict > 0) and use it for the non-zero dimension
params. Swapping z.number().positive() → measurement(..,{min:0}) had started
admitting 0 (the core node schemas have no positivity backstop), so a zero-size
wall/opening/roof could be created. Inclusive-0 fields (overhang, sill height,
knee-wall height, opening offset, roof pitch) keep min:0.
- Escalate AMBIGUOUS_NUMBER to error so "1,234" fails instead of silently reading
as 1234 — a 1000x hazard for European decimals. Matches lingo's own /ai fields.
- roofLevelElevation reverted to z.number() (it's a level ordinal, not meters);
radians fields now advertise radian-appropriate examples.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
75 lines
2.5 KiB
TypeScript
75 lines
2.5 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 { SceneOperations } from '../operations'
|
|
import { ErrorCode, throwMcpError } from './errors'
|
|
import { publishLiveSceneSnapshot } from './live-sync'
|
|
import { measurement } from './measurement'
|
|
import { NodeIdSchema, Vec2Schema } from './schemas'
|
|
|
|
export const createWallInput = {
|
|
levelId: NodeIdSchema,
|
|
start: Vec2Schema,
|
|
end: Vec2Schema,
|
|
thickness: measurement('length', 'm', {
|
|
positive: true,
|
|
description: 'Wall thickness.',
|
|
}).optional(),
|
|
height: measurement('length', 'm', { positive: true, description: 'Wall height.' }).optional(),
|
|
}
|
|
|
|
export const createWallOutput = {
|
|
wallId: z.string(),
|
|
}
|
|
|
|
export function registerCreateWall(server: McpServer, bridge: SceneOperations): 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`,
|
|
)
|
|
}
|
|
if (
|
|
typeof parent.metadata === 'object' &&
|
|
parent.metadata !== null &&
|
|
'role' in parent.metadata &&
|
|
parent.metadata.role === 'roof'
|
|
) {
|
|
throwMcpError(
|
|
ErrorCode.InvalidParams,
|
|
`Roof support level ${levelId} is not an occupied story; create walls on an occupied level instead`,
|
|
)
|
|
}
|
|
|
|
const wall = WallNode.parse({
|
|
start: start as [number, number],
|
|
end: end as [number, number],
|
|
...(thickness !== undefined ? { thickness } : {}),
|
|
...(height !== undefined ? { height } : {}),
|
|
})
|
|
const id = bridge.createNode(wall, levelId as AnyNodeId)
|
|
await publishLiveSceneSnapshot(bridge, 'create_wall')
|
|
const payload = { wallId: id as string }
|
|
return {
|
|
content: [{ type: 'text' as const, text: JSON.stringify(payload) }],
|
|
structuredContent: payload,
|
|
}
|
|
},
|
|
)
|
|
}
|