import_persona
Enables dynamic AI persona management by importing a persona from a specified file path or JSON string, with optional overwrite capabilities.
Instructions
Import a persona from a file path or JSON string
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| overwrite | No | Overwrite if persona already exists (default: false) | |
| source | Yes | File path to a .md or .json file, or a JSON string of the persona |
Implementation Reference
- src/server/tools/PersonaTools.ts:47-68 (registration)MCP tool registration for 'import_persona' including name, description, input schema validation, and handler that delegates to server.importPersona{ tool: { name: "import_persona", description: "Import a persona from a file path or JSON string", inputSchema: { type: "object", properties: { source: { type: "string", description: "File path to a .md or .json file, or a JSON string of the persona", }, overwrite: { type: "boolean", description: "Overwrite if persona already exists (default: false)", }, }, required: ["source"], }, }, handler: (args: any) => server.importPersona(args.source, args.overwrite) } ];
- Core implementation of persona import handling various input formats (file, base64, JSON, markdown), security validation, conflict checking, and file creation. Likely called from server.importPersona method.async importPersona(source: string, existingPersonas: Map<string, Persona>, overwrite = false): Promise<ImportResult> { try { // Determine source type let personaData: ExportedPersona | null = null; // Check if it's a file path if (source.startsWith('/') || source.startsWith('./') || source.endsWith('.md') || source.endsWith('.json')) { personaData = await this.importFromFile(source); } // Check if it's base64 encoded else if (this.isBase64(source)) { personaData = await this.importFromBase64(source); } // Try parsing as JSON directly else { try { const parsed = JSON.parse(source); if (this.isExportBundle(parsed)) { return this.importBundle(parsed, existingPersonas, overwrite); } else if (this.isExportedPersona(parsed)) { personaData = parsed; } } catch { // Not JSON, might be raw markdown return this.importFromMarkdown(source, existingPersonas, overwrite); } } if (!personaData) { return { success: false, message: "Could not parse import source. Please provide a file path, JSON string, or base64 encoded data." }; } // Validate and create persona return await this.createPersonaFromExport(personaData, existingPersonas, overwrite); } catch (error) { logger.error('Import error', error); return { success: false, message: `Import failed: ${error instanceof Error ? error.message : String(error)}` }; } }
- src/server/types.ts:64-64 (schema)Type definition for the server.importPersona method called by the tool handler.importPersona(source: string, overwrite?: boolean): Promise<any>;