关于 Neurodev Mcp
Neurodev Mcp 是面向 Python 开发者的 MCP 服务,提供代码审查、pytest 测试生成与执行,以及代码格式化。它结合静态分析工具和 AST 分析,并支持 STDIO 与 SSE 传输。
主要功能
- 01多工具静态代码审查
- 02AST 驱动的 pytest 生成
- 03测试执行与覆盖率报告
- 04Black 和 autopep8 格式化
- 05支持 STDIO 与 SSE
适用场景
- 01检查 Python 代码质量与安全问题
- 02为函数和类生成边界测试
- 03运行测试并查看覆盖率
- 04将代码格式化为 PEP 8 风格
MCP 相关
该 MCP 服务向客户端提供代码审查、测试生成、测试执行和格式化工具。可使用 STDIO 连接本地客户端,也可通过 SSE 支持 Web 集成。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
🧠 NeuroDev MCP Server
智能代码分析、测试生成与执行
这是一款功能强大的模型上下文协议(MCP)服务,通过 AI 驱动的代码审查、智能测试生成和全面的测试执行,为你的 Python 开发工作流注入强大动力。
✨ 功能
🔍 代码审查
|
🧪 测试生成
|
▶️ 测试执行
|
🎨 代码格式化
|
📦 安装
快速安装
```bash
# Clone the repository
git clone https://github.com/ravikant1918/neurodev-mcp.git
cd neurodev-mcp
# Create virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
# Install the package
pip install -e .
\`\`\`
### **Verify Installation**
\`\`\`bash
# Run tests (should show 15/15 passing)
python test_installation.py
# Test the server
python -m neurodev_mcp.server
\`\`\`
<details>
<summary><b>📁 Project Structure</b> (click to expand)</summary>
\`\`\`
neurodev-mcp/
├─ neurodev_mcp/ # 📦 Main package
│ ├─ __init__.py # Package exports
│ ├─ server.py # MCP server entry point
│ ├─ analyzers/ # 🔍 Code analysis
│ │ ├─ __init__.py
│ │ └─ code_analyzer.py # Multi-tool static analysis
│ ├─ generators/ # 🧪 Test generation
│ │ ├─ __init__.py
│ │ └─ test_generator.py # AST-based test creation
│ └─ executors/ # ▶️ Test execution
│ ├─ __init__.py
│ └─ test_executor.py # Test running & formatting
├─ pyproject.toml # Project configuration
├─ README.md # This file
├─ test_installation.py # Installation validator
├─ examples.py # Usage examples
└─ requirements.txt # Dependencies
🚀 快速入门
步骤 1:配置 MCP 客户端
🖥️ Claude Desktop
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"neurodev-mcp": {
"command": "/absolute/path/to/neurodev-mcp/.venv/bin/python",
"args": ["-m", "neurodev_mcp.server"]
}
}
}
💡 提示: 将
/absolute/path/to/neurodev-mcp替换为你的实际路径
🔧 Cline (VSCode)
添加到 MCP 设置中:
{
"neurodev-mcp": {
"command": "python",
"args": ["-m", "neurodev_mcp.server"]
}
}
🐍 独立使用
直接运行服务:
# Using the module
python -m neurodev_mcp.server
# Or as a command (if installed)
neurodev-mcp
步骤 2:重启客户端
重启 Claude Desktop 或重新加载 VSCode,以加载服务。
步骤 3:开始使用!🎉
尝试向 AI 助手发送以下指令:
- “检查这段 Python 代码是否存在问题”
- “为此函数生成单元测试”
- “运行这些测试并生成覆盖率报告”
- “将这段代码格式化为符合 PEP8 规范”
🌐 传输选项
NeuroDev MCP 支持多种传输协议,以适用于不同场景:
STDIO(默认)- 本地 CLI
适用于使用 Claude Desktop 或 Cline 等 MCP 客户端进行本地开发:
# Default STDIO transport
neurodev-mcp
# Or explicitly specify STDIO
neurodev-mcp --transport stdio
配置(Claude Desktop):
{
"mcpServers": {
"neurodev-mcp": {
"command": "neurodev-mcp",
"args": ["--transport", "stdio"]
}
}
}
SSE(服务器发送事件)- Web 集成
适用于基于 Web 的集成和 HTTP 流式传输:
# Run with SSE on default port (8000)
neurodev-mcp --transport sse
# Custom host and port
neurodev-mcp --transport sse --host 0.0.0.0 --port 3000
端点:
- SSE 流:
http://localhost:8000/sse - 消息:
http://localhost:8000/messages(POST)
Web 客户端示例:
const sse = new EventSource('http://localhost:8000/sse');
sse.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
// Send message
fetch('http://localhost:8000/messages', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
method: 'tools/call',
params: {
name: 'code_review',
arguments: { code: 'def test(): pass', analyzers: ['pylint'] }
}
})
});
传输方式对比
| 传输方式 | 使用场景 | 最适合 |
|---|---|---|
| STDIO | 本地 CLI 客户端 | Claude Desktop、Cline、本地开发 |
| SSE | Web 集成 | 浏览器应用、webhook、远程客户端 |
🛠️ 可用工具
1. code_review
🔍 使用多种静态分析工具进行全面代码分析
输入:
{
"code": "def calculate(x):\n return x * 2",
"analyzers": ["pylint", "flake8", "mypy", "bandit", "radon", "ast"]
}
输出:
- 各分析器的详细问题报告
- 安全漏洞
- 复杂度指标
- 代码质量评分
- 逐行建议
2. generate_tests
🧪 使用 AST 分析智能生成 pytest 测试
输入:
{
"code": "def add(a: int, b: int) -> int:\n return a + b",
"module_name": "calculator",
"save": false
}
输出:
- 完整的 pytest 测试套件
- 多种测试用例(正常路径、边界情况、异常)
- 类型验证测试
- 可直接运行的测试代码
3. run_tests
▶️ 运行 pytest 测试并生成覆盖率报告
输入:
{
"test_code": "def test_add():\n assert add(1, 2) == 3",
"source_code": "def add(a, b):\n return a + b",
"timeout": 30
}
输出:
- 通过/失败状态
- 覆盖率百分比
- 行覆盖率详情
- 执行时间
- 详细的 stdout/stderr
4. format_code
🎨 将 Python 代码自动格式化为符合 PEP8 标准的样式
输入:
{
"code": "def messy( x,y ):\n return x+y",
"line_length": 88
}
输出:
- 格式优美的代码
- 符合 PEP8 标准
- 风格一致
- 变更检测
💡 使用示例
示例 1:完整的代码审查工作流
You: "Review this code for issues and security problems"
[paste code]
AI: [Uses code_review tool]
→ Finds 3 style issues
→ Detects 1 security vulnerability
→ Suggests complexity improvements
You: "Fix those issues and show me the updated code"
AI: [Provides fixed code with explanations]
示例 2:生成并运行测试
You: "Generate tests for this function and run them"
def divide(a: float, b: float) -> float:
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
AI: [Uses generate_tests tool]
→ Creates 5 test cases
→ Includes edge cases (zero, negative numbers)
→ Tests exception handling
[Uses run_tests tool]
→ 5/5 tests passing ✓
→ 100% code coverage
→ All edge cases handled
示例 3:代码格式化
You: "Format this messy code"
def calculate( x,y,z ):
result=x+y+z
if result>10:
return True
return False
AI: [Uses format_code tool]
→ Applies black formatting
→ Returns clean, PEP8-compliant code
def calculate(x, y, z):
result = x + y + z
if result > 10:
return True
return False
📋 依赖要求
| 包 | 版本 | 用途 |
|---|---|---|
mcp | ≥0.9.0 | Model Context Protocol SDK |
pylint | ≥3.0.0 | 代码质量分析 |
flake8 | ≥7.0.0 | 样式检查 |
mypy | ≥1.7.0 | 静态类型检查 |
bandit | ≥1.7.5 | 安全扫描 |
radon | ≥6.0.1 | 复杂度指标 |
black | ≥23.12.0 | 代码格式化 |
autopep8 | ≥2.0.4 | PEP8 格式化 |
pytest | ≥7.4.3 | 测试框架 |
pytest-cov | ≥4.1.0 | 覆盖率报告 |
pytest-timeout | ≥2.2.0 | 测试超时 |
Python: 3.8 或更高版本
🧪 开发
运行测试
# Run installation tests
python test_installation.py
# Run examples
python examples.py
# Run pytest (if you add tests)
pytest
作为库使用
from neurodev_mcp import CodeAnalyzer, TestGenerator, TestExecutor
import asyncio
# Analyze code
code = "def hello(): print('world')"
result = asyncio.run(CodeAnalyzer.analyze_ast(code))
# Generate tests
tests = TestGenerator.generate_tests(code, "mymodule")
# Run tests
output = TestExecutor.run_tests(test_code, source_code)
❓ 故障排查
在 MCP 客户端中看不到服务?
- ✅ 检查配置中的路径是否为绝对路径
- ✅ 确保 Python 可执行文件路径正确
- ✅ 完全重启 Claude Desktop 或 VSCode
- ✅ 检查服务日志是否有错误
导入或模块错误?
# Reinstall the package
pip install -e .
# Verify installation
python -c "from neurodev_mcp import CodeAnalyzer; print('✓ OK')"
# Run installation tests
python test_installation.py
测试失败?
- ✅ 确保已安装 Python 3.8+
- ✅ 激活虚拟环境:
source .venv/bin/activate - ✅ 重新安装依赖:
pip install -e . - ✅ 运行:
python test_installation.py以进行诊断
性能问题?
- 某些分析器(pylint、mypy)在大型文件上运行可能较慢
- 使用指定的分析器:
"analyzers": ["flake8", "ast"] - 为大型测试套件延长超时时间
- 考虑缓存结果(未来功能)
🤝 参与贡献
欢迎贡献!参与方式如下:
- Fork 此仓库
- 创建功能分支:
git checkout -b feature/amazing-feature - 进行修改
- 运行测试:
python test_installation.py - 提交:
git commit -m 'Add amazing feature' - 推送:
git push origin feature/amazing-feature - 发起 Pull Request
未来改进
- 添加更多分析器(pydocstyle、vulture)
- 缓存结果以提升性能
- 支持配置文件
- Web 仪表板
- 支持多种语言
- CI/CD 流水线
📄 许可证
本项目采用 MIT License 授权,详情请参阅 LICENSE 文件。
🙏 致谢
📞 支持
- 📖 文档:你正在阅读本文档!
- 🐛 问题:GitHub Issues
- 💬 讨论:GitHub Discussions
- 📧 电子邮件:[email protected]
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。