listComponents
Retrieve a list of components within a specified project in Weblate MCP Server. Input the project slug to access and manage translation-related components efficiently.
Instructions
List components in a specific project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectSlug | Yes | The slug of the project |
Implementation Reference
- src/tools/components.tool.ts:12-48 (handler)The @Tool-decorated handler function that implements the listComponents MCP tool logic, including input schema validation via Zod, API call, response formatting, and error handling.@Tool({ name: 'listComponents', description: 'List components in a specific project', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }), }) async listComponents({ projectSlug }: { projectSlug: string }) { try { const components = await this.weblateApiService.listComponents(projectSlug); return { content: [ { type: 'text', text: `Components in project "${projectSlug}":\n\n${components .map( (c) => `- **${c.name}** (${c.slug})\n Source Language: ${c.source_language.name} (${c.source_language.code})`, ) .join('\n\n')}`, }, ], }; } catch (error) { this.logger.error(`Failed to list components for ${projectSlug}`, error); return { content: [ { type: 'text', text: `Error listing components for project "${projectSlug}": ${error.message}`, }, ], isError: true, }; }
- src/app.module.ts:74-79 (registration)Registration of the WeblateComponentsTool class in the NestJS AppModule providers array, making it available for MCP tool discovery.WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool,
- Supporting service method that performs the actual Weblate API call to retrieve the list of components, handling various response formats.async listComponents(projectSlug: string): Promise<Component[]> { try { const client = this.weblateClientService.getClient(); const response = await projectsComponentsRetrieve({ client, path: { slug: projectSlug } }); // According to the API comment, this should return a list of components // The typing might be incorrect - try to handle both single and array responses const components = response.data as any; if (Array.isArray(components)) { return components; } // If it's a paginated response if (components && components.results && Array.isArray(components.results)) { return components.results; } // If it's a single component, wrap it in an array if (components && typeof components === 'object') { return [components]; } return []; } catch (error) { this.logger.error( `Failed to list components for project ${projectSlug}`, error, ); throw new Error(`Failed to list components: ${error.message}`); } }
- Facade method in WeblateApiService that delegates the listComponents call to the underlying components service.async listComponents(projectSlug: string): Promise<Component[]> { return this.componentsService.listComponents(projectSlug); }
- src/tools/index.ts:2-2 (registration)Export of the components tool module for barrel export in tools directory.export * from './components.tool';