create_substance
Define mathematical objects and relationships by specifying domain, declarations, and statements for creating structured mathematical diagrams in the Penrose MCP Server.
Instructions
Define mathematical objects and relationships
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| declarations | Yes | ||
| domain | Yes | Reference to domain | |
| statements | Yes |
Implementation Reference
- src/index.ts:353-409 (handler)Handler function for the 'create_substance' tool. Validates input arguments, checks if the referenced domain exists, parses and validates declarations and statements, creates a Substance object, stores it in the substances Map using the domain name as key, and returns a success message.case "create_substance": { const args = request.params.arguments; if (!args || typeof args !== 'object') { throw new Error('Invalid arguments'); } const { domain: domainName, declarations, statements } = args as { domain?: string; declarations?: Array<any>; statements?: Array<any>; }; if (!domainName || !Array.isArray(declarations) || !Array.isArray(statements)) { throw new Error('Invalid substance definition: requires domain, declarations array, and statements array'); } // Validate domain exists if (!domains.has(domainName)) { throw new Error(`Domain ${domainName} not found`); } // Validate declarations const validatedDeclarations: Array<Declaration> = declarations.map(decl => { if (!decl.type || !Array.isArray(decl.objects)) { throw new Error('Invalid declaration: requires type and objects array'); } return { type: String(decl.type), objects: decl.objects.map((obj: any) => String(obj)) }; }); // Validate statements const validatedStatements: Array<Statement> = statements.map(stmt => { if (!stmt.predicate || !Array.isArray(stmt.args)) { throw new Error('Invalid statement: requires predicate and args array'); } return { predicate: String(stmt.predicate), args: stmt.args.map((arg: any) => String(arg)) }; }); const substance: Substance = { domain: domainName, declarations: validatedDeclarations, statements: validatedStatements }; substances.set(domainName, substance); return { content: [{ type: "text", text: `Created substance for domain: ${domainName}` }] }; }
- src/index.ts:213-254 (registration)Registration of the 'create_substance' tool in the list of available tools, including its name, description, and detailed input schema for domain reference, declarations, and statements.{ name: "create_substance", description: "Define mathematical objects and relationships", inputSchema: { type: "object", properties: { domain: { type: "string", description: "Reference to domain" }, declarations: { type: "array", items: { type: "object", properties: { type: { type: "string" }, objects: { type: "array", items: { type: "string" } } }, required: ["type", "objects"] } }, statements: { type: "array", items: { type: "object", properties: { predicate: { type: "string" }, args: { type: "array", items: { type: "string" } } }, required: ["predicate", "args"] } } }, required: ["domain", "declarations", "statements"] } },
- src/index.ts:37-51 (schema)TypeScript interfaces defining the structure of Substance, including Declaration and Statement, used for type validation in the create_substance handler.interface Declaration { type: string; objects: Array<string>; } interface Statement { predicate: string; args: Array<string>; } interface Substance { domain: string; declarations: Array<Declaration>; statements: Array<Statement>; }