Python LFT(Lint、Format、Test)-MCP服务器
一个现代的模块化Python开发工具包,通过以下方式公开linting、格式化和测试功能 模型上下文协议(MCP)。采用干净的架构和现代设计模式构建,用于专业开发工作流程。
](https://github.com/Agent-Hellboy/python-lft-mcp) 
 
一个全面的MCP服务器,为Python项目提供智能linting、格式化和测试功能。它自动检测项目配置,并使LLM能够对代码质量工具做出明智的决策。
特性
- 全面配置检测 -分析70多个Python生态系统配置文件
- 智能工具集成 -支持褶皱、黑色、pytest、mypy、pylint等
- LLM优化 -为智能工具选择提供详细的配置数据
- 跨项目支持 -适用于任何Python项目结构
- 快速可靠 -采用现代异步Python和MCP协议构建
快速开始
安装
# Install from PyPI (when published)
pip install python-lft-mcp
# Or install with all optional tool dependencies
pip install python-lft-mcp[tools]MCP客户端配置
安装后,生成MCP配置:
# Generate configuration for your MCP client
python-lft-config这将显示您需要添加到MCP客户端的配置。
Cursor IDE的快速配置
增添 ~/.cursor/mcp.json:
{
"mcpServers": {
"python-lft": {
"command": "python",
"args": ["-m", "python_lft"],
"description": "Python LFT MCP Server"
}
}
}对于其他MCP客户端
- 跑
python-lft-config获取完整说明 - 看
examples/mcp-config.json有关更多配置选项
开发安装
# Clone the repository
git clone https://github.com/Agent-Hellboy/python-lft-mcp.git
cd python-lft-mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e ".[dev]"有关开发配置,请参阅 examples/README.md.
用法
1.检测项目配置
# LLM calls this first to understand the project
detect_workspace_tools(work_dir="/path/to/project")2.使用项目设置执行工具
# LLM uses the detected configuration
lint(
target="all",
exact_tool="ruff",
tool_config={"line-length": 88, "target-version": "py39"},
work_dir="/path/to/project"
)
format_code(
exact_tool="black",
tool_config={"line-length": 88, "target-version": ["py39"]},
work_dir="/path/to/project"
)
test(
exact_tool="pytest",
tool_config={"testpaths": ["tests"], "addopts": "-v"},
work_dir="/path/to/project"
)支持的工具
棉毛
- 颈毛 -快速Python linter
- 薄片8 -风格指南执行
- 皮林 -代码分析
- mypy -静态类型检查
- 强盗 -安全防盗
- pydoc风格 -Docstring约定
使用格式器
- 黑色 -代码格式
- 颈毛 -快速格式化
- isort -导入排序
- autopep8 -PEP 8格式
- 雅普夫 -代码格式
试车手
- pytest -测试框架
- 鼻子2 -单元测试
- 单位测试 -内置测试
支持的配置文件
pyproject.toml-现代Python项目配置setup.cfg-旧版安装工具配置tox.ini-测试自动化pytest.ini-Pytest配置.flake8-Flake8设置.pylintrc-Pylint配置mypy.ini-MyPy设置requirements.txt-依赖关系.pre-commit-config.yaml-预提交挂钩- 还有60多个Python生态系统配置!
发展
设置开发环境
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks (if available)
pre-commit installTox开发工作流
我们使用 毒素 对于标准化的开发工作流程:
# Run tests across all supported Python versions
tox
# Run specific environments
tox -e lint # Run linting with ruff
tox -e format # Format code with ruff (includes import sorting)
tox -e format-check # Check formatting without changes
tox -e type # Type checking with mypy
tox -e coverage # Run tests with coverage reporting
# Run comprehensive testing
tox -e all # Lint + format-check + type + test + coverage
# Test specific Python version
tox -e py39 # Test with Python 3.9
tox -e py312 # Test with Python 3.12
# Clean build artifacts
tox -e clean
# Build package for distribution
tox -e build手动工具使用
# Run tests
pytest
# Run linting
ruff check .
# Type checking
mypy python_lft/
# Format code
ruff check --fix . # Fix linting issues and sort imports
ruff format . # Format code
# Run tests with coverage
pytest --cov=python_lft建筑
python_lft/
├── app.py # MCP server creation
├── tools_api.py # MCP tool definitions
├── services/
│ ├── workspace.py # Configuration detection
│ ├── orchestrator.py # Tool execution coordination
│ └── runners.py # Command execution
├── executors/ # Tool-specific executors
├── core/ # Core models and interfaces
└── config/ # Constants and configuration贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 添加测试
- 运行测试套件:
tox -e all - 提交拉取请求
CI/CD
该项目使用GitHub Actions进行持续集成:
- 棉绒:跑步
ruff check每次推送/PR - 测试:在每次推送/PR时跨Python 3.9-3.12运行测试套件
- CI公司:全面的质量检查(皮棉+格式+类型+测试+构建)
- 发布:在版本标签上自动发布到PyPI和GitHub版本
在合并pull请求之前,必须通过所有检查。
许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
仓库
有关最新更新、问题和贡献,请访问:
