Python最佳实践MCP服务

提供Python编码最佳实践和指南的MCP服务器,包含交互式工具、资源和提示,适用于AI助手和开发者。

  • by davecthomas
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 davecthomas/mcp_python

使用说明

Python最佳实践MCP服务器

一个模型上下文协议(MCP)服务器,为AI助手提供Python编码最佳实践和指南。

概述

此MCP服务器公开了交互式工具、资源和提示,用于从涵盖通用Python编码和FastAPI开发的知识库中搜索和检索精心策划的Python编码标准。

特性

工具

  • search_practices -按关键字搜索最佳实践
  • get_topic -检索特定主题的详细信息
  • list_categories -列出所有可用类别
  • get_category -获取一个类别中的所有主题
  • list_all_topics -获取所有主题的完整概述

资源

  • bestpractices://catalog -完整的最佳实践目录
  • bestpractices://category/{category_name} -特定类别实践
  • bestpractices://topic/{category}/{topic_name} -具体主题内容

提示

  • review_code -根据最佳实践审查代码
  • suggest_improvements -对代码提出具体改进建议
  • explain_practice -获取最佳实践的详细解释

安装

通过uvx安装:

uvx bestpractices-mcp-server

或者从源代码安装:

pip install -e .

配置

开发 IDE

添加到 .kiro/settings/mcp.json:

{
  "mcpServers": {
    "python-best-practices": {
      "command": "uvx",
      "args": ["bestpractices-mcp-server"],
      "env": {
        "BEST_PRACTICES_JSON_PATH": "data/python_best_practices.json",
        "LOG_LEVEL": "INFO"
      }
    }
  }
}

克劳德桌面(macOS)

添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "python-best-practices": {
      "command": "uvx",
      "args": ["bestpractices-mcp-server"],
      "env": {
        "BEST_PRACTICES_JSON_PATH": "/absolute/path/to/data/python_best_practices.json",
        "LOG_LEVEL": "INFO"
      }
    }
  }
}

备注:Claude Desktop要求文件引用的绝对路径。

环境变量

  • BEST_PRACTICES_JSON_PATH -JSON文件的路径(默认值: data/python_best_practices.json)
  • MAX_SEARCH_RESULTS -最大搜索结果数(默认值: 50)
  • LOG_LEVEL -日志记录级别(默认值: INFO)
  • ENABLE_CACHING -启用/禁用缓存(默认值: true)

发展

安装开发依赖项:

pip install -e ".[dev]"

运行测试:

pytest

运行基于属性的测试:

pytest tests/test_properties.py

项目结构

bestpractices_mcp_server/
├── src/
│   └── bestpractices_mcp_server/
│       ├── __init__.py
│       ├── server.py              # Main MCP server
│       ├── data_layer.py          # Data loading and caching
│       ├── business_logic.py      # Search, retrieval, formatting
│       └── models.py              # Data models
├── tests/
│   ├── test_data_layer.py
│   ├── test_business_logic.py
│   ├── test_server.py
│   └── test_properties.py         # Property-based tests
├── data/
│   └── python_best_practices.json
├── config/
│   ├── kiro_mcp.json              # Example Kiro configuration
│   └── claude_desktop_config.json # Example Claude Desktop configuration
├── pyproject.toml
├── README.md
└── .env.example

故障排除

开发 IDE

  • 确保MCP服务器列在 .kiro/settings/mcp.json
  • 检查Kiro日志中的连接错误
  • 验证JSON文件路径是否正确

克劳德桌面版

  • 确保在配置中使用绝对路径
  • 配置更改后重新启动Claude Desktop
  • 检查 ~/Library/Logs/Claude/mcp*.log 对于错误

许可证

麻省理工学院