UNPKG

mem100x

Version:

⚡ The FASTEST MCP memory server ever built - 66k+ entities/sec with intelligent context detection

125 lines 6.01 kB
"use strict"; /** * Zod schemas for tool input validation * Provides type safety and runtime validation for all MCP tools */ Object.defineProperty(exports, "__esModule", { value: true }); exports.toolSchemas = void 0; exports.validateToolInput = validateToolInput; const zod_1 = require("zod"); // Entity schemas const EntitySchema = zod_1.z.object({ name: zod_1.z.string().min(1, 'Entity name cannot be empty'), entityType: zod_1.z.string().min(1, 'Entity type cannot be empty'), observations: zod_1.z.array(zod_1.z.string()).min(1, 'At least one observation is required'), }); const RelationSchema = zod_1.z.object({ from: zod_1.z.string().min(1, 'From entity cannot be empty'), to: zod_1.z.string().min(1, 'To entity cannot be empty'), relationType: zod_1.z.string().min(1, 'Relation type cannot be empty'), }); const ObservationUpdateSchema = zod_1.z.object({ entityName: zod_1.z.string().min(1, 'Entity name cannot be empty'), contents: zod_1.z.array(zod_1.z.string()).min(1, 'At least one observation is required'), }); const ObservationDeletionSchema = zod_1.z.object({ entityName: zod_1.z.string().min(1, 'Entity name cannot be empty'), observations: zod_1.z.array(zod_1.z.string()).min(1, 'At least one observation to delete is required'), }); // Tool input schemas exports.toolSchemas = { // Context management set_context: zod_1.z.object({ context: zod_1.z.string().min(1, 'Context name cannot be empty'), }), get_context_info: zod_1.z.object({}), // Entity operations create_entities: zod_1.z.object({ entities: zod_1.z.array(EntitySchema).min(1, 'At least one entity is required'), context: zod_1.z.string().optional(), }), search_nodes: zod_1.z.object({ query: zod_1.z.string().min(1, 'Search query cannot be empty'), limit: zod_1.z.number().int().positive().default(20).optional(), context: zod_1.z.string().optional(), allContexts: zod_1.z.boolean().default(false).optional(), }), read_graph: zod_1.z.object({ limit: zod_1.z.number().int().positive().optional(), offset: zod_1.z.number().int().min(0).default(0).optional(), context: zod_1.z.string().optional(), }), open_nodes: zod_1.z.object({ names: zod_1.z.array(zod_1.z.string()).min(1, 'At least one entity name is required'), context: zod_1.z.string().optional(), }), // Relation operations create_relations: zod_1.z.object({ relations: zod_1.z.array(RelationSchema).min(1, 'At least one relation is required'), }), delete_relations: zod_1.z.object({ relations: zod_1.z.array(RelationSchema).min(1, 'At least one relation is required'), }), // Observation operations add_observations: zod_1.z.object({ observations: zod_1.z.array(ObservationUpdateSchema).min(1, 'At least one observation update is required'), }), delete_observations: zod_1.z.object({ deletions: zod_1.z.array(ObservationDeletionSchema).min(1, 'At least one deletion is required'), }), // Entity deletion delete_entities: zod_1.z.object({ entityNames: zod_1.z.array(zod_1.z.string()).min(1, 'At least one entity name is required'), }), // Transaction management begin_transaction: zod_1.z.object({ name: zod_1.z.string().optional().describe('Optional transaction name for debugging'), }), commit_transaction: zod_1.z.object({}), rollback_transaction: zod_1.z.object({}), // Backup and restore create_backup: zod_1.z.object({ backupPath: zod_1.z.string().optional().describe('Path for the backup file. If not provided, a timestamped backup will be created in the default backup directory'), context: zod_1.z.string().optional().describe('Specific context to backup. If not provided, backs up current context'), }), restore_backup: zod_1.z.object({ backupPath: zod_1.z.string().describe('Path to the backup file to restore'), context: zod_1.z.string().optional().describe('Context to restore to. If not provided, restores to current context'), confirmRestore: zod_1.z.boolean().describe('Must be true to confirm the restore operation'), }), // Graph traversal operations get_neighbors: zod_1.z.object({ entityName: zod_1.z.string().min(1, 'Entity name is required'), direction: zod_1.z.enum(['outgoing', 'incoming', 'both']).default('both').optional() .describe('Direction of relations to follow'), relationType: zod_1.z.string().optional() .describe('Filter by specific relation type'), depth: zod_1.z.number().int().min(1).max(5).default(1).optional() .describe('How many hops to traverse (1-5)'), includeRelations: zod_1.z.boolean().default(true).optional() .describe('Include relation details in response'), context: zod_1.z.string().optional() .describe('Specific context to search in'), }), find_shortest_path: zod_1.z.object({ from: zod_1.z.string().min(1, 'Source entity name is required'), to: zod_1.z.string().min(1, 'Target entity name is required'), bidirectional: zod_1.z.boolean().default(true).optional() .describe('Whether to follow relations in both directions'), relationType: zod_1.z.string().optional() .describe('Filter by specific relation type'), maxDepth: zod_1.z.number().int().min(1).max(10).default(6).optional() .describe('Maximum path length to search (1-10)'), context: zod_1.z.string().optional() .describe('Specific context to search in'), }), }; // Helper to validate tool input function validateToolInput(toolName, input) { const schema = exports.toolSchemas[toolName]; if (!schema) { throw new Error(`No schema defined for tool: ${toolName}`); } return schema.parse(input); } //# sourceMappingURL=tool-schemas.js.map