xliff-mcp-server 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xliff_mcp_server-0.1.0/.gitignore +81 -0
- xliff_mcp_server-0.1.0/DEPLOYMENT.md +496 -0
- xliff_mcp_server-0.1.0/DOCUMENTATION.md +258 -0
- xliff_mcp_server-0.1.0/Dockerfile +46 -0
- xliff_mcp_server-0.1.0/LICENSE +21 -0
- xliff_mcp_server-0.1.0/PKG-INFO +216 -0
- xliff_mcp_server-0.1.0/QUICKSTART.md +139 -0
- xliff_mcp_server-0.1.0/README.md +171 -0
- xliff_mcp_server-0.1.0/claude_config_example.json +9 -0
- xliff_mcp_server-0.1.0/docker-compose.yml +45 -0
- xliff_mcp_server-0.1.0/examples/client_example.py +175 -0
- xliff_mcp_server-0.1.0/examples/javascript_client.js +221 -0
- xliff_mcp_server-0.1.0/install.bat +42 -0
- xliff_mcp_server-0.1.0/install.sh +58 -0
- xliff_mcp_server-0.1.0/manage_keys.py +171 -0
- xliff_mcp_server-0.1.0/nginx.conf +85 -0
- xliff_mcp_server-0.1.0/pyproject.toml +41 -0
- xliff_mcp_server-0.1.0/requirements.txt +4 -0
- xliff_mcp_server-0.1.0/setup.py +145 -0
- xliff_mcp_server-0.1.0/test_http_server.py +251 -0
- xliff_mcp_server-0.1.0/test_server.py +126 -0
- xliff_mcp_server-0.1.0/xliff_mcp/__init__.py +3 -0
- xliff_mcp_server-0.1.0/xliff_mcp/__main__.py +6 -0
- xliff_mcp_server-0.1.0/xliff_mcp/auth.py +133 -0
- xliff_mcp_server-0.1.0/xliff_mcp/http_server.py +318 -0
- xliff_mcp_server-0.1.0/xliff_mcp/models.py +41 -0
- xliff_mcp_server-0.1.0/xliff_mcp/server.py +223 -0
- xliff_mcp_server-0.1.0/xliff_mcp/tmx_processor.py +155 -0
- xliff_mcp_server-0.1.0/xliff_mcp/xliff_processor.py +347 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
*.manifest
|
|
31
|
+
*.spec
|
|
32
|
+
|
|
33
|
+
# Installer logs
|
|
34
|
+
pip-log.txt
|
|
35
|
+
pip-delete-this-directory.txt
|
|
36
|
+
|
|
37
|
+
# Unit test / coverage reports
|
|
38
|
+
htmlcov/
|
|
39
|
+
.tox/
|
|
40
|
+
.nox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
*.py,cover
|
|
48
|
+
.hypothesis/
|
|
49
|
+
.pytest_cache/
|
|
50
|
+
cover/
|
|
51
|
+
|
|
52
|
+
# Virtual environments
|
|
53
|
+
.env
|
|
54
|
+
.venv
|
|
55
|
+
env/
|
|
56
|
+
venv/
|
|
57
|
+
ENV/
|
|
58
|
+
env.bak/
|
|
59
|
+
venv.bak/
|
|
60
|
+
|
|
61
|
+
# IDEs
|
|
62
|
+
.idea/
|
|
63
|
+
.vscode/
|
|
64
|
+
*.swp
|
|
65
|
+
*.swo
|
|
66
|
+
*~
|
|
67
|
+
.DS_Store
|
|
68
|
+
|
|
69
|
+
# mypy
|
|
70
|
+
.mypy_cache/
|
|
71
|
+
.dmypy.json
|
|
72
|
+
dmypy.json
|
|
73
|
+
|
|
74
|
+
# Pyre type checker
|
|
75
|
+
.pyre/
|
|
76
|
+
|
|
77
|
+
# pytype static type analyzer
|
|
78
|
+
.pytype/
|
|
79
|
+
|
|
80
|
+
# Cython debug symbols
|
|
81
|
+
cython_debug/
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
# XLIFF MCP Server - 公共部署指南
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
本指南说明如何将XLIFF MCP服务器部署为公共服务,让其他应用程序和用户可以通过HTTP访问,而无需本地安装。
|
|
6
|
+
|
|
7
|
+
## 部署选项
|
|
8
|
+
|
|
9
|
+
### 选项1: Docker部署 (推荐)
|
|
10
|
+
|
|
11
|
+
#### 快速启动
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# 1. 构建并启动服务
|
|
15
|
+
docker-compose up -d
|
|
16
|
+
|
|
17
|
+
# 2. 检查服务状态
|
|
18
|
+
docker-compose ps
|
|
19
|
+
|
|
20
|
+
# 3. 查看日志
|
|
21
|
+
docker-compose logs -f xliff-mcp-server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### 自定义配置
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 设置API密钥保护服务
|
|
28
|
+
export XLIFF_MCP_API_KEYS="key1,key2,key3"
|
|
29
|
+
docker-compose up -d
|
|
30
|
+
|
|
31
|
+
# 或者修改 docker-compose.yml
|
|
32
|
+
environment:
|
|
33
|
+
- XLIFF_MCP_API_KEYS=your-secret-key-1,your-secret-key-2
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 选项2: 直接运行
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# 安装依赖
|
|
40
|
+
pip install -r requirements.txt
|
|
41
|
+
pip install -e .
|
|
42
|
+
|
|
43
|
+
# 设置环境变量
|
|
44
|
+
export HOST=0.0.0.0
|
|
45
|
+
export PORT=8000
|
|
46
|
+
export XLIFF_MCP_API_KEYS=your-secret-api-key
|
|
47
|
+
|
|
48
|
+
# 启动HTTP服务器
|
|
49
|
+
python -m xliff_mcp.http_server
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 选项3: 生产环境部署
|
|
53
|
+
|
|
54
|
+
#### 使用 systemd (Linux)
|
|
55
|
+
|
|
56
|
+
```ini
|
|
57
|
+
# /etc/systemd/system/xliff-mcp.service
|
|
58
|
+
[Unit]
|
|
59
|
+
Description=XLIFF MCP Server
|
|
60
|
+
After=network.target
|
|
61
|
+
|
|
62
|
+
[Service]
|
|
63
|
+
Type=simple
|
|
64
|
+
User=www-data
|
|
65
|
+
WorkingDirectory=/opt/xliff-mcp-server
|
|
66
|
+
Environment=HOST=0.0.0.0
|
|
67
|
+
Environment=PORT=8000
|
|
68
|
+
Environment=XLIFF_MCP_API_KEYS=your-secret-key
|
|
69
|
+
ExecStart=/opt/xliff-mcp-server/.venv/bin/python -m xliff_mcp.http_server
|
|
70
|
+
Restart=always
|
|
71
|
+
RestartSec=10
|
|
72
|
+
|
|
73
|
+
[Install]
|
|
74
|
+
WantedBy=multi-user.target
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 启用并启动服务
|
|
79
|
+
sudo systemctl enable xliff-mcp
|
|
80
|
+
sudo systemctl start xliff-mcp
|
|
81
|
+
sudo systemctl status xliff-mcp
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 安全配置
|
|
85
|
+
|
|
86
|
+
### 1. API密钥认证
|
|
87
|
+
|
|
88
|
+
#### 环境变量方式
|
|
89
|
+
```bash
|
|
90
|
+
export XLIFF_MCP_API_KEYS="key1,key2,key3"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### 配置文件方式
|
|
94
|
+
创建 `api_keys.json`:
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"your-api-key-1": {
|
|
98
|
+
"name": "Client 1",
|
|
99
|
+
"permissions": ["all"],
|
|
100
|
+
"rate_limit": 100
|
|
101
|
+
},
|
|
102
|
+
"your-api-key-2": {
|
|
103
|
+
"name": "Client 2",
|
|
104
|
+
"permissions": ["read"],
|
|
105
|
+
"rate_limit": 50
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 2. 反向代理配置
|
|
111
|
+
|
|
112
|
+
#### Nginx配置
|
|
113
|
+
```nginx
|
|
114
|
+
server {
|
|
115
|
+
listen 80;
|
|
116
|
+
server_name your-domain.com;
|
|
117
|
+
|
|
118
|
+
# Rate limiting
|
|
119
|
+
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
|
|
120
|
+
|
|
121
|
+
location /mcp {
|
|
122
|
+
limit_req zone=api burst=20 nodelay;
|
|
123
|
+
|
|
124
|
+
proxy_pass http://localhost:8000;
|
|
125
|
+
proxy_set_header Host $host;
|
|
126
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
127
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
128
|
+
|
|
129
|
+
# CORS headers
|
|
130
|
+
add_header Access-Control-Allow-Origin "*" always;
|
|
131
|
+
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS" always;
|
|
132
|
+
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-API-Key" always;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Apache配置
|
|
138
|
+
```apache
|
|
139
|
+
<VirtualHost *:80>
|
|
140
|
+
ServerName your-domain.com
|
|
141
|
+
|
|
142
|
+
ProxyPass /mcp http://localhost:8000/mcp
|
|
143
|
+
ProxyPassReverse /mcp http://localhost:8000/mcp
|
|
144
|
+
|
|
145
|
+
# CORS headers
|
|
146
|
+
Header always set Access-Control-Allow-Origin "*"
|
|
147
|
+
Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS"
|
|
148
|
+
Header always set Access-Control-Allow-Headers "Authorization, Content-Type, X-API-Key"
|
|
149
|
+
</VirtualHost>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 3. HTTPS配置
|
|
153
|
+
|
|
154
|
+
使用 Let's Encrypt 免费SSL证书:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# 安装 certbot
|
|
158
|
+
sudo apt install certbot python3-certbot-nginx
|
|
159
|
+
|
|
160
|
+
# 获取证书
|
|
161
|
+
sudo certbot --nginx -d your-domain.com
|
|
162
|
+
|
|
163
|
+
# 自动续期
|
|
164
|
+
sudo crontab -e
|
|
165
|
+
# 添加: 0 12 * * * /usr/bin/certbot renew --quiet
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## 云平台部署
|
|
169
|
+
|
|
170
|
+
### AWS ECS
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
# ecs-task-definition.json
|
|
174
|
+
{
|
|
175
|
+
"family": "xliff-mcp-server",
|
|
176
|
+
"networkMode": "awsvpc",
|
|
177
|
+
"requiresCompatibilities": ["FARGATE"],
|
|
178
|
+
"cpu": "256",
|
|
179
|
+
"memory": "512",
|
|
180
|
+
"executionRoleArn": "arn:aws:iam::account:role/ecsTaskExecutionRole",
|
|
181
|
+
"containerDefinitions": [
|
|
182
|
+
{
|
|
183
|
+
"name": "xliff-mcp",
|
|
184
|
+
"image": "your-account.dkr.ecr.region.amazonaws.com/xliff-mcp:latest",
|
|
185
|
+
"portMappings": [
|
|
186
|
+
{
|
|
187
|
+
"containerPort": 8000,
|
|
188
|
+
"protocol": "tcp"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"environment": [
|
|
192
|
+
{
|
|
193
|
+
"name": "XLIFF_MCP_API_KEYS",
|
|
194
|
+
"value": "your-secret-keys"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"logConfiguration": {
|
|
198
|
+
"logDriver": "awslogs",
|
|
199
|
+
"options": {
|
|
200
|
+
"awslogs-group": "/ecs/xliff-mcp",
|
|
201
|
+
"awslogs-region": "us-east-1",
|
|
202
|
+
"awslogs-stream-prefix": "ecs"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Google Cloud Run
|
|
211
|
+
|
|
212
|
+
```yaml
|
|
213
|
+
# cloudrun.yaml
|
|
214
|
+
apiVersion: serving.knative.dev/v1
|
|
215
|
+
kind: Service
|
|
216
|
+
metadata:
|
|
217
|
+
name: xliff-mcp-server
|
|
218
|
+
spec:
|
|
219
|
+
template:
|
|
220
|
+
metadata:
|
|
221
|
+
annotations:
|
|
222
|
+
autoscaling.knative.dev/maxScale: "10"
|
|
223
|
+
spec:
|
|
224
|
+
containers:
|
|
225
|
+
- image: gcr.io/your-project/xliff-mcp:latest
|
|
226
|
+
ports:
|
|
227
|
+
- containerPort: 8000
|
|
228
|
+
env:
|
|
229
|
+
- name: XLIFF_MCP_API_KEYS
|
|
230
|
+
value: "your-secret-keys"
|
|
231
|
+
resources:
|
|
232
|
+
limits:
|
|
233
|
+
cpu: "1"
|
|
234
|
+
memory: "512Mi"
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# 部署到 Cloud Run
|
|
239
|
+
gcloud run deploy xliff-mcp-server \
|
|
240
|
+
--image gcr.io/your-project/xliff-mcp:latest \
|
|
241
|
+
--platform managed \
|
|
242
|
+
--region us-central1 \
|
|
243
|
+
--allow-unauthenticated \
|
|
244
|
+
--set-env-vars XLIFF_MCP_API_KEYS=your-keys
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Heroku
|
|
248
|
+
|
|
249
|
+
```yaml
|
|
250
|
+
# app.json
|
|
251
|
+
{
|
|
252
|
+
"name": "xliff-mcp-server",
|
|
253
|
+
"description": "XLIFF MCP Server for translation processing",
|
|
254
|
+
"repository": "https://github.com/your-username/xliff-mcp-server",
|
|
255
|
+
"logo": "https://your-logo-url.com/logo.png",
|
|
256
|
+
"keywords": ["mcp", "xliff", "translation"],
|
|
257
|
+
"env": {
|
|
258
|
+
"XLIFF_MCP_API_KEYS": {
|
|
259
|
+
"description": "Comma-separated API keys for authentication",
|
|
260
|
+
"value": "your-secret-keys"
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
"formation": {
|
|
264
|
+
"web": {
|
|
265
|
+
"quantity": 1,
|
|
266
|
+
"size": "hobby"
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
"buildpacks": [
|
|
270
|
+
{
|
|
271
|
+
"url": "heroku/python"
|
|
272
|
+
}
|
|
273
|
+
]
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
# 部署到 Heroku
|
|
279
|
+
heroku create your-xliff-mcp-server
|
|
280
|
+
heroku config:set XLIFF_MCP_API_KEYS=your-secret-keys
|
|
281
|
+
git push heroku main
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 客户端连接
|
|
285
|
+
|
|
286
|
+
### Claude Desktop配置
|
|
287
|
+
|
|
288
|
+
```json
|
|
289
|
+
{
|
|
290
|
+
"mcpServers": {
|
|
291
|
+
"xliff-processor-remote": {
|
|
292
|
+
"command": "python",
|
|
293
|
+
"args": ["-c", "
|
|
294
|
+
import asyncio
|
|
295
|
+
from mcp import ClientSession
|
|
296
|
+
from mcp.client.streamable_http import streamablehttp_client
|
|
297
|
+
|
|
298
|
+
async def main():
|
|
299
|
+
async with streamablehttp_client('https://your-domain.com/mcp') as (r, w, _):
|
|
300
|
+
async with ClientSession(r, w) as session:
|
|
301
|
+
await session.initialize()
|
|
302
|
+
# MCP处理逻辑
|
|
303
|
+
|
|
304
|
+
asyncio.run(main())
|
|
305
|
+
"]
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 其他MCP客户端
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
# Python客户端
|
|
315
|
+
import asyncio
|
|
316
|
+
from mcp import ClientSession
|
|
317
|
+
from mcp.client.streamable_http import streamablehttp_client
|
|
318
|
+
|
|
319
|
+
async def connect_to_remote_mcp():
|
|
320
|
+
async with streamablehttp_client('https://your-domain.com/mcp') as (r, w, _):
|
|
321
|
+
async with ClientSession(r, w) as session:
|
|
322
|
+
await session.initialize()
|
|
323
|
+
|
|
324
|
+
result = await session.call_tool('process_xliff', {
|
|
325
|
+
'file_name': 'test.xliff',
|
|
326
|
+
'content': xliff_content,
|
|
327
|
+
'api_key': 'your-api-key'
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
return result
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
```javascript
|
|
334
|
+
// JavaScript/Node.js客户端
|
|
335
|
+
const { Client } = require('@modelcontextprotocol/sdk/client');
|
|
336
|
+
const { StreamableHttpTransport } = require('@modelcontextprotocol/sdk/client/streamablehttp');
|
|
337
|
+
|
|
338
|
+
async function connectToMCP() {
|
|
339
|
+
const transport = new StreamableHttpTransport('https://your-domain.com/mcp');
|
|
340
|
+
const client = new Client({ name: "xliff-client", version: "1.0.0" });
|
|
341
|
+
|
|
342
|
+
await client.connect(transport);
|
|
343
|
+
|
|
344
|
+
const result = await client.callTool({
|
|
345
|
+
name: 'process_xliff',
|
|
346
|
+
arguments: {
|
|
347
|
+
file_name: 'test.xliff',
|
|
348
|
+
content: xliffContent,
|
|
349
|
+
api_key: 'your-api-key'
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
return result;
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## 监控和维护
|
|
358
|
+
|
|
359
|
+
### 1. 健康检查
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
# 检查服务状态
|
|
363
|
+
curl http://your-domain.com/mcp/health
|
|
364
|
+
|
|
365
|
+
# 检查工具列表
|
|
366
|
+
curl -X POST http://your-domain.com/mcp \
|
|
367
|
+
-H "Content-Type: application/json" \
|
|
368
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### 2. 日志监控
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
# Docker日志
|
|
375
|
+
docker-compose logs -f xliff-mcp-server
|
|
376
|
+
|
|
377
|
+
# 系统日志
|
|
378
|
+
sudo journalctl -u xliff-mcp -f
|
|
379
|
+
|
|
380
|
+
# 访问日志分析
|
|
381
|
+
tail -f /var/log/nginx/access.log | grep "/mcp"
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### 3. 性能监控
|
|
385
|
+
|
|
386
|
+
```python
|
|
387
|
+
# 添加到http_server.py
|
|
388
|
+
import time
|
|
389
|
+
from functools import wraps
|
|
390
|
+
|
|
391
|
+
def monitor_performance(func):
|
|
392
|
+
@wraps(func)
|
|
393
|
+
def wrapper(*args, **kwargs):
|
|
394
|
+
start_time = time.time()
|
|
395
|
+
result = func(*args, **kwargs)
|
|
396
|
+
duration = time.time() - start_time
|
|
397
|
+
logger.info(f"Tool {func.__name__} took {duration:.2f}s")
|
|
398
|
+
return result
|
|
399
|
+
return wrapper
|
|
400
|
+
|
|
401
|
+
# 应用到所有工具
|
|
402
|
+
@mcp.tool()
|
|
403
|
+
@monitor_performance
|
|
404
|
+
def process_xliff(file_name: str, content: str, api_key: Optional[str] = None) -> str:
|
|
405
|
+
# ...
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### 4. 错误处理和限流
|
|
409
|
+
|
|
410
|
+
```python
|
|
411
|
+
# 添加到auth.py
|
|
412
|
+
class ErrorHandler:
|
|
413
|
+
@staticmethod
|
|
414
|
+
def handle_error(error: Exception) -> dict:
|
|
415
|
+
if isinstance(error, ValueError):
|
|
416
|
+
return {"error": "Invalid input", "code": 400}
|
|
417
|
+
elif isinstance(error, PermissionError):
|
|
418
|
+
return {"error": "Access denied", "code": 403}
|
|
419
|
+
else:
|
|
420
|
+
return {"error": "Internal server error", "code": 500}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
## 费用预估
|
|
424
|
+
|
|
425
|
+
### 小规模部署 (< 1000请求/天)
|
|
426
|
+
- **Heroku Hobby**: $7/月
|
|
427
|
+
- **Google Cloud Run**: $0-5/月
|
|
428
|
+
- **AWS ECS Fargate**: $10-15/月
|
|
429
|
+
|
|
430
|
+
### 中规模部署 (< 10000请求/天)
|
|
431
|
+
- **Digital Ocean App Platform**: $15-25/月
|
|
432
|
+
- **AWS ECS**: $30-50/月
|
|
433
|
+
- **Google Cloud Run**: $10-30/月
|
|
434
|
+
|
|
435
|
+
### 大规模部署 (> 100000请求/天)
|
|
436
|
+
- **AWS ECS + ALB**: $100-300/月
|
|
437
|
+
- **Google Cloud Run + Load Balancer**: $80-250/月
|
|
438
|
+
- **自建服务器**: $50-150/月
|
|
439
|
+
|
|
440
|
+
## 故障排除
|
|
441
|
+
|
|
442
|
+
### 常见问题
|
|
443
|
+
|
|
444
|
+
1. **CORS错误**
|
|
445
|
+
```bash
|
|
446
|
+
# 检查CORS配置
|
|
447
|
+
curl -H "Origin: http://example.com" \
|
|
448
|
+
-H "Access-Control-Request-Method: POST" \
|
|
449
|
+
-X OPTIONS http://your-domain.com/mcp
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
2. **认证失败**
|
|
453
|
+
```bash
|
|
454
|
+
# 测试API密钥
|
|
455
|
+
curl -X POST http://your-domain.com/mcp \
|
|
456
|
+
-H "Content-Type: application/json" \
|
|
457
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_server_info","arguments":{"api_key":"your-key"}}}'
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
3. **性能问题**
|
|
461
|
+
```bash
|
|
462
|
+
# 监控资源使用
|
|
463
|
+
docker stats xliff-mcp-server
|
|
464
|
+
|
|
465
|
+
# 检查内存使用
|
|
466
|
+
docker exec xliff-mcp-server ps aux
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
4. **连接超时**
|
|
470
|
+
```bash
|
|
471
|
+
# 调整超时设置
|
|
472
|
+
docker-compose.yml:
|
|
473
|
+
environment:
|
|
474
|
+
- TIMEOUT=300
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### 日志级别配置
|
|
478
|
+
|
|
479
|
+
```python
|
|
480
|
+
# 在http_server.py中设置
|
|
481
|
+
import os
|
|
482
|
+
log_level = os.getenv("LOG_LEVEL", "INFO")
|
|
483
|
+
logging.basicConfig(level=getattr(logging, log_level))
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
## 总结
|
|
487
|
+
|
|
488
|
+
通过以上配置,您的XLIFF MCP服务器将能够:
|
|
489
|
+
|
|
490
|
+
1. ✅ **公开访问** - 任何支持MCP的应用都可以连接
|
|
491
|
+
2. ✅ **安全认证** - API密钥保护和速率限制
|
|
492
|
+
3. ✅ **高可用性** - 负载均衡和自动重启
|
|
493
|
+
4. ✅ **可扩展性** - 支持Docker和云平台部署
|
|
494
|
+
5. ✅ **易于维护** - 完整的监控和日志系统
|
|
495
|
+
|
|
496
|
+
现在其他开发者可以通过简单的HTTP连接使用您的XLIFF处理服务,无需本地部署! 🚀
|