Powers the translation service with OpenAI-compatible models, enabling translation between 20+ languages, automatic language detection, and processing of long texts by breaking them into manageable chunks.
Allows the server to be published and installed as a package from PyPI, enabling easier distribution and installation for users.
Translation MCP Server
一个基于 Model Context Protocol (MCP) 的文本翻译服务,支持 OpenAI 和兼容 OpenAI API 的模型。
功能特性
- 🌍 多语言支持: 支持 20+ 种主要语言之间的翻译
- 🤖 AI 驱动: 基于 OpenAI 兼容的大语言模型
- 📄 长文本处理: 自动分块处理大文档,突破 API 长度限制
- 🔍 语言检测: 自动识别输入文本的语言
- 🔌 MCP 协议: 标准化接口,易于集成到支持 MCP 的应用中
- ⚡ 异步处理: 基于 asyncio 的高性能异步架构
- 🛠️ 灵活配置: 支持自定义模型和 API 端点
支持的语言
语言代码 | 语言名称 | 语言代码 | 语言名称 |
---|---|---|---|
en | English | zh | 中文 |
ja | 日本語 | ko | 한국어 |
es | Español | fr | Français |
de | Deutsch | it | Italiano |
pt | Português | ru | Русский |
ar | العربية | hi | हिन्दी |
th | ไทย | vi | Tiếng Việt |
id | Bahasa Indonesia | ms | Bahasa Melayu |
tl | Filipino | tr | Türkçe |
pl | Polski | nl | Nederlands |
安装
环境要求
- Python 3.10+
- OpenAI API 密钥(或兼容的 API 服务)
安装依赖
环境配置
创建 .env
文件并配置必要的环境变量:
使用方法
作为 MCP 服务器使用
本项目是一个 MCP (Model Context Protocol) 服务器,需要在支持 MCP 的客户端中配置使用,而不是直接运行。
在 Claude Desktop 中配置
在 Claude Desktop 的配置文件中添加:
使用 uvx 运行(推荐)
首先构建分发包:
然后在 Claude Desktop 配置中使用:
或者直接从 PyPI 安装(如果已发布):
开发和测试
MCP 工具
服务器提供以下 MCP 工具:
1. translate_text
翻译普通文本到指定语言。
参数:
text
(string, 必需): 要翻译的文本target_language
(string, 必需): 目标语言代码source_language
(string, 可选): 源语言代码,不指定则自动检测
示例:
2. detect_language
检测文本的语言。
参数:
text
(string, 必需): 要检测语言的文本
示例:
3. translate_long_text
翻译长文本,自动分块处理。
参数:
text
(string, 必需): 要翻译的长文本target_language
(string, 必需): 目标语言代码source_language
(string, 可选): 源语言代码max_chunk_size
(integer, 可选): 每个文本块的最大字符数,默认 2000
示例:
MCP 资源
translation://languages
获取所有支持的语言列表,包含语言代码和名称。
API 响应格式
成功响应
错误响应
长文本翻译响应
配置选项
环境变量
变量名 | 描述 | 默认值 |
---|---|---|
OPENAI_API_KEY | OpenAI API 密钥 | 必需 |
OPENAI_BASE_URL | API 基础 URL | https://api.openai.com/v1 |
OPENAI_MODEL | 默认模型 | gpt-3.5-turbo |
自定义模型
支持使用兼容 OpenAI API 的其他服务:
开发
项目结构
构建和分发
核心组件
- OpenAITranslator: 翻译服务核心类
- TranslationMCPServer: MCP 服务器实现
- 异步处理: 基于 asyncio 的异步架构
- 错误处理: 完善的异常处理机制
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
更新日志
v0.1.0
- 初始版本发布
- 支持基础文本翻译
- 支持语言检测
- 支持长文本分块翻译
- MCP 协议集成
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
An AI-driven text translation service supporting 20+ languages, based on the Model Context Protocol (MCP) for integration with Claude Desktop and other MCP-compatible applications.
Related MCP Servers
- -securityFlicense-qualityA comprehensive suite of Model Context Protocol servers designed to extend AI agent Claude's capabilities with integrations for knowledge management, reasoning, advanced search, news access, and workspace tools.Last updated -5TypeScript
- -securityAlicense-qualityA Model Context Protocol server that integrates high-quality text-to-speech capabilities with Claude Desktop and other MCP-compatible clients, supporting multiple voice options and audio formats.Last updated -141TypeScriptMIT License
- -securityFlicense-qualityA ModelContextProtocol server providing high-quality translation services with a three-stage translation workflow (analysis, segmented translation, full-text review) that supports multiple languages and integrates with Claude and OpenAI-compatible models.Last updated -19TypeScript
- -securityFlicense-qualityA custom MCP protocol service that enhances AI models by providing multilingual translation capabilities and resource management, allowing for automatic text extraction and translation through external APIs.Last updated -TypeScript