MCP Corrector de Català (多语种)
一个MCP(模型上下文协议)服务器,用于纠正包含英语技术术语和代码的加泰罗尼亚语文本。专为将加泰罗尼亚语散文与英语编程词汇和代码块相结合的教材而设计。
特性
- 混合语言支持:处理内嵌英语技术术语的加泰罗尼亚语散文
- 代码感知:自动检测和跳过代码块、内联代码和编程模式
- 评论检查:提取代码块中的注释并进行拼写检查
- 语言检测:对评论语言(加泰罗尼亚语/英语)进行分类,以便正确路由
- 精确的偏移:所有更正都精确地映射到原始文件位置
- 加泰罗尼亚语变体:支持通用、巴伦西亚和巴利阿里变体
快速开始
# Install and setup
uv sync && uv pip install -e .
docker compose up -d
# Run the MCP server
uv run python -m corrector.server
# Run tests
uv run pytest tests/ -v建筑
Claude (Code CLI or claude.ai)
→ MCP Server (src/corrector/server.py, Python + FastMCP)
→ LanguageTool Docker (localhost:8011)三相管道
- 第1阶段-冲裁:检测代码块和内联代码模式,将其留空以防止误报
- 第2阶段-双路由:将加泰罗尼亚语文本路由到ca ES,将检测到的英语术语路由到en-US
- 第3阶段-评论:从代码块中提取注释,对语言进行分类,单独检查
安装
先决条件
- Python 3.11+
- Docker(用于LanguageTool)
- 紫外线 包管理器
设置
# Clone the repository
git clone
cd mcp-corrector-dual-cat-en
# Install dependencies
uv sync
# Start LanguageTool Docker
docker compose up -d
# Verify LanguageTool is running
curl http://localhost:8011/v2/languages | head使用克劳德代码注册
claude mcp add corrector-catala -- uv run python -m corrector.server用法
MCP工具
corregir_text_mixt (推荐)
对加泰罗尼亚语/英语混合文本和代码进行全面的多语言更正。
corregir_text_mixt(
text: str, # Text to correct (prose, Markdown, or full files)
variant: str = "general", # "general", "valencia", or "balear"
picky: bool = False, # Enable strict style rules
debug: bool = False, # Include debug info in response
format_json: bool = True # Return JSON or plain text
)示例输入:
El `callback` es crida quan el *promis* es resol.
// Això carrega les dades fetch(url).then(data => { console.log(data); // Log the respons });
Detected errors:
promis→promise(English term, checked with en-US)Aixòin comment → checked with ca-ESrespons→response(English comment typo)
corregir_text
Simple monolingual Catalan correction (no code handling).
verificar_servidor
Check if LanguageTool Docker is running.
llistar_idiomes
List available languages on the LanguageTool server.
Running the Server
# stdio transport (for Claude Code CLI)
uv run python -m corrector.server
# HTTP transport (for claude.ai via ngrok)
uv run python -m corrector.server --transport streamable-http --port 8000配置
| 环境变量 | 默认值 | 描述 |
|---|---|---|
LANGUAGETOOL_URL | http://localhost:8011 | LanguageTool服务器URL |
CORRECTOR_LANG | ca-ES | 默认语言变体 |
CORRECTOR_TIMEOUT | 30 | HTTP超时(秒) |
代码检测模式
预处理器检测并清空这些模式以防止误报:
| 模式 | 示例 | 检测 |
|---|---|---|
| 倒勾 | ` variable ` | 显式标记 |
| 点符号 | console.log | 对象访问 |
| 函数调用 | forEach(x) | 之前没有空间 ( |
| camelCase | myVariable | 案例转换 |
| 尖叫_蛇 | MAX_VALUE | 常量 |
重要:加泰罗尼亚语括号表达,如 funció (que és important) 没有空白,因为括号前有空格。
英语术语词典
这 data/terms_en.txt 该文件包含约980个技术术语。系统:
- 让LanguageTool标记未知单词
- 检查标记的单词是否在英语词典中
- 如果是:前往en-US进行拼写检查的路线
- 如果否:保持为加泰罗尼亚语错误
模糊匹配(编辑距离1)捕获拼写错误的英语术语,如 calback → callback.
发展
运行测试
# Run all tests (requires LanguageTool Docker running)
uv run pytest tests/ -v
# Run specific phase tests
uv run pytest tests/test_phase1.py -v
uv run pytest tests/test_phase2.py -v
uv run pytest tests/test_phase3.py -v项目结构
├── src/
│ └── corrector/
│ ├── __init__.py # Package exports
│ ├── server.py # MCP server and tool definitions
│ ├── preprocessor.py # Phase 1: code detection and blanking
│ ├── text_spans.py # Span utilities (merge, blank, filter)
│ ├── english_detector.py # Phase 2: English dictionary and fuzzy matching
│ ├── match_filter.py # Phase 2: match partitioning and remapping
│ ├── comment_extractor.py # Phase 3: string-aware comment parser
│ └── comment_checker.py # Phase 3: comment batching and routing
├── data/
│ └── terms_en.txt # English technical terms dictionary
├── tests/
│ ├── conftest.py # pytest configuration
│ ├── test_phase1.py # Blanking tests
│ ├── test_phase2.py # English term routing tests
│ ├── test_phase3.py # Comment extraction tests
│ └── test_document_phases.py # Integration tests
├── docs/
│ ├── CLAUDE.md # Project instructions
│ └── plans/ # Implementation design documents
├── pyproject.toml
├── docker-compose.yml # LanguageTool Docker config
└── README.md依赖项
fastmcp-MCP服务器框架httpx-异步HTTP客户端lingua-language-detector-评论语言检测rapidfuzz-模糊字符串匹配
许可证
麻省理工学院
