create_style
Define visual representation rules for mathematical diagrams by specifying canvas dimensions and styling rules with selectors, properties, and constraints.
Instructions
Define visual representation rules
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"canvas": "<canvas>",
"rules": "<rules>"
},
"name": "create_style"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| canvas | Yes | ||
| rules | Yes |
Implementation Reference
- src/index.ts:411-460 (handler)The main handler logic for the 'create_style' tool. It validates the input arguments (canvas with width/height and array of rules), constructs a Style object with validated rules, generates a unique ID, stores it in the global 'styles' Map, and returns a success message with the ID.
case "create_style": { const args = request.params.arguments; if (!args || typeof args !== 'object') { throw new Error('Invalid arguments'); } const { canvas, rules } = args as { canvas?: { width?: number; height?: number }; rules?: Array<any>; }; if (!canvas || typeof canvas.width !== 'number' || typeof canvas.height !== 'number') { throw new Error('Invalid style definition: requires canvas with width and height'); } if (!Array.isArray(rules)) { throw new Error('Invalid style definition: requires rules array'); } // Validate rules const validatedRules: Array<StyleRule> = rules.map(rule => { if (!rule.selector || typeof rule.selector !== 'string' || !rule.properties || typeof rule.properties !== 'object' || !Array.isArray(rule.constraints)) { throw new Error('Invalid rule: requires selector, properties object, and constraints array'); } return { selector: rule.selector, properties: rule.properties, constraints: rule.constraints.map((c: any) => String(c)) }; }); const style: Style = { canvas: { width: canvas.width, height: canvas.height }, rules: validatedRules }; const id = `style_${styles.size + 1}`; styles.set(id, style); return { content: [{ type: "text", text: `Created style: ${id}` }] }; } - src/index.ts:255-287 (registration)The tool registration entry in the listTools response, including the name, description, and detailed inputSchema for validation.
{ name: "create_style", description: "Define visual representation rules", inputSchema: { type: "object", properties: { canvas: { type: "object", properties: { width: { type: "number" }, height: { type: "number" } }, required: ["width", "height"] }, rules: { type: "array", items: { type: "object", properties: { selector: { type: "string" }, properties: { type: "object" }, constraints: { type: "array", items: { type: "string" } } }, required: ["selector", "properties", "constraints"] } } }, required: ["canvas", "rules"] } }, - src/index.ts:258-286 (schema)The input schema definition for the 'create_style' tool, specifying the structure for canvas (width, height) and rules array (selector, properties, constraints).
inputSchema: { type: "object", properties: { canvas: { type: "object", properties: { width: { type: "number" }, height: { type: "number" } }, required: ["width", "height"] }, rules: { type: "array", items: { type: "object", properties: { selector: { type: "string" }, properties: { type: "object" }, constraints: { type: "array", items: { type: "string" } } }, required: ["selector", "properties", "constraints"] } } }, required: ["canvas", "rules"] }