ai-chatbot/packages/mcp/src/tools/place-item.ts
Wawa e618175bba Reset core/viewer/editor/mcp packages and apps/editor from private-editor
Wholesale swap of packages/{core,viewer,editor,mcp} and apps/editor with the
versions from the private editor repo, which is the production source of truth.

Setup changes:
- packages/{core,viewer,editor} versions held at 0.7.0 baseline (matching
  the most recent published release) so a bump=minor publishes 0.8.0
- packages/mcp held at 0.1.1 (never published; first publish will go through
  the new release.yml flow)
- peerDependencies and devDependencies for inter-package @pascal-app/*
  references pinned to ^0.7.0 instead of '*' / 'workspace:*' so they are
  valid for npm consumers
- Root package.json: TypeScript bumped to 6.0.2, added overrides for
  @types/react, @types/react-dom, @types/three to prevent JSX namespace
  fragmentation across the workspace
- release.yml extended to also publish editor and mcp; 'both' option renamed
  to 'all'; added a sync step that updates inter-package peerDeps/devDeps to
  match the new versions on every bump (so viewer/editor/mcp tarballs always
  reference the version of core they were built against)
- Root scripts gained release:editor and release:mcp shortcuts

Verification:
- bun install --frozen-lockfile is consistent
- packages/{core,viewer,mcp} build cleanly, dist/index.d.ts emitted
- packages/editor check-types reports 21 pre-existing errors, identical to
  what private-editor currently reports

Open PRs against editor-v2 will need rebasing/conflict resolution.
2026-05-09 20:52:26 +00:00

111 lines
3.8 KiB
TypeScript

import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import type { AnyNodeId } from '@pascal-app/core/schema'
import { ItemNode } from '@pascal-app/core/schema'
import { z } from 'zod'
import type { SceneOperations } from '../operations'
import { findCatalogItem } from './asset-catalog'
import { ErrorCode, throwMcpError } from './errors'
import { projectWorldPointToWallLocalX, wallLength } from './geometry'
import { publishLiveSceneSnapshot } from './live-sync'
import { NodeIdSchema, Vec3Schema } from './schemas'
export const placeItemInput = {
catalogItemId: z.string().min(1),
targetNodeId: NodeIdSchema,
position: Vec3Schema,
rotation: z.number().optional(),
}
export const placeItemOutput = {
itemId: z.string(),
status: z.string().optional(),
}
export function registerPlaceItem(server: McpServer, bridge: SceneOperations): void {
server.registerTool(
'place_item',
{
title: 'Place item',
description:
'Place a catalog item into the scene. Target a level/slab/zone for floor items, a wall for wall-attached items, or a ceiling for ceiling-attached items. Do not target the site node directly.',
inputSchema: placeItemInput,
outputSchema: placeItemOutput,
},
async ({ catalogItemId, targetNodeId, position, rotation }) => {
const target = bridge.getNode(targetNodeId as AnyNodeId)
if (!target) {
throwMcpError(ErrorCode.InvalidParams, `Target node not found: ${targetNodeId}`)
}
const targetType = target.type
if (
targetType !== 'level' &&
targetType !== 'slab' &&
targetType !== 'zone' &&
targetType !== 'wall' &&
targetType !== 'ceiling'
) {
throwMcpError(
ErrorCode.InvalidRequest,
`Cannot place item on ${targetType}; target must be a level, slab, zone, wall, or ceiling. Site-level placement is not supported yet because site.children is reserved for buildings.`,
)
}
const catalogAsset = findCatalogItem(catalogItemId)
const baseAsset = catalogAsset ?? {
id: catalogItemId,
name: catalogItemId,
category: 'unknown',
thumbnail: '',
src: 'asset://placeholder',
dimensions: [0.5, 0.5, 0.5] as [number, number, number],
offset: [0, 0, 0] as [number, number, number],
rotation: [0, 0, 0] as [number, number, number],
scale: [1, 1, 1] as [number, number, number],
}
const requestedPosition = position as [number, number, number]
const parentId =
targetType === 'slab' || targetType === 'zone'
? bridge.resolveLevelId(targetNodeId as AnyNodeId)
: targetNodeId
if (!parentId) {
throwMcpError(
ErrorCode.InvalidParams,
`Could not resolve a level parent for target ${targetNodeId}`,
)
}
const wallExtras: { wallId: string; wallT: number } | Record<string, never> = {}
let itemPosition = requestedPosition
if (targetType === 'wall') {
const localX = projectWorldPointToWallLocalX(target, requestedPosition)
const length = wallLength(target)
itemPosition = [localX, requestedPosition[1], 0]
Object.assign(wallExtras, {
wallId: targetNodeId,
wallT: length === 0 ? 0 : localX / length,
})
}
const item = ItemNode.parse({
position: itemPosition,
rotation: [0, rotation ?? 0, 0],
asset: baseAsset,
...wallExtras,
})
const id = bridge.createNode(item, parentId as AnyNodeId)
await publishLiveSceneSnapshot(bridge, 'place_item')
const payload = {
itemId: id as string,
status: catalogAsset ? 'ok' : 'catalog_unavailable',
}
return {
content: [{ type: 'text' as const, text: JSON.stringify(payload) }],
structuredContent: payload,
}
},
)
}