grepai-mcp-cursor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI 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

前置条件

  1. GrepAI installed
  2. Ollama running (or other embedding provider)
  3. Project indexed (
    grepai watch
    )
  4. Cursor IDE installed
  1. 已安装GrepAI
  2. Ollama正在运行(或使用其他嵌入模型提供商)
  3. 项目已建立索引(执行
    grepai watch
  4. 已安装Cursor IDE

Configuration

配置步骤

Step 1: Create MCP Config File

步骤1:创建MCP配置文件

Create
.cursor/mcp.json
in your project root:
json
{
  "mcpServers": {
    "grepai": {
      "command": "grepai",
      "args": ["mcp-serve"]
    }
  }
}
在项目根目录创建
.cursor/mcp.json
文件:
json
{
  "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
grepai_search
tool.
向Cursor的AI提问:
"Search the codebase for authentication"
Cursor应调用
grepai_search
工具。

Global 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:
ToolDescription
grepai_search
Semantic code search
grepai_trace_callers
Find function callers
grepai_trace_callees
Find function callees
grepai_trace_graph
Build call graphs
grepai_index_status
Check index health
配置完成后,Cursor可使用以下工具:
工具描述
grepai_search
语义代码搜索
grepai_trace_callers
查找函数调用方
grepai_trace_callees
查找函数被调用方
grepai_trace_graph
生成调用图
grepai_index_status
检查索引健康状态

Usage Examples

使用示例

Finding Code

查找代码

Ask Cursor:
"Find code that handles user login"
Cursor uses
grepai_search
to find semantically related code.
向Cursor提问:
"查找处理用户登录的代码"
Cursor会使用
grepai_search
工具查找语义相关的代码。

Understanding Dependencies

理解依赖关系

Ask Cursor:
"What functions call validateToken?"
Cursor uses
grepai_trace_callers
to show all callers.
向Cursor提问:
"哪些函数调用了validateToken?"
Cursor会使用
grepai_trace_callers
工具显示所有调用方。

Code Navigation

代码导航

Ask Cursor:
"Show me the call graph for processPayment"
Cursor uses
grepai_trace_graph
to display dependencies.
向Cursor提问:
"展示processPayment的调用图"
Cursor会使用
grepai_trace_graph
工具展示依赖关系。

Cursor Settings Integration

Cursor设置集成

Enable MCP in Settings

在设置中启用MCP

  1. Open Cursor Settings (
    Cmd+,
    /
    Ctrl+,
    )
  2. Search for "MCP"
  3. Ensure MCP is enabled
  1. 打开Cursor设置(
    Cmd+,
    /
    Ctrl+,
  2. 搜索"MCP"
  3. 确保MCP已启用

Verify MCP Status

验证MCP状态

  1. Open Command Palette (
    Cmd+Shift+P
    /
    Ctrl+Shift+P
    )
  2. Search "MCP"
  3. Check connected servers
  1. 打开命令面板(
    Cmd+Shift+P
    /
    Ctrl+Shift+P
  2. 搜索"MCP"
  3. 查看已连接的服务器

Windsurf Configuration

Windsurf配置

Windsurf uses the same MCP format as Cursor:
Windsurf使用与Cursor相同的MCP格式:

Location

配置文件位置

Create
.windsurf/mcp.json
:
json
{
  "mcpServers": {
    "grepai": {
      "command": "grepai",
      "args": ["mcp-serve"]
    }
  }
}
创建
.windsurf/mcp.json
文件:
json
{
  "mcpServers": {
    "grepai": {
      "command": "grepai",
      "args": ["mcp-serve"]
    }
  }
}

Multiple Projects Setup

多项目设置

Option 1: Separate Configs

选项1:独立配置

Each project has its own
.cursor/mcp.json
with appropriate
cwd
.
每个项目拥有自己的
.cursor/mcp.json
文件,并设置合适的
cwd

Option 2: Workspaces

选项2:工作区

bash
undefined
bash
undefined

Create 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:
  1. Check file location:
    .cursor/mcp.json
    in project root
  2. Verify JSON syntax (no trailing commas)
  3. Restart Cursor completely
  4. Check
    grepai
    is in PATH
问题: Cursor无法识别GrepAI工具
解决方案:
  1. 检查文件位置:项目根目录下的
    .cursor/mcp.json
  2. 验证JSON语法(无尾随逗号)
  3. 完全重启Cursor
  4. 确认
    grepai
    已添加到系统PATH中

Search Returns Nothing

搜索无结果

Problem: Empty search results
Solutions:
  1. Ensure index exists:
    grepai status
  2. Run
    grepai watch
    first
  3. Verify working directory
问题: 搜索结果为空
解决方案:
  1. 确认索引已存在:执行
    grepai status
  2. 先执行
    grepai watch
  3. 验证工作目录是否正确

Connection Errors

连接错误

Problem: MCP connection failed
Solutions:
  1. Test manually:
    grepai mcp-serve
  2. Check Ollama:
    curl http://localhost:11434/api/tags
  3. Look at Cursor's developer console for errors
问题: MCP连接失败
解决方案:
  1. 手动测试:执行
    grepai mcp-serve
  2. 检查Ollama状态:执行
    curl http://localhost:11434/api/tags
  3. 在Cursor开发者控制台查看错误信息

Wrong Results

结果错误

Problem: Results from wrong project
Solutions:
  1. Set explicit
    cwd
    in config
  2. Check you opened the right folder in Cursor
  3. Use
    grepai_index_status
    to verify
问题: 返回错误项目的结果
解决方案:
  1. 在配置中设置明确的
    cwd
  2. 确认在Cursor中打开了正确的文件夹
  3. 使用
    grepai_index_status
    验证索引

Performance Tips

性能优化建议

  1. Background daemon: Keep
    grepai watch --background
    running
  2. Use compact mode: MCP tools use compact by default
  3. Limit results: AI will request appropriate limits
  4. Index regularly: Especially after git pull
  1. 后台守护进程: 保持
    grepai watch --background
    运行
  2. 使用紧凑模式: MCP工具默认使用紧凑模式
  3. 限制结果数量: AI会自动请求合适的结果数量
  4. 定期更新索引: 尤其是在执行git pull之后

Comparison: Cursor vs Claude Code

对比:Cursor vs Claude Code

FeatureCursorClaude Code
Config location
.cursor/mcp.json
~/.claude/mcp.json
Setup commandManual JSON
claude mcp add
Project scopePer-project or globalGlobal
IDE integrationNativeTerminal
特性CursorClaude Code
配置文件位置
.cursor/mcp.json
~/.claude/mcp.json
设置命令手动编写JSON
claude mcp add
项目范围项目专属或全局全局
IDE集成原生集成终端集成

Best Practices

最佳实践

  1. Version control: Add
    .cursor/mcp.json
    to git (without secrets)
  2. Team setup: Document MCP config in README
  3. Keep index fresh: Run watch daemon
  4. Test locally: Verify
    grepai mcp-serve
    works first
  5. Use workspaces: For multi-project setups
  1. 版本控制:
    .cursor/mcp.json
    添加到git中(不含敏感信息)
  2. 团队设置: 在README中记录MCP配置方法
  3. 保持索引更新: 运行watch守护进程
  4. 本地测试: 先验证
    grepai mcp-serve
    可正常运行
  5. 使用工作区: 适用于多项目场景

Removing Integration

移除集成

Delete
.cursor/mcp.json
and restart Cursor.
Or remove just GrepAI:
json
{
  "mcpServers": {
    // Remove grepai entry
  }
}
删除
.cursor/mcp.json
并重启Cursor。
或仅移除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"