Skip to main content
Glama
playcanvas

PlayCanvas Editor MCP Server

Official
by playcanvas

add_components

Attach custom components like audio, camera, collision, or light to a specified entity in PlayCanvas Editor to enhance its functionality and behavior in real-time 3D applications.

Instructions

Add components to an entity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentsYesA dictionary that contains the components of the entity and their data.
idYesAn entity ID.

Implementation Reference

  • WebSocket server handler implementing the add components logic: retrieves entity, adds each component using entity.addComponent(name, data), logs, and returns updated entity JSON.
    wsc.method('entities:components:add', (id, components) => { const entity = api.entities.get(id); if (!entity) { return { error: 'Entity not found' }; } Object.entries(components).forEach(([name, data]) => { entity.addComponent(name, data); }); log(`Added components(${Object.keys(components).join(', ')}) to entity(${id})`); return { data: entity.json() }; });
  • MCP tool registration for 'add_components', defining input schema and proxy handler to WebSocket 'entities:components:add'.
    mcp.tool( 'add_components', 'Add components to an entity', { id: EntityIdSchema, components: ComponentsSchema }, ({ id, components }) => { return wss.call('entities:components:add', id, components); } );
  • Zod schema defining the structure of components (audiolistener, camera, etc.) that can be added to an entity.
    export const ComponentsSchema = z.object({ audiolistener: AudioListenerSchema.optional(), camera: CameraSchema.optional(), collision: CollisionSchema.optional(), element: ElementSchema.optional(), light: LightSchema.optional(), render: RenderSchema.optional(), rigidbody: RigidBodySchema.optional(), screen: ScreenSchema.optional(), script: ScriptSchema.optional(), sound: SoundSchema.optional() }).describe('A dictionary that contains the components of the entity and their data.');
  • Zod schema for the entity ID parameter, validating as UUID string.
    export const EntityIdSchema = z.string().uuid().describe('An entity ID.');

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/playcanvas/editor-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server