create_substance
Define mathematical objects and relationships to create visual diagrams using Penrose's domain-specific languages, enabling natural language specification of types and representation rules.
Instructions
Define mathematical objects and relationships
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | Reference to domain | |
| declarations | Yes | ||
| statements | Yes |
Implementation Reference
- src/index.ts:353-409 (handler)Handler for 'create_substance' tool: validates arguments, checks referenced domain exists, parses declarations and statements, stores Substance in memory map, returns confirmation 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:216-253 (schema)JSON Schema defining the input parameters for the 'create_substance' tool: domain reference, array of declarations (type and objects), array of statements (predicate and args).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:213-254 (registration)Registration of the 'create_substance' tool in the ListTools response, including name, description, and input schema.{ 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:47-51 (helper)TypeScript interface defining the structure of a Substance used by the create_substance tool.interface Substance { domain: string; declarations: Array<Declaration>; statements: Array<Statement>; }
- src/index.ts:37-46 (helper)TypeScript interfaces for Declaration and Statement, components of Substance.interface Declaration { type: string; objects: Array<string>; } interface Statement { predicate: string; args: Array<string>; }