Skip to main content

MCP 翻译服务

基于小牛翻译(NiuTrans)API 的 MCP Provider,提供文字翻译工具和语种目录资源,方便在 Cursor/mcp-cli 等客户端中引用。

快速开始

使用 uv 安装并启动发布版

uv tool install mcp-translation-text

环境变量

计费说明

本服务使用小牛翻译的文本翻译 API,计费规则如下:

项目 说明
计费单位 2000 字符 = 1 积分
免费额度 每天免费赠送 100 积分
每日可翻译 约 20 万字符(免费额度)

💡 提示:每日免费赠送的 100 积分足够日常使用,超出部分可在小牛翻译开放平台充值购买。

MCP 客户端配置示例

若通过 uv tool install 安装,可在 mcp.json 中写:

{
  "mcpServers": {
    "translation": {
      "type": "stdio",
      "command": "uv",
      "args": [
        "tool",
        "run",
        "mcp-translation-text"
      ],
      "env": {
        "NIUTRANS_API_KEY": "${env.NIUTRANS_API_KEY}"
      }
    }
  }
}

启动 Cursor 后执行 ListTools 即可看到 translate_text,同时支持 ListResources 读取 language://catalog。

可用功能

工具:translate_text

  • 参数:
    • text:待翻译内容。
    • source:源语言代码或别名(会通过本地映射表规范化)。
    • target:目标语言代码或别名。
  • 返回:
    {
      "source": "zh",
      "target": "en",
      "original_text": "你好",
      "translated_text": "Hello",
      "raw": { ... 小牛原始响应 ... }
    }
    

资源:language://catalog

提供所有可用语种及别名,示例如下:

{
  "total": 455,
  "languages": [
    {"code": "zh", "zh": "中文(简体)", "en": "Chinese (Simplified)"},
    {"code": "en", "zh": "英语", "en": "English"}
    // ... 其余省略 ...
  ],
  "aliases": {
    "zhongwenjianti": "zh",
    "english": "en"
    // ... 其余省略 ...
  }
}

推荐在客户端的 LLM 中先读取该资源,完成语种描述到代码的映射后,再调用 translate_text。

调试与常见问题

  • 缺少 API Key:启动时报 缺少环境变量 NIUTRANS_API_KEY,请确认已在 .env 或系统环境中设置。
  • 语种不支持:translate_text 会校验语种代码/别名,若报错请检查是否使用了 language://catalog 中列出的值。
  • 路径或依赖问题:脚本依赖 uv,请先安装 pip install uv 或参考 uv 文档。
  • 命令名称:通过 PyPI 安装后,可直接运行 mcp-translation-text;若 global PATH 中找不到,记得激活虚拟环境或使用 python -m mcp_translation_text。
  • 发布/升级包:
    python -m build
    twine upload dist/*
    

目录结构(关键文件)

E:\MCP
├── pyproject.toml
├── server.py                # 入口包装,确保 python server.py 可运行
├── src/
│   └── translation_server.py
├── scripts/
│   ├── start.ps1
│   └── start.sh
├── .env.example
├── LICENSE
└── README.md

发布后,用户只需设置 NiuTrans API Key,即可通过 mcp-translation-text 直接加载该 Provider。

Metadata

Release files for iflow-mcp_niutrans_mcp-translation-text 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_niutrans_mcp-translation-text 1.0.7
File Size Uploaded
iflow_mcp_niutrans_mcp_translation_text-1.0.7.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_niutrans_mcp-translation-text 1.0.7
File Interpreter ABI Platform
iflow_mcp_niutrans_mcp_translation_text-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / iflow_mcp_niutrans_mcp_translation_text-1.0.7.tar.gz

Download URL iflow_mcp_niutrans_mcp_translation_text-1.0.7.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d7d283e77918b2fb206a839d081d0a681ecc9428a6b8134c23476433f05bfc5f
BLAKE2b-256 checksum
How to use checksums
39e5793c4a05bae094007e90e85787c5e1a8d01edac395e97f4c338160ef047c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_niutrans_mcp_translation_text-1.0.7-py3-none-any.whl

Download URL iflow_mcp_niutrans_mcp_translation_text-1.0.7-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbe4484c3d1e2104639d41b65630578b3384c15e9060d976f4032be9d05327ad
BLAKE2b-256 checksum
How to use checksums
bc9cdd3ebcaa8b96439ed64fe7f16dcfbbbaae2f41b3bafc1e61ae788ae3e5f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.7 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page