MCP 翻译服务
基于小牛翻译(Niutrans)API 的 MCP Provider,提供文字翻译工具和语种目录资源,方便在 Cursor/mcp-cli 等客户端中引用。
快速开始
使用 uv 安装并启动发布版
uv tool install mcp-translation-text
环境变量
NIUTRANS_API_KEY(必填):小牛翻译开放平台提供的 API Key,可免费使用, 请登录后获取:https://niutrans.com/cloud/account_info/info
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 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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_translation_text-1.0.7.tar.gz | 13.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_translation_text-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.7 kB
Release files / mcp_translation_text-1.0.7.tar.gz
| Download URL | mcp_translation_text-1.0.7.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e58c8f30dbfc661b7937df80686c87ba2d738fed4506696c6602d7e2e0dcb44c
|
|
BLAKE2b-256 checksum How to use checksums |
8309234a0bd0eb134511c06fd4ca66098637df65d03f9b0c5060798d69baac9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / mcp_translation_text-1.0.7-py3-none-any.whl
| Download URL | mcp_translation_text-1.0.7-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bb7885e9d7790d3fa9575233c52a80929c82b7dddc143ab7b14f55a0b76f85b
|
|
BLAKE2b-256 checksum How to use checksums |
aac8a822e4c5886728d3eb6a789745ec7c1870c26bfb3cb797da150ed9c143c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for mcp-translation-text 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.