Skip to main content
Glama

localizationAdd

Adds a complete translation entry with Chinese and English versions to localization files for multilingual application support.

Instructions

新增一個完整的翻譯項目

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
entryYes

Implementation Reference

  • Core handler function that implements the localizationAdd tool logic: reads CSV, checks for duplicate Key, adds the new entry, writes back to file, and handles caching.
    static async addEntry(filePath: string, entry: LocalizationEntry): Promise<string> {
      try {
        // 檢查輸入是否有效
        if (!entry.Key) {
          return '錯誤: Key 不能為空';
        }
        
        const records = await this.getCSVData(filePath);
    
        // 檢查Key是否已存在
        if (records.some(e => e.Key === entry.Key)) {
          return `錯誤: Key "${entry.Key}" 已存在`;
        }
    
        // 新增項目
        records.push({...entry});
    
        // 寫回檔案並更新緩存
        await this.writeCSVData(filePath, records);
    
        return `成功新增Key "${entry.Key}"`;
      } catch (error) {
        console.error(`新增翻譯項失敗: ${error instanceof Error ? error.message : '未知錯誤'}`);
        throw error;
      }
    }
  • main.ts:346-369 (registration)
    MCP server registration of the 'localizationAdd' tool, including inline input schema and handler wrapper that calls LocalizationTool.addEntry.
    server.tool("localizationAdd",
        "新增一個完整的翻譯項目",
        {
            filePath: z.string(),
            entry: z.object({
                Key: z.string(),
                "zh-TW": z.string(),
                "zh-CN": z.string(),
                en: z.string()
            }).passthrough()
        },
        async ({ filePath, entry }) => {
            try {
                const result = await LocalizationTool.addEntry(filePath, entry as LocalizationEntry);
                return {
                    content: [{ type: "text", text: result }]
                };
            } catch (error) {
                return {
                    content: [{ type: "text", text: `新增失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }]
                };
            }
        }
    );
  • Zod input schema validation for the localizationAdd tool defining filePath and entry structure (Key, zh-TW, zh-CN, en).
    {
        filePath: z.string(),
        entry: z.object({
            Key: z.string(),
            "zh-TW": z.string(),
            "zh-CN": z.string(),
            en: z.string()
        }).passthrough()
    },
  • TypeScript interface defining the structure of a LocalizationEntry used in the tool.
    export interface LocalizationEntry {
      Key: string;
      'zh-TW': string;
      'zh-CN': string;
      en: string;
      [key: string]: string; // 其他可能的語言欄位
    }
  • Helper method to write updated CSV data back to file with proper column ordering, CSV stringification, and cache update, used by addEntry.
    private static async writeCSVData(filePath: string, data: LocalizationEntry[]): Promise<void> {
      try {
        // 檢查是否有數據
        if (data.length === 0) {
          throw new Error('沒有要寫入的數據');
        }
        
        // 獲取所有列名
        const columnSet = new Set<string>();
        columnSet.add('Key'); // 確保Key始終是第一列
        
        // 收集所有可能的列
        data.forEach(entry => {
          Object.keys(entry).forEach(key => columnSet.add(key));
        });
        
        // 轉換為陣列並將Key移到第一位
        const columns = Array.from(columnSet);
        if (columns[0] !== 'Key') {
          const keyIndex = columns.indexOf('Key');
          if (keyIndex > 0) {
            columns.splice(keyIndex, 1);
            columns.unshift('Key');
          }
        }
        
        // 使用csv-stringify生成CSV內容
        const output = stringify(data, {
          header: true,
          columns,
          quoted_string: true,
          quoted_empty: true
        });
        
        // 寫入檔案
        await fs.writeFile(filePath, output, 'utf-8');
        
        // 更新緩存
        this.cache.set(filePath, {
          data: [...data], // 深拷貝防止引用問題
          timestamp: Date.now()
        });
      } catch (error) {
        console.error(`寫入CSV檔案失敗: ${error instanceof Error ? error.message : '未知錯誤'}`);
        throw error;
      }
    }
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 offers minimal behavioral insight. '新增' (add) implies a write operation, but it doesn't disclose whether this creates new files, appends to existing ones, requires specific file formats, or has side effects. No information about permissions, error handling, or response format is included.

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?

Extremely concise with a single sentence that directly states the tool's action. No wasted words or redundant information. The structure is front-loaded with the core purpose, though it lacks detail.

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?

For a tool with 2 parameters (including a nested object), 0% schema coverage, no annotations, and no output schema, the description is inadequate. It doesn't explain the tool's behavior, parameter meanings, or expected outcomes, leaving significant gaps for an AI agent to understand its use.

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 but adds no parameter information. It doesn't explain what 'filePath' refers to (e.g., translation file location) or what 'entry' contains (translation key and values). The two parameters remain undocumented beyond their schema structure.

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

Purpose3/5

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

The description '新增一個完整的翻譯項目' (Add a complete translation project) states a general purpose but lacks specificity. It mentions adding translation items but doesn't clarify what constitutes a 'complete translation project' or how it differs from sibling tools like localizationUpdate or localizationDelete. The verb+resource is present but 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 on when to use this tool versus alternatives like localizationUpdate or localizationDelete. The description doesn't mention prerequisites, constraints, or typical scenarios for adding translation entries versus updating existing ones. Usage context is implied but not explicit.

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