create_domain
Define domain-specific language (DSL) structures by specifying domain names, types, and predicates for creating mathematical diagrams in the Penrose MCP Server.
Instructions
Create domain-specific language (DSL) definitions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Domain name | |
| types | Yes |
Implementation Reference
- src/index.ts:308-351 (handler)The handler logic for the 'create_domain' tool. It parses and validates the input arguments (name and types with optional predicates), constructs a Domain object, stores it in a Map called 'domains', and returns a success message.case "create_domain": { const args = request.params.arguments; if (!args || typeof args !== 'object') { throw new Error('Invalid arguments'); } const { name, types } = args as { name?: string; types?: Array<any> }; if (!name || !Array.isArray(types)) { throw new Error('Invalid domain definition: requires name and types array'); } // Validate types const validatedTypes: Array<DomainType> = types.map(type => { if (!type.name || typeof type.name !== 'string') { throw new Error('Invalid type definition: requires name'); } const validatedType: DomainType = { name: type.name }; if (type.predicates) { if (!Array.isArray(type.predicates)) { throw new Error('Invalid predicates: must be an array'); } validatedType.predicates = type.predicates.map((pred: any) => { if (!pred.name || !Array.isArray(pred.args)) { throw new Error('Invalid predicate: requires name and args array'); } return { name: String(pred.name), args: pred.args.map((arg: any) => String(arg)) }; }); } return validatedType; }); const domain: Domain = { name, types: validatedTypes }; domains.set(name, domain); return { content: [{ type: "text", text: `Created domain: ${name}` }] }; }
- src/index.ts:175-211 (schema)The JSON schema defining the input structure for the 'create_domain' tool, including required 'name' (string) and 'types' array of objects with 'name' and optional 'predicates'.inputSchema: { type: "object", properties: { name: { type: "string", description: "Domain name" }, types: { type: "array", items: { type: "object", properties: { name: { type: "string", description: "Type name" }, predicates: { type: "array", items: { type: "object", properties: { name: { type: "string" }, args: { type: "array", items: { type: "string" } } }, required: ["name", "args"] } } }, required: ["name"] } } }, required: ["name", "types"] }
- src/index.ts:172-212 (registration)The registration of the 'create_domain' tool in the tools list returned by the ListTools handler, including name, description, and inputSchema.{ name: "create_domain", description: "Create domain-specific language (DSL) definitions", inputSchema: { type: "object", properties: { name: { type: "string", description: "Domain name" }, types: { type: "array", items: { type: "object", properties: { name: { type: "string", description: "Type name" }, predicates: { type: "array", items: { type: "object", properties: { name: { type: "string" }, args: { type: "array", items: { type: "string" } } }, required: ["name", "args"] } } }, required: ["name"] } } }, required: ["name", "types"] } },