文本预处理MCP服务器
一种模型上下文协议(MCP)服务器,为CSV数据集提供自动化的综合文本预处理功能。该服务器使AI助手能够对CSV文件中存储的文本数据执行各种文本清理和转换任务。
核心功能
🧹 基本文本清理
- 小写:将文本转换为小写
- 标点符号删除:从文本中删除标点符号
- 表情符号删除:清除表情符号字符
- 表情移除:移除基于文本的表情符号(:)、:(等)
🔤 高级文本处理
- 删除停用词:过滤掉常见的停用词(“the”、“and”、“is”等)
- 词干:使用波特词干器将单词还原为词根形式
- Lemmatization:使用WordNet Lemmatizer将单词转换为字典基础形式
安装
先决条件
- Python 3.11或更高版本(必填)
- uv(推荐)或pip包管理器
来自紫外线源(推荐)
# Clone the repository
git clone https://github.com/ayyu-ssh/text-preprocessing-MCP-server.git
cd text-preprocessing-MCP-server
# Install with uv
uv sync
# Or install in development mode
uv pip install -e .uv开发设置
# Clone and set up for development
git clone https://github.com/ayyu-ssh/text-preprocessing-MCP-server.git
cd text-preprocessing-MCP-server
# Sync dependencies (creates venv automatically)
uv sync
# Activate the virtual environment
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Download required NLTK data
uv run python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords'); nltk.download('wordnet')"依赖项
此软件包会自动安装以下依赖项:
- 人择性≥0.57.1 -Anthropic API客户集成
- fastmcp≥2.8.1 -快速MCP服务器实施
- mcp服务器≥0.1.4 -核心MCP服务器组件
- mcp\[cli,fastmcp\]≥1.9.4 -支持CLI和FastMCP的MCP
- nltk≥3.9.1 -用于文本处理的自然语言工具包
- 熊猫≥2.3.0 -数据操作和分析
- python dotenv≥1.1.0 -环境变量管理
- scikit-learn≥1.7.0 -机器学习工具
🚀 用法
启动服务器
使用紫外线
# Run the MCP server directly
uv run server.py服务器将启动并向连接的LLM公开主要工具。
使用CLI
交互模式
# using custom client
uv run client.py🔧 客户端配置
{
"mcpServers": {
"TextPreprocessingMCP": {
"command": "uv",
"args": [
"--directory",
"path/to/server.py",
"run",
"server.py"
]
}
}
}上述配置也可用作Claude Desktop的配置。
文件结构
text-preprocessing-mcp/
├── server.py # Main MCP server implementation with tools
├── functions.py # Preprocessing functions source code
├── client.py # Implementation of custom client
├── requirements.txt # Python dependencies
├── pyproject.toml # Configutation file
└── README.md # This file可用功能
1.CSV操作
- read_csv(file_path)-读取csv文件并返回基本信息
- use_cols(file_path,cols)-选择特定列并保存到temp.csv
2.文本清理功能
- 小写(col,file_path)-将文本转换为小写
- remove_punctuation(col,file_path)-删除标点符号
- remove_emojis(col,file_path)-删除表情符号字符
- remove_emoticons(col,file_path)-删除文本表情符号
3.文本处理功能
- remove_stopwords(col,file_path)-删除常见的停用词
- 词干(col,file_path)-对单词应用词干
- 引理(col,file_path)-对单词进行引理
4.分析功能
- get_words_count(col,file_path)-获取词频计数
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
