Polyglot - 翻译模型上下文协议
Polyglot 是模型上下文协议 (MCP) 的开源实现,专注于翻译服务。它使用 Claude Sonnet 3.5 提供了一种标准化的方式来处理跨多种语言的翻译请求。
支持的语言
阿拉伯语(ar)
中文(zh)
英语 (en)
法语(fr)
俄语(ru)
西班牙语(es)
Related MCP server: Lara Translate MCP Server
特征
标准化翻译请求格式
支持多个领域(法律、医疗、一般)
正式程度控制(正式/非正式)
Claude Sonnet 3.5 集成
MCP 协议服务器(通过 FastMCP)
API密钥认证
安装
使用 uv(推荐)
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install the package and its dependencies
uv pip install .
# For development, install with dev dependencies
uv pip install ".[dev]"使用 pip
# Install the package and its dependencies
pip install .
# For development, install with dev dependencies
pip install ".[dev]"配置
在项目根目录中创建一个
.env文件:
ANTHROPIC_API_KEY=your_api_key_here确保您的 API 密钥的安全,并且切勿将其提交到版本控制中。
运行 MCP 服务器
Polyglot MCP 服务器使用FastMCP通过 MCP 协议(SSE 传输)公开翻译工具和资源。
要启动服务器:
python -m polyglot.server默认情况下,服务器将使用 SSE 传输在端口 8001 上运行。
测试 MCP 服务器
使用 MCP 检查器(推荐)
安装 MCP 检查器:
npx @modelcontextprotocol/inspector打开 Inspector UI(终端将显示本地地址)。
在 Inspector UI 中设置以下内容:
运输类型: SSE
网址:
http://localhost:8001/sse(可选)如果需要,设置检查器代理地址
您现在可以通过 Inspector UI 与翻译工具和资源进行交互。
使用 Python MCP 客户端
您还可以使用 MCP Python SDK 以编程方式与服务器交互:
from mcp.client.sse import sse_client
import asyncio
async def main():
async with sse_client(url="http://localhost:8001/sse") as (read, write):
# Example: call the translate tool
request = {
"tool": "translate",
"args": {
"request": {
"version": "1.0",
"type": "translation_request",
"metadata": {
"source_language": "fr",
"target_language": "en",
"domain": "legal",
"formality": "formal",
"api_key": "your_api_key_here" # Required for authentication
},
"data": {"text": "Le contrat a été signé hier à Genève."}
}
}
}
await write(request)
response = await read()
print(response)
asyncio.run(main())协议规范
翻译请求遵循以下 JSON 结构:
{
"version": "1.0",
"type": "translation_request",
"metadata": {
"source_language": "fr",
"target_language": "en",
"domain": "legal",
"formality": "formal",
"api_key": "your_api_key_here" // Required for authentication
},
"data": {
"text": "Le contrat a été signé hier à Genève."
}
}发展
设置开发环境:
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create and activate a virtual environment
uv venv
source .venv/bin/activate # On Unix/macOS
# or
.venv\Scripts\activate # On Windows
# Install development dependencies
uv pip install ".[dev]"执照
MIT 许可证