HACKMCP接入教程(示例)

MCP 接入完整教程

1. 环境准备

在开始之前,请确保安装以下依赖:

必需软件

软件 版本要求 下载地址
Node.js ≥ 18.0 https://nodejs.org/
Python ≥ 3.10 https://python.org/
uv (Python包管理) 最新版 pip install uv
Git 最新版 https://git-scm.com/

验证安装

node --version # v18.x.x 以上
python --version # Python 3.10+
uv --version # uv 0.x.x
npx --version # 9.x.x 以上

2. Claude Desktop 接入配置

配置文件位置

Windows %APPDATA%\Claude\claude_desktop_config.json
macOS ~/Library/Application Support/Claude/claude_desktop_config.json
Linux ~/.config/Claude/claude_desktop_config.json

基础配置模板

{ "mcpServers": { "server-name": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-xxx"], "env": { "API_KEY": "your-api-key" } } } }

修改配置后需要完全退出并重启 Claude Desktop

3. Cursor IDE 接入配置

配置步骤

  1. 打开 Cursor IDE
  2. 点击 File → Preferences → Cursor Settings
  3. 找到 MCP Servers 部分
  4. 点击 Add new MCP server
  5. 填入服务配置信息

或直接编辑配置文件

文件位置:~/.cursor/mcp.json

{ "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/workspace"] } } }

4. 常用 MCP Server 推荐

Server 功能 安装命令
filesystem 文件读写、目录操作 @modelcontextprotocol/server-filesystem
github GitHub 仓库操作 @modelcontextprotocol/server-github
postgres PostgreSQL 数据库操作 @modelcontextprotocol/server-postgres
sqlite SQLite 数据库操作 @modelcontextprotocol/server-sqlite
puppeteer 浏览器自动化、网页截图 @modelcontextprotocol/server-puppeteer
brave-search 网络搜索 @modelcontextprotocol/server-brave-search
memory 知识图谱、长期记忆 @modelcontextprotocol/server-memory
fetch HTTP 请求、API 调用 @modelcontextprotocol/server-fetch
slack Slack 消息操作 @modelcontextprotocol/server-slack
google-drive Google Drive 文件管理 @modelcontextprotocol/server-gdrive
hackmcp 渗透测试工具集成 pip install hackmcp

5. 实战接入示例

示例 1:文件系统操作

让 AI 能够读写本地文件

{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/Users/yourname/Documents", "/Users/yourname/Projects" ] } } }

使用示例:"帮我在 Documents 文件夹创建一个 notes.txt 文件"


示例 2:GitHub 仓库操作

让 AI 能够管理 GitHub 仓库、创建 Issue、PR 等

{ "mcpServers": { "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx" } } } }

获取 Token:GitHub → Settings → Developer settings → Personal access tokens

使用示例:"帮我查看 hackmcp 仓库的最新 Issues"


示例 3:PostgreSQL 数据库

让 AI 能够查询和操作数据库

{ "mcpServers": { "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres"], "env": { "POSTGRES_CONNECTION_STRING": "postgresql://user:pass@localhost:5432/mydb" } } } }

使用示例:"帮我查询 users 表中注册时间在本月的用户"


示例 4:浏览器自动化 (Puppeteer)

让 AI 能够控制浏览器、截图、爬取网页

{ "mcpServers": { "puppeteer": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-puppeteer"] } } }

使用示例:"帮我打开 example.com 并截取首页截图"


示例 5:网络搜索 (Brave Search)

让 AI 能够实时搜索网络信息

{ "mcpServers": { "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "BSAxxxxxxxxxx" } } } }

获取 API Key:https://brave.com/search/api/

使用示例:"搜索最新的 CVE 漏洞信息"


示例 6:HACKMCP 渗透测试

让 AI 能够执行渗透测试工具

{ "mcpServers": { "hackmcp": { "command": "uv", "args": [ "--directory", "/path/to/hackmcp", "run", "hackmcp" ] } } }

使用示例:"对 testphp.vulnweb.com 进行端口扫描"


示例 7:多服务组合配置

同时启用多个 MCP 服务

{ "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/workspace"] }, "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxx" } }, "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "BSAxxxx" } }, "puppeteer": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-puppeteer"] }, "hackmcp": { "command": "uv", "args": ["--directory", "/opt/hackmcp", "run", "hackmcp"] } } }

6. 自定义 MCP Server 开发

Python 版本(推荐)

# my_mcp_server.py from mcp.server import Server from mcp.types import Tool, TextContent server = Server("my-custom-server") @server.list_tools() async def list_tools(): return [ Tool( name="hello", description="Say hello to someone", inputSchema={ "type": "object", "properties": { "name": {"type": "string", "description": "Name to greet"} }, "required": ["name"] } ) ] @server.call_tool() async def call_tool(name: str, arguments: dict): if name == "hello": return [TextContent(type="text", text=f"Hello, {arguments['name']}!")] if __name__ == "__main__": import asyncio asyncio.run(server.run())

安装 MCP SDK

pip install mcp

配置自定义 Server

{ "mcpServers": { "my-server": { "command": "python", "args": ["/path/to/my_mcp_server.py"] } } }

7. 常见问题

Q: 配置后没有生效? 完全退出 Claude Desktop(托盘图标也要退出),然后重新启动
Q: 提示 npx 命令找不到? 确保 Node.js 已正确安装并添加到系统 PATH
Q: 如何查看 MCP 日志? macOS: ~/Library/Logs/Claude/
Windows: %APPDATA%\Claude\logs\
Q: 多个 Server 冲突? 确保每个 Server 的名称唯一,检查端口占用
Q: Windows 路径格式? 使用正斜杠 C:/Users/xxx 或双反斜杠 C:\\Users\\xxx
Q: 如何验证 Server 运行? 在 Claude 中输入 "你有什么工具可以使用?" 查看已加载的工具列表

更多资源

  • MCP 官方文档:https://modelcontextprotocol.io/
  • 官方 Server 列表:https://github.com/modelcontextprotocol/servers
  • MCP SDK (Python):https://github.com/modelcontextprotocol/python-sdk
  • MCP SDK (TypeScript):https://github.com/modelcontextprotocol/typescript-sdk
  • 社区 Server 合集:https://github.com/wong2/awesome-mcp-servers
顶部