list_elements
Retrieve and display all available elements of a chosen type, such as personas, skills, templates, agents, memories, or ensembles, on DollhouseMCP for dynamic AI persona management.
Instructions
List all available elements of a specific type
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | Yes | The element type to list |
Implementation Reference
- Core handler logic that lists element files in the portfolio directory for the specified type, filters by file extension, excludes test elements, and handles various filesystem errors gracefully.public async listElements(type: ElementType): Promise<string[]> { const elementDir = this.getElementDir(type); const fileExtension = ELEMENT_FILE_EXTENSIONS[type] || DEFAULT_ELEMENT_FILE_EXTENSION; try { const files = await fs.readdir(elementDir); // Filter for correct file extension based on element type and exclude test elements return files .filter(file => file.endsWith(fileExtension)) .filter(file => !this.isTestElement(file)); } catch (error) { const err = error as NodeJS.ErrnoException; if (err.code === 'ENOENT') { // Directory doesn't exist yet - this is expected for new installations logger.debug(`[PortfolioManager] Element directory doesn't exist yet: ${elementDir}`); return []; } if (err.code === 'EACCES' || err.code === 'EPERM') { // Permission denied - log but return empty array ErrorHandler.logError('PortfolioManager.listElements', error, { elementDir }); return []; } if (err.code === 'ENOTDIR') { // Path exists but is not a directory ErrorHandler.logError('PortfolioManager.listElements', error, { elementDir }); throw ErrorHandler.createError(`Path is not a directory: ${elementDir}`, ErrorCategory.SYSTEM_ERROR); } // For any other errors, throw with context ErrorHandler.logError('PortfolioManager.listElements', error, { elementDir }); throw ErrorHandler.wrapError(error, 'Failed to list elements', ErrorCategory.SYSTEM_ERROR); } }
- src/server/tools/ElementTools.ts:77-94 (registration)Tool registration object defining the 'list_elements' tool name, description, input schema (requiring 'type' enum from ElementType), and handler that delegates to server.listElements.{ tool: { name: "list_elements", description: "List all available elements of a specific type", inputSchema: { type: "object", properties: { type: { type: "string", description: "The element type to list", enum: Object.values(ElementType), }, }, required: ["type"], }, }, handler: (args: ListElementsArgs) => server.listElements(args.type) },
- Input schema for list_elements tool: object with required 'type' property (string enum from ElementType).inputSchema: { type: "object", properties: { type: { type: "string", description: "The element type to list", enum: Object.values(ElementType), }, }, required: ["type"], },
- src/server/ServerSetup.ts:53-53 (registration)Registers all element tools including list_elements by calling registerMany on getElementTools which returns the tool definitions.this.toolRegistry.registerMany(getElementTools(instance));
- Helper function used by listElements to filter out test and dangerous-looking element files from the listing.public isTestElement(filename: string): boolean { // Dangerous test patterns that should never appear in production const dangerousPatterns = [ /^bin-sh/i, /^rm-rf/i, /^nc-e-bin/i, /^python-c-import/i, /^curl.*evil/i, /^wget.*malicious/i, /^eval-/i, /^exec-/i, /^bash-c-/i, /^sh-c-/i, /^powershell-/i, /^cmd-c-/i, /shell-injection/i ]; // Common test patterns const testPatterns = [ /^test-/i, /^memory-test-/i, /^yaml-test/i, /^perf-test-/i, /^stability-test-/i, /^roundtrip-test/i, /test-persona/i, /test-skill/i, /test-template/i, /test-agent/i, /\.test\./, /__test__/, /test-data/, /penetration-test/i, /metadata-test/i, /testpersona\d+/i // Generated test personas with timestamps ]; // Check dangerous patterns first if (dangerousPatterns.some(pattern => pattern.test(filename))) { logger.warn(`[PortfolioManager] Filtered dangerous test element: ${filename}`); return true; } // Check common test patterns return testPatterns.some(pattern => pattern.test(filename)); }