generate_diagram
Create mathematical diagrams by inputting domain, substance, and style parameters. Penrose MCP Server enables defining types, relationships, and visual rules for clear diagram representation.
Instructions
Generate diagram from domain/substance/style
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | ||
| style | Yes | ||
| substance | Yes | ||
| variation | No |
Implementation Reference
- src/index.ts:462-514 (handler)Handler for generate_diagram tool: validates domain, substance, and style exist, then generates a mock SVG diagram as base64 data URI.case "generate_diagram": { const { domain: domainName, substance: substanceName, style: styleName } = request.params.arguments as { domain: string; substance: string; style: string; }; // Validate all components exist const domain = domains.get(domainName); if (!domain) throw new Error(`Domain ${domainName} not found`); const substance = substances.get(substanceName); if (!substance) throw new Error(`Substance ${substanceName} not found`); const style = styles.get(styleName); if (!style) throw new Error(`Style ${styleName} not found`); // Generate SVG diagram with proper XML declaration and formatting const svg = `<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="${style.canvas.width}" height="${style.canvas.height}" xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect width="100%" height="100%" fill="white"/> <text x="10" y="20" font-family="Arial">Domain: ${domain.name}</text> <text x="10" y="40" font-family="Arial">Substance: ${substanceName}</text> <text x="10" y="60" font-family="Arial">Style: ${styleName}</text> <!-- Set visualization --> <circle cx="150" cy="150" r="50" fill="#e0e0e0" stroke="black"/> <text x="150" y="150" text-anchor="middle" font-family="Arial">A</text> <circle cx="250" cy="150" r="50" fill="#e0e0e0" stroke="black"/> <text x="250" y="150" text-anchor="middle" font-family="Arial">B</text> <!-- Subset relationship --> <defs> <marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto"> <polygon points="0 0, 10 3.5, 0 7" fill="black"/> </marker> </defs> <path d="M 190 150 L 210 150" stroke="black" marker-end="url(#arrowhead)"/> </svg>`; // Convert SVG to base64 with proper data URI format const svgBase64 = `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`; return { content: [{ type: "text", text: svgBase64 }] }; }
- src/index.ts:288-301 (registration)Registration of generate_diagram tool in ListToolsRequestSchema handler, including input schema definition.{ name: "generate_diagram", description: "Generate diagram from domain/substance/style", inputSchema: { type: "object", properties: { domain: { type: "string" }, substance: { type: "string" }, style: { type: "string" }, variation: { type: "string" } }, required: ["domain", "substance", "style"] } }
- src/index.ts:291-300 (schema)Input schema for generate_diagram tool defining required domain, substance, style parameters.inputSchema: { type: "object", properties: { domain: { type: "string" }, substance: { type: "string" }, style: { type: "string" }, variation: { type: "string" } }, required: ["domain", "substance", "style"] }