listLanguages
Retrieve available languages for a Weblate translation project to manage multilingual content effectively.
Instructions
List languages available in a specific project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectSlug | Yes | The slug of the project |
Implementation Reference
- src/tools/languages.tool.ts:12-47 (handler)The main handler function for the 'listLanguages' MCP tool. It uses @Tool decorator specifying name, description, input schema with Zod, fetches languages via service, formats as markdown list, handles errors, and returns structured content.@Tool({ name: 'listLanguages', description: 'List languages available in a specific project', parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }), }) async listLanguages({ projectSlug }: { projectSlug: string }) { try { const languages = await this.weblateApiService.listLanguages(projectSlug); return { content: [ { type: 'text', text: `Languages in project "${projectSlug}":\n\n${languages .map( (l) => `- **${l.name}** (${l.code})`, ) .join('\n')}`, }, ], }; } catch (error) { this.logger.error(`Failed to list languages for ${projectSlug}`, error); return { content: [ { type: 'text', text: `Error listing languages for project "${projectSlug}": ${error.message}`, }, ], isError: true, }; }
- src/tools/languages.tool.ts:15-17 (schema)Zod schema defining the input parameters for the listLanguages tool: projectSlug as string.parameters: z.object({ projectSlug: z.string().describe('The slug of the project'), }),
- src/app.module.ts:74-80 (registration)Registration of tool classes including WeblateLanguagesTool in the AppModule providers. Since they use @Tool decorator, NestJS/MCP auto-registers them.WeblateProjectsTool, WeblateComponentsTool, WeblateLanguagesTool, WeblateTranslationsTool, WeblateChangesTool, WeblateStatisticsTool, ],
- Helper method in WeblateApiService that delegates listLanguages call to the underlying languages service.async listLanguages(projectSlug: string): Promise<Language[]> { return this.languagesService.listLanguages(projectSlug); }
- Core helper service implementing the API call to retrieve languages for a project using Weblate client, with response parsing and error handling.async listLanguages(projectSlug: string): Promise<Language[]> { try { const client = this.weblateClientService.getClient(); const response = await projectsLanguagesRetrieve({ client, path: { slug: projectSlug } }); // Handle different response formats const languages = response.data as any; if (Array.isArray(languages)) { return languages; } // If it's a paginated response if (languages && languages.results && Array.isArray(languages.results)) { return languages.results; } // If it's a single language, wrap it in an array if (languages && typeof languages === 'object') { return [languages]; } return []; } catch (error) { this.logger.error( `Failed to list languages for project ${projectSlug}`, error, ); throw new Error(`Failed to list languages: ${error.message}`); } }