Skip to main content
Glama

create_element

Add shapes, text, or drawings to an Excalidraw diagram by specifying type, position, and properties like color and size.

Instructions

Create a single Excalidraw element on the canvas

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYes
xYes
yYes
widthNo
heightNo
pointsNo
backgroundColorNo
strokeColorNo
strokeWidthNo
roughnessNo
opacityNo
textNo
fontSizeNo
fontFamilyNo
groupIdsNo
lockedNo
angleNo

Implementation Reference

  • MCP tool registration and handler for 'create_element'. This is the main entry point that receives the MCP tool request, extracts the arguments (type, x, y, and other properties), calls client.createElement(), and returns the result in MCP protocol format.
    // --- Tool: create_element ---
    server.tool(
      'create_element',
      'Create a single Excalidraw element on the canvas',
      elementFields,
      async ({ type, x, y, ...rest }) => {
        try {
          const element = await client.createElement({ type, x, y, ...rest });
          return { content: [{ type: 'text', text: JSON.stringify(element, null, 2) }] };
        } catch (err) {
          return { content: [{ type: 'text', text: `Error: ${(err as Error).message}` }], isError: true };
        }
      }
    );
  • CanvasClient.createElement() method that makes an HTTP POST request to the canvas server's /api/elements endpoint. Handles error responses and returns the created ServerElement.
    async createElement(data: Record<string, unknown>): Promise<ServerElement> {
      const res = await fetch(`${this.baseUrl}/api/elements`, {
        method: 'POST',
        headers: this.headers(),
        body: JSON.stringify(data),
      });
    
      if (!res.ok) {
        const body = await res.json().catch(() => ({})) as ApiResponse;
        throw new Error(body.error ?? `Canvas error: ${res.status}`);
      }
    
      const body = await res.json() as ApiResponse<ServerElement> & { element?: ServerElement };
      return body.element ?? body.data!;
    }
  • CreateElementSchema - Zod validation schema for element creation inputs. Defines all allowed fields (type, x, y, width, height, colors, stroke, text, etc.) with their constraints and optional flags.
    export const CreateElementSchema = z
      .object({
        type: ElementTypeSchema,
        x: CoordinateSchema,
        y: CoordinateSchema,
        width: DimensionSchema,
        height: DimensionSchema,
        points: z.array(PointSchema).max(LIMITS.MAX_POINTS).optional(),
        backgroundColor: ColorSchema,
        strokeColor: ColorSchema,
        strokeWidth: z
          .number()
          .min(0)
          .max(LIMITS.MAX_STROKE_WIDTH)
          .finite()
          .optional(),
        roughness: z
          .number()
          .min(0)
          .max(LIMITS.MAX_ROUGHNESS)
          .finite()
          .optional(),
        opacity: z
          .number()
          .min(LIMITS.MIN_OPACITY)
          .max(LIMITS.MAX_OPACITY)
          .finite()
          .optional(),
        text: z.string().max(LIMITS.MAX_TEXT_LENGTH).optional(),
        fontSize: z.number().min(1).max(LIMITS.MAX_FONT_SIZE).finite().optional(),
        fontFamily: z.number().int().min(1).max(4).optional(),
        groupIds: z
          .array(z.string().max(LIMITS.MAX_GROUP_ID_LENGTH))
          .max(LIMITS.MAX_GROUP_IDS)
          .optional(),
        locked: z.boolean().optional(),
        angle: z.number().min(-360).max(360).finite().optional(),
      })
      .strict();
  • CanvasClientAdapter.createElement() - Alternative implementation for standalone mode (when canvas server is unavailable). Creates elements directly in the in-memory StandaloneStore without making HTTP requests.
    async createElement(data: Record<string, unknown>): Promise<ServerElement> {
      const now = new Date().toISOString();
      const element: ServerElement = {
        id: generateId(),
        type: data.type as ServerElement['type'],
        x: data.x as number,
        y: data.y as number,
        ...(data.width !== undefined && { width: data.width as number }),
        ...(data.height !== undefined && { height: data.height as number }),
        ...(data.points !== undefined && { points: data.points as ServerElement['points'] }),
        ...(data.backgroundColor !== undefined && { backgroundColor: data.backgroundColor as string }),
        ...(data.strokeColor !== undefined && { strokeColor: data.strokeColor as string }),
        ...(data.strokeWidth !== undefined && { strokeWidth: data.strokeWidth as number }),
        ...(data.roughness !== undefined && { roughness: data.roughness as number }),
        ...(data.opacity !== undefined && { opacity: data.opacity as number }),
        ...(data.text !== undefined && { text: data.text as string }),
        ...(data.fontSize !== undefined && { fontSize: data.fontSize as number }),
        ...(data.fontFamily !== undefined && { fontFamily: data.fontFamily as number }),
        ...(data.groupIds !== undefined && { groupIds: data.groupIds as string[] }),
        ...(data.locked !== undefined && { locked: data.locked as boolean }),
        ...(data.angle !== undefined && { angle: data.angle as number }),
        ...(data.fillStyle !== undefined && { fillStyle: data.fillStyle as string }),
        ...(data.strokeStyle !== undefined && { strokeStyle: data.strokeStyle as string }),
        createdAt: now,
        updatedAt: now,
        version: 1,
        source: 'standalone',
      };
    
      await this.store.set(element.id, element);
      logger.debug({ id: element.id, type: element.type }, 'Element created');
      return element;
    }
  • Express.js route handler for POST /api/elements - the server-side implementation that validates input, generates an ID and timestamps, stores the element, and broadcasts the creation via WebSocket.
    router.post('/', async (req, res) => {
      try {
        const result = CreateBodySchema.safeParse(req.body);
        if (!result.success) {
          res.status(400).json({
            success: false,
            error: 'Validation failed',
            details: result.error.issues,
          });
          return;
        }
    
        const now = new Date().toISOString();
        const id = generateId();
        const element: ServerElement = {
          ...result.data,
          id,
          createdAt: now,
          updatedAt: now,
          version: 1,
          source: 'api',
        };
    
        await store.set(id, element);
    
        ws.broadcast({
          type: 'element_created',
          element: element as unknown as Record<string, unknown>,
        });
    
        res.status(201).json({ success: true, element });
      } catch (err) {
        const message = err instanceof Error ? err.message : 'Internal server error';
        logger.error({ err }, 'Failed to create element');
        res.status(message.includes('Maximum element count') ? 409 : 500).json({
          success: false,
          error: message,
        });
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Create' implies a write/mutation operation, but the description doesn't disclose any behavioral traits: no information about permissions needed, whether creation is reversible (can elements be deleted?), what happens on failure, or any side effects. For a mutation tool with 17 parameters and no annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just 7 words, with zero wasted language. It's front-loaded with the core action ('Create') and resource ('Excalidraw element'), making it immediately understandable. Every word earns its place in this minimal description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex creation tool with 17 parameters, no annotations, no output schema, and 0% schema description coverage, the description is completely inadequate. It doesn't explain what gets created, how parameters interact, what the tool returns, or any behavioral characteristics. The agent would struggle to use this tool correctly without significant trial and error.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for 17 parameters, the description provides no parameter information whatsoever. It doesn't explain what 'type', 'x', 'y', or any other parameters mean, nor does it clarify which parameters are required vs. optional. The description doesn't compensate for the complete lack of schema documentation, leaving the agent with no semantic understanding of the parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'create' and the resource 'a single Excalidraw element on the canvas', which is specific and unambiguous. It distinguishes this from batch operations (vs. batch_create_elements) and from other creation methods (vs. create_from_mermaid). However, it doesn't explicitly differentiate from update_element or create_view, which would be needed for a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose create_element over batch_create_elements for multiple elements, or when to use update_element instead for modifications. There's no context about prerequisites, dependencies, or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/debu-sinha/excalidraw-mcp-server'

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