Skip to main content
Glama
DeepLcom
by DeepLcom

translate-text

Convert text into a target language using the DeepL API. Specify the language code and optionally adjust formality for translations. Designed for integration with AI assistants.

Instructions

Translate text to a target language using DeepL API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formalityNoControls whether translations should lean toward informal or formal language
targetLangYesTarget language code (e.g. 'en-US', 'de', 'fr')
textYesText to translate

Implementation Reference

  • The handler function for the 'translate-text' tool. It translates the input text to the target language using the DeepL API client, returns the translated text and detected source language, or handles errors.
    async function translateText({text, targetLang, formality}) {
      try {
        const result = await deeplClient.translateText( text, null, targetLang, { formality });
        return mcpTextContentify([
          result.text,
          'Detected source language: ' + result.detectedSourceLang
        ]);
    
      } catch (error) {
        return handleError(error);
      }
    }
  • Registration of the 'translate-text' tool on the MCP server, including name, description, input schema, and handler reference.
    server.tool(
      "translate-text",
      "Translate text to a target language using the DeepL API",
      {
        text: z.string().describe("Text to translate"),
        targetLang: z.string().describe("Target language ISO-639 code (e.g. 'en-US', 'de', 'fr')"),
        formality: z.enum(formalityTypes).optional()
                    .describe("Controls whether translations should lean toward informal or formal language"),
      },
      translateText
    );
  • Input schema definition using Zod for validating tool parameters: text (string), targetLang (string), and optional formality (enum).
    {
      text: z.string().describe("Text to translate"),
      targetLang: z.string().describe("Target language ISO-639 code (e.g. 'en-US', 'de', 'fr')"),
      formality: z.enum(formalityTypes).optional()
                  .describe("Controls whether translations should lean toward informal or formal language"),
    },
  • Helper function to format strings into MCP-compatible text content objects, used in the handler to return results.
    // Accept either a string or an array of strings, with partial error checking
    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
      };
    }
  • Helper function to handle and format errors for return in MCP format, called from the handler.
    // Finally, a helper function to pass errors back to the AI surface
    function handleError(error) {
      console.error("Error in the DeepL MCP server: ", error);
    
      const errorContentObject = mcpTextContentify([error.message]);
      errorContentObject.isError = true;
    
      return errorContentObject;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention rate limits, authentication needs, error handling, or what the output looks like (e.g., translated text format). This is inadequate for a tool with potential API constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste, clearly front-loading the core purpose. It avoids redundancy and is appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete. It doesn't explain return values, error conditions, or behavioral constraints like API usage limits. For a translation tool with potential complexity, this leaves significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters like 'text', 'targetLang', and 'formality' with enums. The description adds no additional meaning beyond the schema, such as examples or edge cases, but meets the baseline since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'translate' and the resource 'text', specifying it uses the DeepL API. It distinguishes from siblings like 'rephrase-text' by focusing on language translation rather than text modification. However, it doesn't explicitly differentiate from 'get-target-languages' which is related but not a direct alternative.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'rephrase-text' or the sibling language tools. It mentions the DeepL API but doesn't specify prerequisites, limitations, or contextual triggers for choosing translation over other text operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DeepLcom/deepl-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server