使用说明
MCP服务器Monorepo
一组使用FastMCP构建的模型上下文协议(MCP)服务器,为编码辅助和渗透测试提供专用工具。
概述
此monorepo包含多个MCP服务器,每个服务器都提供特定于域的工具,可供Claude和其他AI助手使用:
存储库结构
mcp/
├── README.md # This file - overview and setup guide
├── servers/
│ ├── coding/ # Coding assistance server
│ │ ├── server.py # FastMCP server implementation
│ │ ├── requirements.txt # Python dependencies
│ │ └── README.md # Server-specific documentation
│ └── pentest/ # Penetration testing server
│ ├── server.py # FastMCP server implementation
│ ├── requirements.txt # Python dependencies
│ └── README.md # Server-specific documentation
└── shared/ # Shared utilities (placeholder)
└── __init__.py
快速开始
先决条件
- Python 3.8或更高版本
- pip(Python包管理器)
- 虚拟环境(推荐)
安装
- 克隆或导航到此存储库:
cd mcp
- 设置要使用的每台服务器:
对于编码服务器:
cd servers/coding
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
对于Pentest服务器:
cd servers/pentest
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
测试服务器
使用MCP检查器单独测试服务器:
# Test coding server (stdio)
npx @modelcontextprotocol/inspector python servers/coding/server.py
# Test pentest server (stdio)
npx @modelcontextprotocol/inspector python servers/pentest/server.py
# Test with SSE transport
python servers/coding/server.py --transport sse --port 8000
# Then connect inspector to http://localhost:8000/sse
运输选项
每台服务器支持两种传输机制:
标准输入/输出
- 用途: Claude Desktop、VS Code、本地IDE集成
- 赞成的意见: 简单、安全,无需网络配置
- 欺骗: 每个服务器实例一个客户端
- 违约: 是
python servers/coding/server.py
# or explicitly
python servers/coding/server.py --transport stdio
SSE(带有服务器发送事件的HTTP)
- 用途: 多客户端、远程访问、服务部署
- 赞成的意见: 多个并发客户端,网络可访问
- 欺骗: 需要端口管理、网络安全考虑
- 违约: 不
# Coding server (port 8000)
python servers/coding/server.py --transport sse --host 127.0.0.1 --port 8000
# Pentest server (port 8001)
python servers/pentest/server.py --transport sse --host 127.0.0.1 --port 8001
# Bind to all interfaces (use with caution)
python servers/coding/server.py --transport sse --host 0.0.0.0 --port 8000
安全说明: 使用SSE传输时,特别是对于pentest工具,要小心绑定到0.0.0.0或将服务器暴露在不受信任的网络中。
配置
克劳德桌面版
要将这些服务器与Claude Desktop一起使用,请将它们添加到配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
窗户: %APPDATA%\Claude\claude_desktop_config.json
stdio传输(建议用于桌面)
{
"mcpServers": {
"coding": {
"command": "python",
"args": ["/absolute/path/to/mcp/servers/coding/server.py"],
"env": {}
},
"pentest": {
"command": "python",
"args": ["/absolute/path/to/mcp/servers/pentest/server.py"],
"env": {}
}
}
}
苏格兰和南方能源公司运输(用于共享服务)
如果将服务器作为服务单独运行:
{
"mcpServers": {
"coding": {
"url": "http://localhost:8000/sse"
},
"pentest": {
"url": "http://localhost:8001/sse"
}
}
}
重要提示:
- 使用绝对路径,而不是相对路径(stdio)
- 在Windows上,使用双反斜杠:
C:\\Users\\...\\mcp\\servers\\coding\\server.py - 对于SSE,在启动Claude Desktop之前,确保服务器正在运行
- 配置更改后重新启动Claude Desktop
带Claude扩展名的VS代码
如果使用VS Code或Cursor与Claude Code,请添加到您的设置中:
- 打开命令面板(Cmd+Shift+P/Ctrl+Shift+P)
- 搜索“首选项:打开设置(JSON)”
- 添加MCP服务器配置:
stdio运输
{
"mcp.servers": {
"coding": {
"command": "python",
"args": ["/absolute/path/to/mcp/servers/coding/server.py"]
},
"pentest": {
"command": "python",
"args": ["/absolute/path/to/mcp/servers/pentest/server.py"]
}
}
}
苏格兰和南方能源公司运输
{
"mcp.servers": {
"coding": {
"url": "http://localhost:8000/sse"
},
"pentest": {
"url": "http://localhost:8001/sse"
}
}
}
Cline(VS代码扩展)
对于VS代码中的Cline:
- 打开临床设置
- 导航到MCP服务器部分
- 添加每个服务器:
- 标准:命令:
python,Args:/absolute/path/to/mcp/servers/[server-name]/server.py - 上海证券交易所:URL:
http://localhost:8000/sse(或适当的端口)
- 标准:命令:
Continue.dev
对于Continue.dev,编辑 ~/.continue/config.json:
stdio运输
{
"mcpServers": {
"coding": {
"command": "python",
"args": ["/absolute/path/to/mcp/servers/coding/server.py"]
},
"pentest": {
"command": "python",
"args": ["/absolute/path/to/mcp/servers/pentest/server.py"]
}
}
}
苏格兰和南方能源公司运输
{
"mcpServers": {
"coding": {
"url": "http://localhost:8000/sse"
},
"pentest": {
"url": "http://localhost:8001/sse"
}
}
}
其他平台
大多数MCP兼容平台支持以下两种传输方式:
stdio模式
{
"server-name": {
"command": "python",
"args": ["path/to/server.py"],
"env": {}
}
}
SSE模式
{
"server-name": {
"url": "http://localhost:PORT/sse"
}
}
将服务器作为服务运行
使用SSE传输时,您可能希望将服务器作为持久后台服务运行。
使用screen/tmux(快速方法)
# Start in screen
screen -S mcp-coding
python servers/coding/server.py --transport sse --port 8000
# Detach: Ctrl+A, D
# Start in tmux
tmux new -s mcp-coding
python servers/coding/server.py --transport sse --port 8000
# Detach: Ctrl+B, D
使用nohup(简单背景)
cd servers/coding
nohup python server.py --transport sse --port 8000 > coding.log 2>&1 &
cd ../pentest
nohup python server.py --transport sse --port 8001 > pentest.log 2>&1 &
使用systemd(Linux)
在中创建服务文件 /etc/systemd/system/:
mcp编码服务:
[Unit]
Description=MCP Coding Server
After=network.target
[Service]
Type=simple
User=yourusername
WorkingDirectory=/absolute/path/to/mcp/servers/coding
ExecStart=/usr/bin/python server.py --transport sse --host 127.0.0.1 --port 8000
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
启用并启动:
sudo systemctl daemon-reload
sudo systemctl enable mcp-coding
sudo systemctl start mcp-coding
sudo systemctl status mcp-coding
使用Docker(高级)
创建 Dockerfile 在每个服务器目录中:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY server.py .
CMD ["python", "server.py", "--transport", "sse", "--host", "0.0.0.0", "--port", "8000"]
构建并运行:
docker build -t mcp-coding ./servers/coding
docker run -d -p 8000:8000 --name mcp-coding mcp-coding
服务器文档
每个服务器在其各自的目录中都有详细的文档:
-
- code_review:具有多种审核类型的自动代码审核
- run_tests:使用pytest、unittest或nose执行测试
- format_code:用黑色、autoep8或isort格式化代码
-
- port_scan:TCP端口扫描和服务检测
- 枚举子域:通过DNS枚举子域
- check_cve:cve数据库查询(模拟实现)
发展
添加新服务器
- 在下创建新目录
servers/:
mkdir servers/new-server
cd servers/new-server
- 创建服务器结构:
touch server.py requirements.txt README.md
- 使用FastMCP实现您的服务器:
from fastmcp import FastMCP
mcp = FastMCP("server-name")
@mcp.tool()
def example_tool(param: str) -> str:
"""Tool description"""
return f"Result: {param}"
if __name__ == "__main__":
mcp.run()
- 在README.md中记录您的工具
- 用新服务器更新此主README
向现有服务器添加工具
- 导航到服务器目录
- 编辑
server.py - 添加一个新功能,用
@mcp.tool() - 包含正确的类型提示和文档字符串
- 更新服务器的README.md
- 使用MCP检查员进行测试
共享公用设施
这 shared/ 目录可用于跨服务器使用的通用代码:
# In your server.py
import sys
sys.path.append('../..')
from shared import your_utility
故障排除
服务器未出现
- 检查配置中的路径是否绝对正确
- 验证Python是否在您的PATH中:
python --version - 独立测试服务器:
python servers/coding/server.py - 检查配置JSON中的语法错误
导入错误
- 确保已激活虚拟环境
- 安装依赖项:
pip install -r requirements.txt - 检查Python版本:
python --version(3.8+必填)
权限错误
- 在Unix系统上,使server.py可执行:
chmod +x server.py - 确保您对服务器目录具有读取权限
工具执行错误
- 检查特定于工具的依赖关系(pytest、black等)
- 查看Claude输出中的错误消息
- 使用MCP Inspector独立测试工具
- 检查文件路径是否可访问
资源
安全说明
编码服务器
- 代码审查工具读取系统上的文件
- 测试执行使用您的用户权限运行代码
- 代码格式化程序就地修改文件
最顶层服务器
- 端口扫描可能会触发IDS/IPS警报
- 仅在授权系统上使用
- 子域枚举生成DNS流量
- 测试前始终获得适当的授权
贡献
要为此monorepo做出贡献:
- 使用MCP检查器测试您的更改
- 更新相关的README文件
- 遵循现有的代码风格和模式
- 添加适当的错误处理和文档字符串
- 文档安全注意事项
许可证
[在此处添加您的许可证]
支持
对于问题或疑问:
- 检查特定于服务器的README文件
- 查看上面的故障排除部分
- 使用MCP检查员进行调试测试
- 检查FastMCP文档
版本历史
0.1.0(初始版本)
- 使用code_review、run_tests、format_code工具的编码服务器
- 带port_scan、enum_subdomains、check_cve工具的Pentest服务器
- 基本单回购结构
- 所有服务器的文档
