detect_language
Identify the language of input text with confidence scores. Supports single strings or batches up to 128 items for efficient processing.
Instructions
Detects the language of the provided text. Returns the detected language, content type, and a list of predictions with confidence scores. Accepts a single string or an array of strings (up to 128 elements).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text to detect the language of. Can be a single string or an array of strings (up to 128 elements). | |
| hint | No | Optional language code hint to guide detection (e.g., 'en-EN'). | |
| passlist | No | Optional list of language codes to restrict detection results to. |
Implementation Reference
- src/mcp/tools/detect_language.ts:24-28 (handler)The main handler function for detect_language. Parses args (text, hint, passlist) via Zod schema and calls lara.detect().
export async function detectLanguage(args: unknown, lara: Translator) { const { text, hint, passlist } = detectLanguageSchema.parse(args); return lara.detect(text, hint, passlist); } - Zod schema defining input validation for detect_language: 'text' (string or array up to 128), optional 'hint' (language code), optional 'passlist' (array of language codes).
export const detectLanguageSchema = z.object({ text: z .union([z.string(), z.array(z.string()).max(128)]) .describe( "The text to detect the language of. Can be a single string or an array of strings (up to 128 elements)." ), hint: z .string() .optional() .describe( "Optional language code hint to guide detection (e.g., 'en-EN')." ), passlist: z .array(z.string()) .optional() .describe( "Optional list of language codes to restrict detection results to." ), }); - src/mcp/tools.ts:48-49 (registration)Registration of detect_language in the handlers map, mapping the tool name string to the detectLanguage function.
const handlers: Record<string, Handler> = { detect_language: detectLanguage, - src/mcp/tools.ts:203-216 (registration)Tool definition registration including name, description, inputSchema, annotations (title, readOnlyHint, destructiveHint, openWorldHint), and _meta for the detect_language tool.
const toolDefinitions = [ { name: "detect_language", description: "Detects the language of the provided text. Returns the detected language, content type, and a list of predictions with confidence scores. Accepts a single string or an array of strings (up to 128 elements).", inputSchema: z.toJSONSchema(detectLanguageSchema), annotations: { title: "Detect language", readOnlyHint: true, destructiveHint: false, openWorldHint: true, }, _meta: invocationMeta("Detecting language…", "Language detected"), },