使用说明
受信任的Python MCP工具
最小计算平台(MCP)工具 continue.dev VSCode中的插件,用于运行Python脚本、执行linting(使用 ruff),类型检查(使用 ty 来自astral sh)和安全扫描(使用 bandit).它应该与其他工具配合得很好
特性
- 在Docker容器中独立运行Python 3.11代码。
- 使用以下命令检查Python代码样式和lint问题
ruff. - 使用检查类型错误
ty. - 使用执行安全分析
bandit. - 为每个会话使用隔离的临时目录进行缓存和文件管理。
- 完全在Docker容器内运行,以确保沙盒并防止未经授权的文件系统访问。
快速入门
安装 uvx。不需要管理权限,但您需要将其永久添加到您的路径中(例如 ~/.local/bin)
按原样使用 uvx mcp-trusted-python.
如果代理始终可以使用额外的库,则将其放入需求文件中(例如 requirements-science.txt).然后,替换你喜欢的Python解释器,
uvx create --python python3.11 mcp-trusted-python
uvx shell mcp-trusted-python
uv pip install mcp-trusted-python
uv pip install -r requirements-science.txt
许可证
麻省理工学院
Python开发规则
将这些添加到工具的规则中以包含 *.py 文件夹。对于continue.dev,这些可以进入 ~/.continue/rules/trusted-python-rules.md.规则
## Test-Driven Development
- Write tests FIRST before implementation code
- Use `list_installed_packages()` to check available testing frameworks (pytest recommended)
- Run tests with `run_python()` to verify behavior before suggesting code
- Aim for >80% code coverage on business logic
## Code Quality & Validation
- Always `check_python()` and `security_scan()` before presenting code
- Use type hints for all function signatures (Python 3.11+)
- Keep cyclomatic complexity ≤3 per function (max 3 decision points/branches)
- Extract complex logic into well-named helper functions
- Write Pythonic, idiomatic code when it improves clarity
## SOLID Principles
- **Single Responsibility**: One function = one clear purpose
- **Open/Closed**: Use protocols/ABC for extensibility
- **Liskov Substitution**: Subtypes must be substitutable
- **Interface Segregation**: Small, focused interfaces over large ones
- **Dependency Inversion**: Depend on abstractions (protocols), inject dependencies
## Security & Configuration
- Use `python-dotenv` for sensitive values, never hardcode secrets
- Use stdlib `hashlib` and `secrets` for cryptography, avoid third-party crypto libs
- Validate all external inputs with type hints + runtime validation (pydantic recommended)
- Web applications always include CORS support and disable debugging at run time
## Architecture Patterns
- Separate concerns: handlers → services → repositories
- Use dataclasses/pydantic models for data structures
- Implement error handling at boundaries with custom exceptions
- Document public APIs with docstrings (Google/NumPy style)
- Prefer composition over inheritance
## Workflow
1. Query `list_installed_packages()` to verify available dependencies
2. Write failing test
3. Implement minimal code to pass test
4. Run `check_python()` and `security_scan()`
5. Refactor while keeping tests green
6. Present validated, tested code
