get-source-languages
Retrieve a list of available source languages for translation using the DeepL API. Identify supported languages to ensure accurate and efficient text translation workflows.
Instructions
Get list of available source languages for translation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Handler function for the get-source-languages tool. It delegates to getDeeplLanguages('source') to retrieve available source languages from the DeepL API.async function getSourceLanguages() { return await getDeeplLanguages('source'); }
- workshops/deepl-simple-js/deepl-simple.js:40-44 (registration)Registration of the get-source-languages tool on the MCP server, specifying name, description, and handler function.server.tool( 'get-source-languages', 'Get list of available source languages for translation', getSourceLanguages );
- Core helper function that calls the appropriate DeepL API method to get source or target languages, formats the response as MCP text content, and handles errors.async function getDeeplLanguages(sourceOrDestination) { const method = sourceOrDestination == 'source' ? 'getSourceLanguages' : 'getTargetLanguages'; try { const languages = await deeplClient[method](); return mcpTextContentify(languages.map(JSON.stringify)); } catch (error) { return handleError(error); } }
- Utility function to wrap strings or array of strings into the MCP expected content object structure with type 'text'.function mcpTextContentify(param) { if (typeof(param) != 'string' && !Array.isArray(param)) { throw new Error('mcpTextContentify() expects a string or an array of strings'); } const strings = typeof(param) == 'string' ? [param] : param; const contentObjects = strings.map( str => ({ type: "text", text: str }) ); return { content: contentObjects }; }