Skip to main content
Glama
bmorphism

Penrose MCP Server

generate_diagram

Create mathematical diagrams by defining domain concepts, substance relationships, and visual style rules using Penrose's domain-specific languages.

Instructions

Generate diagram from domain/substance/style

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domainYes
substanceYes
styleYes
variationNo

Implementation Reference

  • The handler function for the 'generate_diagram' tool. It validates the existence of the specified domain, substance, and style resources, generates a static SVG diagram depicting two objects 'A' and 'B' with a subset relationship arrow, and returns the SVG as a base64-encoded 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 the 'generate_diagram' tool in the list of available tools, including its description and 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"]
      }
    }

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/bmorphism/penrose-mcp'

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