create_presentation_definition
Generate a DIF Presentation Exchange v2.0 definition to specify credential requirements, including input descriptors and field constraints, for secure and structured verification workflows.
Instructions
Create a DIF Presentation Exchange v2.0 definition for requesting specific credentials. Defines input descriptors and constraints for credential selection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| inputDescriptors | Yes | ||
| name | No | ||
| purpose | No |
Implementation Reference
- The main handler function that validates input using the schema, builds a DIF Presentation Exchange v2.0 presentation definition, performs validation checks, generates a human-readable summary, and returns the result as MCP CallToolResult with text and JSON content.export async function createPresentationDefinition(args: any): Promise<CallToolResult> { // Validate and sanitize input const validation = validateAndSanitizeInput(CreatePresentationDefinitionInputSchema, args, 'create_presentation_definition'); if (!validation.success) { return createValidationErrorResult(validation.error!); } const data = validation.data!; const { id, name, purpose, inputDescriptors } = data; try { // Build the presentation definition according to DIF PEX v2.0 spec const presentationDefinition = { id, name, purpose, input_descriptors: inputDescriptors.map((descriptor: any) => ({ id: descriptor.id, name: descriptor.name, purpose: descriptor.purpose, constraints: descriptor.constraints || {}, schema: descriptor.schema || undefined })) }; // Validate the structure if (!presentationDefinition.input_descriptors.length) { throw new Error('At least one input descriptor is required'); } // Check for duplicate IDs const descriptorIds = presentationDefinition.input_descriptors.map((d: any) => d.id); const uniqueIds = new Set(descriptorIds); if (descriptorIds.length !== uniqueIds.size) { throw new Error('Input descriptor IDs must be unique'); } const summary = [ `• Definition ID: ${id}`, `• Name: ${name || 'Not specified'}`, `• Purpose: ${purpose || 'Not specified'}`, `• Input Descriptors: ${inputDescriptors.length}`, '' ]; inputDescriptors.forEach((descriptor: any, index: number) => { summary.push(`Input Descriptor ${index + 1}:`); summary.push(` • ID: ${descriptor.id}`); summary.push(` • Name: ${descriptor.name || 'Not specified'}`); summary.push(` • Purpose: ${descriptor.purpose || 'Not specified'}`); if (descriptor.constraints?.fields) { summary.push(` • Field Constraints: ${descriptor.constraints.fields.length}`); descriptor.constraints.fields.forEach((field: any, fieldIndex: number) => { summary.push(` - Field ${fieldIndex + 1}: ${field.path?.join(', ') || 'No path specified'}`); }); } summary.push(''); }); return { content: [ { type: 'text', text: `Created Presentation Definition:\n\n${summary.join('\n')}` }, { type: 'text', text: `\`\`\`json\n${JSON.stringify(presentationDefinition, null, 2)}\n\`\`\`` } ] }; } catch (error: any) { return { content: [ { type: 'text', text: `Failed to create presentation definition: ${error.message}` } ], isError: true }; } }
- src/schemas/toolSchemas.ts:115-120 (schema)Zod input schema for the create_presentation_definition tool, defining required id, optional name/purpose, and array of inputDescriptors (referencing InputDescriptorSchema).export const CreatePresentationDefinitionInputSchema = z.object({ id: z.string().min(1, 'Presentation definition ID is required'), name: z.string().optional(), purpose: z.string().optional(), inputDescriptors: z.array(InputDescriptorSchema).min(1, 'At least one input descriptor is required') });
- src/utils/schemaConverter.ts:37-39 (registration)Tool registration in TOOL_DEFINITIONS array, providing the MCP tool name, description, and input schema reference used by createMCPTools() to generate the Tool[] list.name: 'create_presentation_definition', description: 'Create a DIF Presentation Exchange v2.0 definition for requesting specific credentials. Defines input descriptors and constraints for credential selection.', inputSchema: TOOL_SCHEMAS.create_presentation_definition
- src/index.ts:95-96 (registration)Handler dispatch registration in the switch statement within the CallToolRequestSchema handler, mapping the tool name to the createPresentationDefinition function call.case 'create_presentation_definition': return await createPresentationDefinition(args);
- src/schemas/toolSchemas.ts:182-182 (registration)Schema mapping in TOOL_SCHEMAS object, associating the tool name with its Zod input schema for use in schemaConverter.create_presentation_definition: CreatePresentationDefinitionInputSchema,