MCP (Model Context Protocol) 工具介绍

MCP是一个标准化协议,允许AI助手通过工具扩展其能力。这些工具专门为在Cursor IDE中使用而设计,为您的开发工作流程提供强大的功能支持。

🎯 为什么要在Cursor中使用MCP工具?

  • 无缝集成: 直接在Cursor中调用各种外部服务和工具
  • 提高效率: 无需切换到其他应用程序或浏览器
  • 智能辅助: AI可以自动选择合适的工具来完成任务
  • 上下文保持: 工具之间可以共享项目上下文信息

配置文件位置

在Mac上,Cursor的MCP配置文件位于:

~/.cursor-mcp/config.json

8个强大的MCP工具详细介绍

🧠 1. Sequential Thinking (序列化思考工具)

功能: 提供结构化的思维过程分析工具

  • 帮助AI进行复杂问题的分步分析
  • 支持思维过程的回溯和修正
  • 适用于需要深度思考的编程问题
  • 在Cursor中的优势: 让AI助手能够更系统地分析复杂的代码问题

Mac配置:

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

Mac环境要求:

  • Node.js 16+
  • 网络连接用于下载包

安装验证:

# 验证Node.js版本
node --version
npm --version

🎨 2. Shadcn UI (UI组件工具)

功能: UI组件注册表和管理工具

  • 访问Shadcn UI组件库
  • 自动获取组件代码和文档
  • 简化React/Next.js项目的UI开发
  • 使用Vercel的注册表源
  • 在Cursor中的优势: 直接在IDE中浏览和插入UI组件,无需手动复制粘贴

Mac配置:

{
  "mcpServers": {
    "shadcn": {
      "command": "npx",
      "args": [
        "-y",
        "shadcn@canary",
        "registry:mcp"
      ],
      "env": {
        "REGISTRY_URL": "https://registry-starter.vercel.app/r/registry.json"
      }
    }
  }
}

Mac环境要求:

  • Node.js 18+
  • 网络连接访问注册表

使用场景:

  • React/Next.js项目开发
  • 快速获取UI组件代码

📚 3. Context7 (代码文档工具)

功能: 代码上下文和文档检索工具

  • 获取流行库和框架的最新文档
  • 提供代码示例和API参考
  • 支持实时文档查询
  • 在Cursor中的优势: AI可以实时获取最新的库文档,提供准确的代码建议
  • ⚠️ 需要配置: CONTEXT7_API_KEY (需要申请API密钥)

Mac配置:

{
  "mcpServers": {
    "context7": {
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "your_context7_api_key_here"
      }
    }
  }
}

Mac设置步骤:

  1. 访问 https://context7.com 注册账号
  2. 获取API密钥
  3. 替换配置中的 your_context7_api_key_here

环境变量设置 (可选):

# 在 ~/.zshrc 中添加
export CONTEXT7_API_KEY="your_api_key"

☁️ 4. Vercel (部署工具)

功能: Vercel平台集成工具

  • 部署和管理Vercel项目
  • 查看部署状态和日志
  • 配置域名和环境变量
  • 在Cursor中的优势: 直接在IDE中管理部署,无需切换到Vercel仪表板

Mac配置:

{
  "mcpServers": {
    "Vercel": {
      "url": "https://mcp.vercel.com",
      "headers": {}
    }
  }
}

Mac设置步骤:

  1. 安装Vercel CLI
npm i -g vercel
  1. 登录Vercel账号
vercel login

注意事项:

  • 需要Vercel账号
  • 项目需要与Vercel关联

🌐 5. Playwright (浏览器自动化工具)

功能: 浏览器自动化和测试工具

  • 网页自动化操作
  • 截图和页面交互
  • E2E测试支持
  • 支持多种浏览器 (Chromium, Firefox, Safari)
  • 在Cursor中的优势: 直接在IDE中编写和运行浏览器测试,实时查看结果

Mac配置:

{
  "mcpServers": {
    "Playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {},
      "args": []
    }
  }
}

Mac安装步骤:

# 安装Playwright
npm install -g @playwright/test

# 安装浏览器
npx playwright install

支持的浏览器:

  • Chromium
  • Firefox
  • Safari (Mac专用)

🔍 6. Fetch (网页抓取工具)

功能: 网页内容获取工具

  • 抓取网页内容
  • 转换为Markdown格式
  • 获取实时网络信息
  • 在Cursor中的优势: AI可以实时获取网页内容进行分析,帮助解决开发问题

Mac配置:

{
  "mcpServers": {
    "fetch": {
      "command": "python",
      "args": ["-m", "mcp_server_fetch"]
    }
  }
}

Mac安装步骤:

# 使用Homebrew安装Python (如果没有)
brew install python

# 安装mcp-server-fetch
pip install mcp-server-fetch

验证安装:

python -c "import mcp_server_fetch; print('安装成功')"

💾 7. Memory (记忆存储工具)

功能: 持久化记忆存储

  • 存储项目信息和用户偏好
  • 跨会话保持上下文
  • 记住开发规范和约定
  • 在Cursor中的优势: AI可以记住您的编码习惯和项目特定信息,提供个性化建议
  • 配置路径: /Users/Documents/workspaces/Curosr/custom/memory.json

Mac配置:

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ],
      "env": {
        "MEMORY_FILE_PATH": "/Users/$(whoami)/Documents/workspaces/Curosr/custom/memory.json"
      }
    }
  }
}

Mac目录创建:

# 创建存储目录
mkdir -p ~/Documents/workspaces/Curosr/custom

# 创建初始内存文件
echo '{}' > ~/Documents/workspaces/Curosr/custom/memory.json

# 设置权限
chmod 644 ~/Documents/workspaces/Curosr/custom/memory.json

🗄️ 8. PostgreSQL (数据库工具)

功能: PostgreSQL数据库操作

  • 执行SQL查询
  • 数据库结构分析
  • 数据导入导出
  • 在Cursor中的优势: 直接在IDE中查询和分析数据库,无需外部数据库客户端
  • ⚠️ 需要配置: 数据库连接字符串

Mac配置:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://username:password@localhost:5432/database_name"
      ]
    }
  }
}

Mac PostgreSQL安装:

# 使用Homebrew安装PostgreSQL
brew install postgresql

# 启动PostgreSQL服务
brew services start postgresql

# 创建数据库
createdb your_database_name

连接字符串格式:

postgresql://[用户名]:[密码]@[主机]:[端口]/[数据库名]

示例:
postgresql://david:mypassword@localhost:5432/myapp

在Cursor中的使用建议

🚀 开发工作流程优化

1. 开发阶段:

  • 使用 sequential-thinking 进行复杂问题分析
  • 使用 shadcn 快速获取UI组件
  • 使用 context7 查询最新文档
  • 使用 memory 记住项目规范

2. 测试阶段:

  • 使用 playwright 进行自动化测试
  • 使用 fetch 获取测试数据

3. 部署阶段:

  • 使用 vercel 进行项目部署
  • 使用 postgres 管理生产数据库

4. 数据处理:

  • 使用 postgres 进行数据查询分析
  • 使用 fetch 获取外部API数据

⚠️ 重要注意事项

  • 某些工具需要网络连接和API密钥
  • Playwright可能需要额外的浏览器安装
  • Memory工具的存储路径需要确保有写入权限
  • 建议逐个启用工具进行测试
  • 所有操作都在Cursor IDE内完成,无需切换应用程序

完整的MCP配置文件

将以下内容保存到 ~/.cursor-mcp/config.json:

{
  "mcpServers": {
    "sequential-thinking": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
    },
    "shadcn": {
      "command": "npx",
      "args": ["-y", "shadcn@canary", "registry:mcp"],
      "env": {
        "REGISTRY_URL": "https://registry-starter.vercel.app/r/registry.json"
      }
    },
    "context7": {
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "your_context7_api_key_here"
      }
    },
    "Vercel": {
      "url": "https://mcp.vercel.com",
      "headers": {}
    },
    "Playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {}
    },
    "fetch": {
      "command": "python",
      "args": ["-m", "mcp_server_fetch"]
    },
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"],
      "env": {
        "MEMORY_FILE_PATH": "/Users/$(whoami)/Documents/workspaces/Curosr/custom/memory.json"
      }
    },
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://username:password@localhost:5432/database_name"
      ]
    }
  }
}

Mac特殊配置说明

🔐 系统权限

某些工具可能需要系统权限,在macOS中:

# 给予Cursor完全磁盘访问权限
# 系统偏好设置 -> 安全性与隐私 -> 完全磁盘访问权限 -> 添加Cursor

🔧 环境变量

~/.zshrc 中添加常用的环境变量:

# MCP相关环境变量
export CONTEXT7_API_KEY="your_api_key"
export MEMORY_FILE_PATH="$HOME/Documents/workspaces/Curosr/custom/memory.json"

# 重新加载配置
source ~/.zshrc

🚨 故障排除

常见问题:

  1. npx命令失败: 检查Node.js版本和网络连接
  2. Python模块找不到: 使用正确的Python路径
  3. 权限问题: 检查文件和目录权限
  4. 数据库连接失败: 验证PostgreSQL服务状态
  5. Cursor无法加载MCP: 检查配置文件语法和路径

调试命令:

# 检查MCP服务状态
ps aux | grep mcp

# 查看Cursor日志
tail -f ~/Library/Logs/Cursor/main.log

# 验证配置文件
cat ~/.cursor-mcp/config.json | jq .

💡 Cursor使用技巧

  1. 快速切换工具: 在Cursor中使用@工具名快速调用特定MCP工具
  2. 组合使用: 多个工具可以在同一个对话中协同工作
  3. 上下文共享: 工具之间自动共享项目上下文信息
  4. 实时反馈: 所有操作结果直接显示在Cursor界面中
  5. 历史记录: Memory工具会记住您的使用习惯,提供更好的建议

🎯 总结

这8个MCP工具为Cursor IDE提供了完整的开发生态系统支持:

  • 思考工具: Sequential Thinking
  • UI开发: Shadcn
  • 文档查询: Context7
  • 部署管理: Vercel
  • 测试自动化: Playwright
  • 数据获取: Fetch
  • 记忆存储: Memory
  • 数据库操作: PostgreSQL
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐