Skip to main content
Glama

localizationGetByKey

Retrieve specific translation entries by key from localization files to support multilingual application development and content management.

Instructions

根據Key查詢特定翻譯項目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
keyYes

Implementation Reference

  • Core handler logic for retrieving a localization entry by key: loads CSV data from cache or parses file, finds matching entry by Key field, returns the entry or null. Handles errors by throwing.
    static async getEntryByKey(filePath: string, key: string): Promise<LocalizationEntry | null> {
      try {
        // 讀取所有資料
        const records = await this.getCSVData(filePath);
        
        // 尋找匹配的Key
        const foundEntry = records.find(entry => entry.Key === key);
        return foundEntry || null;
      } catch (error) {
        console.error(`讀取Key失敗: ${error instanceof Error ? error.message : '未知錯誤'}`);
        throw error;
      }
    }
  • TypeScript interface defining the structure of a localization entry, used as return type for getEntryByKey.
    export interface LocalizationEntry {
      Key: string;
      'zh-TW': string;
      'zh-CN': string;
      en: string;
      [key: string]: string; // 其他可能的語言欄位
    }
  • main.ts:305-320 (registration)
    MCP server tool registration for 'localizationGetByKey', includes description, Zod input schema, and thin async handler that calls the core implementation and returns JSON-formatted result or error.
    server.tool("localizationGetByKey",
        "根據Key查詢特定翻譯項目",
        { filePath: z.string(), key: z.string() },
        async ({ filePath, key }) => {
            try {
                const entry = await LocalizationTool.getEntryByKey(filePath, key);
                return {
                    content: [{ type: "text", text: JSON.stringify(entry, null, 2) }]
                };
            } catch (error) {
                return {
                    content: [{ type: "text", text: `查詢失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }]
                };
            }
        }
    );
  • main.ts:308-319 (handler)
    Thin MCP tool handler wrapper: invokes LocalizationTool.getEntryByKey with inputs, returns MCP-formatted text content with JSON entry or error message.
    async ({ filePath, key }) => {
        try {
            const entry = await LocalizationTool.getEntryByKey(filePath, key);
            return {
                content: [{ type: "text", text: JSON.stringify(entry, null, 2) }]
            };
        } catch (error) {
            return {
                content: [{ type: "text", text: `查詢失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }]
            };
        }
    }
  • Inline Zod schema for tool inputs: filePath (CSV file path) and key (localization key to lookup).
    { filePath: z.string(), key: z.string() },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It implies a read operation ('查詢' - query), suggesting it's non-destructive, but doesn't clarify permissions, rate limits, error handling, or what happens if the key is not found. This is a significant gap for a tool with zero annotation coverage.

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 in Chinese, front-loaded with the core action. There is no wasted text, making it highly concise and well-structured for quick understanding.

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 the complexity (2 required parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the return values, error cases, or how parameters interact, leaving the agent with insufficient information to use the tool effectively in context.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'Key' but doesn't explain its format or purpose, and ignores 'filePath' entirely. This fails to add meaningful context beyond the bare schema, leaving key details unspecified.

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 ('查詢' - query) and resource ('翻譯項目' - translation item), specifying it's based on a key. It distinguishes from siblings like localizationAdd (add), localizationDelete (delete), and localizationSearch (search), though not explicitly. However, it lacks specificity about what a 'translation item' entails, making it slightly vague.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention when to choose this over localizationSearch (which might search broadly) or localizationFindMissing (which finds gaps), nor does it specify prerequisites or contexts for usage, leaving the agent with no direction.

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

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/GonTwVn/GonMCPtool'

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