listComponents
Retrieve components from a Weblate translation project to manage and organize translation units for collaborative localization workflows.
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-49 (handler)The MCP tool handler for 'listComponents'. It uses the @Tool decorator to define the tool name, description, and Zod schema for input parameters. The function fetches components via WeblateApiService and formats them into a markdown response, handling errors gracefully.@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:65-81 (registration)Registration of the WeblateComponentsTool in the AppModule providers array, which makes it available to the MCP module.providers: [ WeblateClientService, WeblateProjectsService, WeblateComponentsService, WeblateLanguagesService, WeblateTranslationsService, WeblateChangesService, WeblateApiService, WeblateStatisticsService, WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool, ], })
- Core service implementation that calls the Weblate API to retrieve components for a project, handling various response formats and errors.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}`); } }
- src/tools/components.tool.ts:37-40 (helper)Proxy method in WeblateApiService that delegates to ComponentsService.listComponents.} catch (error) { this.logger.error(`Failed to list components for ${projectSlug}`, error); return { content: [
- src/tools/components.tool.ts:15-17 (schema)Zod schema defining the input parameter 'projectSlug' for the listComponents tool.parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }),