grepai-mcp-cursor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGrepAI MCP Integration with Cursor
GrepAI与Cursor的MCP集成
This skill covers integrating GrepAI with Cursor IDE using the Model Context Protocol (MCP).
本技能介绍如何通过模型上下文协议(MCP)将GrepAI与Cursor IDE集成。
When to Use This Skill
何时使用此技能
- Setting up GrepAI in Cursor
- Enabling semantic search for Cursor AI
- Configuring MCP for Cursor
- Troubleshooting Cursor integration
- 在Cursor中设置GrepAI
- 为Cursor AI启用语义搜索
- 为Cursor配置MCP
- 排查Cursor集成问题
What is Cursor?
什么是Cursor?
Cursor is an AI-powered IDE that supports MCP for external tools. GrepAI integration gives Cursor's AI:
- Semantic code search beyond simple text matching
- Call graph analysis for understanding dependencies
- Index-based code navigation
Cursor是一款支持通过MCP接入外部工具的AI驱动IDE。集成GrepAI后,Cursor的AI将具备以下能力:
- 超越简单文本匹配的语义代码搜索
- 用于理解依赖关系的调用图分析
- 基于索引的代码导航
Prerequisites
前置条件
- GrepAI installed
- Ollama running (or other embedding provider)
- Project indexed ()
grepai watch - Cursor IDE installed
- 已安装GrepAI
- Ollama正在运行(或使用其他嵌入模型提供商)
- 项目已建立索引(执行)
grepai watch - 已安装Cursor IDE
Configuration
配置步骤
Step 1: Create MCP Config File
步骤1:创建MCP配置文件
Create in your project root:
.cursor/mcp.jsonjson
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"]
}
}
}在项目根目录创建文件:
.cursor/mcp.jsonjson
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"]
}
}
}Step 2: Restart Cursor
步骤2:重启Cursor
Close and reopen Cursor for the config to take effect.
关闭并重新打开Cursor,使配置生效。
Step 3: Verify
步骤3:验证配置
Ask Cursor's AI:
"Search the codebase for authentication"
Cursor should use the tool.
grepai_search向Cursor的AI提问:
"Search the codebase for authentication"
Cursor应调用工具。
grepai_searchGlobal Configuration
全局配置
For GrepAI in all Cursor projects, use global config:
若要在所有Cursor项目中使用GrepAI,请使用全局配置:
Location
配置文件位置
- macOS:
~/.cursor/mcp.json - Linux:
~/.cursor/mcp.json - Windows:
%APPDATA%\Cursor\mcp.json
- macOS:
~/.cursor/mcp.json - Linux:
~/.cursor/mcp.json - Windows:
%APPDATA%\Cursor\mcp.json
Content
配置内容
json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"]
}
}
}json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"]
}
}
}Per-Project Configuration
项目专属配置
For project-specific settings:
json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"],
"cwd": "/absolute/path/to/project"
}
}
}针对特定项目的配置:
json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"],
"cwd": "/absolute/path/to/project"
}
}
}Available Tools
可用工具
Once configured, Cursor has access to:
| Tool | Description |
|---|---|
| Semantic code search |
| Find function callers |
| Find function callees |
| Build call graphs |
| Check index health |
配置完成后,Cursor可使用以下工具:
| 工具 | 描述 |
|---|---|
| 语义代码搜索 |
| 查找函数调用方 |
| 查找函数被调用方 |
| 生成调用图 |
| 检查索引健康状态 |
Usage Examples
使用示例
Finding Code
查找代码
Ask Cursor:
"Find code that handles user login"
Cursor uses to find semantically related code.
grepai_search向Cursor提问:
"查找处理用户登录的代码"
Cursor会使用工具查找语义相关的代码。
grepai_searchUnderstanding Dependencies
理解依赖关系
Ask Cursor:
"What functions call validateToken?"
Cursor uses to show all callers.
grepai_trace_callers向Cursor提问:
"哪些函数调用了validateToken?"
Cursor会使用工具显示所有调用方。
grepai_trace_callersCode Navigation
代码导航
Ask Cursor:
"Show me the call graph for processPayment"
Cursor uses to display dependencies.
grepai_trace_graph向Cursor提问:
"展示processPayment的调用图"
Cursor会使用工具展示依赖关系。
grepai_trace_graphCursor Settings Integration
Cursor设置集成
Enable MCP in Settings
在设置中启用MCP
- Open Cursor Settings (/
Cmd+,)Ctrl+, - Search for "MCP"
- Ensure MCP is enabled
- 打开Cursor设置(/
Cmd+,)Ctrl+, - 搜索"MCP"
- 确保MCP已启用
Verify MCP Status
验证MCP状态
- Open Command Palette (/
Cmd+Shift+P)Ctrl+Shift+P - Search "MCP"
- Check connected servers
- 打开命令面板(/
Cmd+Shift+P)Ctrl+Shift+P - 搜索"MCP"
- 查看已连接的服务器
Windsurf Configuration
Windsurf配置
Windsurf uses the same MCP format as Cursor:
Windsurf使用与Cursor相同的MCP格式:
Location
配置文件位置
Create :
.windsurf/mcp.jsonjson
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"]
}
}
}创建文件:
.windsurf/mcp.jsonjson
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"]
}
}
}Multiple Projects Setup
多项目设置
Option 1: Separate Configs
选项1:独立配置
Each project has its own with appropriate .
.cursor/mcp.jsoncwd每个项目拥有自己的文件,并设置合适的。
.cursor/mcp.jsoncwdOption 2: Workspaces
选项2:工作区
bash
undefinedbash
undefinedCreate workspace
创建工作区
grepai workspace create dev
grepai workspace add dev /path/to/project1
grepai workspace add dev /path/to/project2
```json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve", "--workspace", "dev"]
}
}
}grepai workspace create dev
grepai workspace add dev /path/to/project1
grepai workspace add dev /path/to/project2
```json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve", "--workspace", "dev"]
}
}
}Environment Variables
环境变量
If GrepAI uses environment variables (like API keys):
json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"],
"env": {
"OPENAI_API_KEY": "sk-..."
}
}
}
}Better: Set environment variables in your shell profile instead.
如果GrepAI需要使用环境变量(如API密钥):
json
{
"mcpServers": {
"grepai": {
"command": "grepai",
"args": ["mcp-serve"],
"env": {
"OPENAI_API_KEY": "sk-..."
}
}
}
}更优方案: 在Shell配置文件中设置环境变量。
Troubleshooting
故障排查
MCP Not Recognized
MCP未被识别
❌ Problem: Cursor doesn't see GrepAI tools
✅ Solutions:
- Check file location: in project root
.cursor/mcp.json - Verify JSON syntax (no trailing commas)
- Restart Cursor completely
- Check is in PATH
grepai
❌ 问题: Cursor无法识别GrepAI工具
✅ 解决方案:
- 检查文件位置:项目根目录下的
.cursor/mcp.json - 验证JSON语法(无尾随逗号)
- 完全重启Cursor
- 确认已添加到系统PATH中
grepai
Search Returns Nothing
搜索无结果
❌ Problem: Empty search results
✅ Solutions:
- Ensure index exists:
grepai status - Run first
grepai watch - Verify working directory
❌ 问题: 搜索结果为空
✅ 解决方案:
- 确认索引已存在:执行
grepai status - 先执行
grepai watch - 验证工作目录是否正确
Connection Errors
连接错误
❌ Problem: MCP connection failed
✅ Solutions:
- Test manually:
grepai mcp-serve - Check Ollama:
curl http://localhost:11434/api/tags - Look at Cursor's developer console for errors
❌ 问题: MCP连接失败
✅ 解决方案:
- 手动测试:执行
grepai mcp-serve - 检查Ollama状态:执行
curl http://localhost:11434/api/tags - 在Cursor开发者控制台查看错误信息
Wrong Results
结果错误
❌ Problem: Results from wrong project
✅ Solutions:
- Set explicit in config
cwd - Check you opened the right folder in Cursor
- Use to verify
grepai_index_status
❌ 问题: 返回错误项目的结果
✅ 解决方案:
- 在配置中设置明确的
cwd - 确认在Cursor中打开了正确的文件夹
- 使用验证索引
grepai_index_status
Performance Tips
性能优化建议
- Background daemon: Keep running
grepai watch --background - Use compact mode: MCP tools use compact by default
- Limit results: AI will request appropriate limits
- Index regularly: Especially after git pull
- 后台守护进程: 保持运行
grepai watch --background - 使用紧凑模式: MCP工具默认使用紧凑模式
- 限制结果数量: AI会自动请求合适的结果数量
- 定期更新索引: 尤其是在执行git pull之后
Comparison: Cursor vs Claude Code
对比:Cursor vs Claude Code
| Feature | Cursor | Claude Code |
|---|---|---|
| Config location | | |
| Setup command | Manual JSON | |
| Project scope | Per-project or global | Global |
| IDE integration | Native | Terminal |
| 特性 | Cursor | Claude Code |
|---|---|---|
| 配置文件位置 | | |
| 设置命令 | 手动编写JSON | |
| 项目范围 | 项目专属或全局 | 全局 |
| IDE集成 | 原生集成 | 终端集成 |
Best Practices
最佳实践
- Version control: Add to git (without secrets)
.cursor/mcp.json - Team setup: Document MCP config in README
- Keep index fresh: Run watch daemon
- Test locally: Verify works first
grepai mcp-serve - Use workspaces: For multi-project setups
- 版本控制: 将添加到git中(不含敏感信息)
.cursor/mcp.json - 团队设置: 在README中记录MCP配置方法
- 保持索引更新: 运行watch守护进程
- 本地测试: 先验证可正常运行
grepai mcp-serve - 使用工作区: 适用于多项目场景
Removing Integration
移除集成
Delete and restart Cursor.
.cursor/mcp.jsonOr remove just GrepAI:
json
{
"mcpServers": {
// Remove grepai entry
}
}删除并重启Cursor。
.cursor/mcp.json或仅移除GrepAI:
json
{
"mcpServers": {
// 移除grepai条目
}
}Output Format
输出格式
Successful Cursor setup:
✅ GrepAI MCP Integration for Cursor
Config: .cursor/mcp.json
Server: grepai mcp-serve
Status: Ready
Available tools:
- grepai_search
- grepai_trace_callers
- grepai_trace_callees
- grepai_trace_graph
- grepai_index_status
Cursor AI can now search your code semantically!
Test: Ask Cursor "search for authentication code"Cursor设置成功后的输出:
✅ GrepAI MCP Integration for Cursor
Config: .cursor/mcp.json
Server: grepai mcp-serve
Status: Ready
Available tools:
- grepai_search
- grepai_trace_callers
- grepai_trace_callees
- grepai_trace_graph
- grepai_index_status
Cursor AI can now search your code semantically!
Test: Ask Cursor "search for authentication code"