grepai-mcp-tools

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI MCP Tools Reference

GrepAI MCP工具参考文档

This skill provides a complete reference for all tools available through GrepAI's MCP server.
本技能提供了GrepAI的MCP服务器上所有可用工具的完整参考文档。

When to Use This Skill

何时使用此技能

  • Understanding available MCP tools
  • Learning tool parameters and options
  • Integrating GrepAI with AI assistants
  • Debugging MCP tool usage
  • 了解可用的MCP工具
  • 学习工具参数和选项
  • 将GrepAI与AI助手集成
  • 调试MCP工具的使用

Starting the MCP Server

启动MCP服务器

bash
grepai mcp-serve
The server exposes tools via the Model Context Protocol.
bash
grepai mcp-serve
服务器通过Model Context Protocol(模型上下文协议)对外暴露工具。

Available Tools

可用工具

1. grepai_search

1. grepai_search

Semantic code search using embeddings.
使用嵌入技术的语义代码搜索。

Parameters

参数

ParameterTypeRequiredDefaultDescription
query
stringYes-Search query describing what to find
limit
numberNo10Maximum results to return
compact
booleanNofalseReturn compact output (no content)
format
stringNo"json"Output format: "json" or "toon" (v0.26.0+)
参数类型是否必填默认值描述
query
string-描述搜索目标的查询语句
limit
number10返回的最大结果数
compact
booleanfalse返回精简输出(不包含内容)
format
string"json"输出格式:"json" 或 "toon"(v0.26.0+)

Example Request

请求示例

json
{
  "tool": "grepai_search",
  "parameters": {
    "query": "user authentication middleware",
    "limit": 5,
    "compact": true,
    "format": "toon"
  }
}
json
{
  "tool": "grepai_search",
  "parameters": {
    "query": "user authentication middleware",
    "limit": 5,
    "compact": true,
    "format": "toon"
  }
}

Response (Compact)

响应(精简模式)

json
{
  "q": "user authentication middleware",
  "r": [
    {"s": 0.92, "f": "src/auth/middleware.go", "l": "15-45"},
    {"s": 0.85, "f": "src/auth/jwt.go", "l": "23-55"},
    {"s": 0.78, "f": "src/handlers/auth.go", "l": "10-40"}
  ],
  "t": 3
}
json
{
  "q": "user authentication middleware",
  "r": [
    {"s": 0.92, "f": "src/auth/middleware.go", "l": "15-45"},
    {"s": 0.85, "f": "src/auth/jwt.go", "l": "23-55"},
    {"s": 0.78, "f": "src/handlers/auth.go", "l": "10-40"}
  ],
  "t": 3
}

Response (Full)

响应(完整模式)

json
{
  "query": "user authentication middleware",
  "results": [
    {
      "score": 0.92,
      "file": "src/auth/middleware.go",
      "start_line": 15,
      "end_line": 45,
      "content": "func AuthMiddleware() gin.HandlerFunc {\n    ..."
    }
  ],
  "total": 3
}

json
{
  "query": "user authentication middleware",
  "results": [
    {
      "score": 0.92,
      "file": "src/auth/middleware.go",
      "start_line": 15,
      "end_line": 45,
      "content": "func AuthMiddleware() gin.HandlerFunc {\n    ..."
    }
  ],
  "total": 3
}

2. grepai_trace_callers

2. grepai_trace_callers

Find all functions that call a specified symbol.
查找调用指定符号的所有函数。

Parameters

参数

ParameterTypeRequiredDefaultDescription
symbol
stringYes-Function/method name to trace
compact
booleanNofalseReturn compact output (no context)
format
stringNo"json"Output format: "json" or "toon" (v0.26.0+)
参数类型是否必填默认值描述
symbol
string-要追踪的函数/方法名称
compact
booleanfalse返回精简输出(不包含上下文)
format
string"json"输出格式:"json" 或 "toon"(v0.26.0+)

Example Request

请求示例

json
{
  "tool": "grepai_trace_callers",
  "parameters": {
    "symbol": "Login",
    "compact": true
  }
}
json
{
  "tool": "grepai_trace_callers",
  "parameters": {
    "symbol": "Login",
    "compact": true
  }
}

Response (Compact)

响应(精简模式)

json
{
  "q": "Login",
  "m": "callers",
  "c": 3,
  "r": [
    {"f": "handlers/auth.go", "l": 42, "fn": "HandleAuth"},
    {"f": "handlers/auth_test.go", "l": 15, "fn": "TestLoginSuccess"},
    {"f": "cmd/main.go", "l": 88, "fn": "RunCLI"}
  ]
}
json
{
  "q": "Login",
  "m": "callers",
  "c": 3,
  "r": [
    {"f": "handlers/auth.go", "l": 42, "fn": "HandleAuth"},
    {"f": "handlers/auth_test.go", "l": 15, "fn": "TestLoginSuccess"},
    {"f": "cmd/main.go", "l": 88, "fn": "RunCLI"}
  ]
}

Response (Full)

响应(完整模式)

json
{
  "query": "Login",
  "mode": "callers",
  "count": 3,
  "results": [
    {
      "file": "handlers/auth.go",
      "line": 42,
      "caller": "HandleAuth",
      "context": "user.Login(ctx, credentials)"
    }
  ]
}

json
{
  "query": "Login",
  "mode": "callers",
  "count": 3,
  "results": [
    {
      "file": "handlers/auth.go",
      "line": 42,
      "caller": "HandleAuth",
      "context": "user.Login(ctx, credentials)"
    }
  ]
}

3. grepai_trace_callees

3. grepai_trace_callees

Find all functions called by a specified symbol.
查找指定符号调用的所有函数。

Parameters

参数

ParameterTypeRequiredDefaultDescription
symbol
stringYes-Function/method name to trace
compact
booleanNofalseReturn compact output (no context)
format
stringNo"json"Output format: "json" or "toon" (v0.26.0+)
参数类型是否必填默认值描述
symbol
string-要追踪的函数/方法名称
compact
booleanfalse返回精简输出(不包含上下文)
format
string"json"输出格式:"json" 或 "toon"(v0.26.0+)

Example Request

请求示例

json
{
  "tool": "grepai_trace_callees",
  "parameters": {
    "symbol": "ProcessOrder",
    "compact": true
  }
}
json
{
  "tool": "grepai_trace_callees",
  "parameters": {
    "symbol": "ProcessOrder",
    "compact": true
  }
}

Response (Compact)

响应(精简模式)

json
{
  "q": "ProcessOrder",
  "m": "callees",
  "c": 4,
  "r": [
    {"f": "services/order.go", "l": 45, "fn": "validateOrder"},
    {"f": "services/order.go", "l": 48, "fn": "calculateTotal"},
    {"f": "services/order.go", "l": 51, "fn": "applyDiscount"},
    {"f": "services/order.go", "l": 55, "fn": "sendConfirmation"}
  ]
}

json
{
  "q": "ProcessOrder",
  "m": "callees",
  "c": 4,
  "r": [
    {"f": "services/order.go", "l": 45, "fn": "validateOrder"},
    {"f": "services/order.go", "l": 48, "fn": "calculateTotal"},
    {"f": "services/order.go", "l": 51, "fn": "applyDiscount"},
    {"f": "services/order.go", "l": 55, "fn": "sendConfirmation"}
  ]
}

4. grepai_trace_graph

4. grepai_trace_graph

Build a complete call graph starting from a symbol.
从指定符号开始构建完整的调用图。

Parameters

参数

ParameterTypeRequiredDefaultDescription
symbol
stringYes-Root function for the graph
depth
numberNo2Maximum recursion depth
compact
booleanNofalseReturn compact JSON format
format
stringNo"json"Output format: "json" or "toon" (v0.26.0+)
参数类型是否必填默认值描述
symbol
string-调用图的根函数
depth
number2最大递归深度
compact
booleanfalse返回精简JSON格式
format
string"json"输出格式:"json" 或 "toon"(v0.26.0+)

Example Request

请求示例

json
{
  "tool": "grepai_trace_graph",
  "parameters": {
    "symbol": "main",
    "depth": 3,
    "compact": true
  }
}
json
{
  "tool": "grepai_trace_graph",
  "parameters": {
    "symbol": "main",
    "depth": 3,
    "compact": true
  }
}

Response (Compact)

响应(精简模式)

json
{
  "q": "main",
  "d": 3,
  "r": {
    "n": "main",
    "c": [
      {
        "n": "initialize",
        "c": [
          {"n": "loadConfig"},
          {"n": "connectDB"}
        ]
      },
      {
        "n": "startServer",
        "c": [
          {"n": "registerRoutes"}
        ]
      }
    ]
  },
  "s": {"nodes": 6, "depth": 3}
}
json
{
  "q": "main",
  "d": 3,
  "r": {
    "n": "main",
    "c": [
      {
        "n": "initialize",
        "c": [
          {"n": "loadConfig"},
          {"n": "connectDB"}
        ]
      },
      {
        "n": "startServer",
        "c": [
          {"n": "registerRoutes"}
        ]
      }
    ]
  },
  "s": {"nodes": 6, "depth": 3}
}

Response (Full)

响应(完整模式)

json
{
  "query": "main",
  "mode": "graph",
  "depth": 3,
  "root": {
    "name": "main",
    "file": "cmd/main.go",
    "line": 10,
    "children": [
      {
        "name": "initialize",
        "file": "cmd/main.go",
        "line": 15,
        "children": [...]
      }
    ]
  },
  "stats": {
    "nodes": 6,
    "max_depth": 3
  }
}

json
{
  "query": "main",
  "mode": "graph",
  "depth": 3,
  "root": {
    "name": "main",
    "file": "cmd/main.go",
    "line": 10,
    "children": [
      {
        "name": "initialize",
        "file": "cmd/main.go",
        "line": 15,
        "children": [...]
      }
    ]
  },
  "stats": {
    "nodes": 6,
    "max_depth": 3
  }
}

5. grepai_index_status

5. grepai_index_status

Check the health and status of the code index.
检查代码索引的健康状态。

Parameters

参数

ParameterTypeRequiredDefaultDescription
verbose
booleanNofalseInclude detailed information
format
stringNo"json"Output format: "json" or "toon" (v0.26.0+)
参数类型是否必填默认值描述
verbose
booleanfalse包含详细信息
format
string"json"输出格式:"json" 或 "toon"(v0.26.0+)

Example Request

请求示例

json
{
  "tool": "grepai_index_status",
  "parameters": {
    "verbose": true
  }
}
json
{
  "tool": "grepai_index_status",
  "parameters": {
    "verbose": true
  }
}

Response

响应

json
{
  "status": "healthy",
  "project": "/path/to/project",
  "embedder": {
    "provider": "ollama",
    "model": "nomic-embed-text",
    "status": "connected"
  },
  "store": {
    "backend": "gob",
    "location": ".grepai/index.gob"
  },
  "index": {
    "files": 245,
    "chunks": 1234,
    "last_updated": "2025-01-28T10:30:00Z"
  },
  "daemon": {
    "running": true,
    "pid": 12345
  }
}
json
{
  "status": "healthy",
  "project": "/path/to/project",
  "embedder": {
    "provider": "ollama",
    "model": "nomic-embed-text",
    "status": "connected"
  },
  "store": {
    "backend": "gob",
    "location": ".grepai/index.gob"
  },
  "index": {
    "files": 245,
    "chunks": 1234,
    "last_updated": "2025-01-28T10:30:00Z"
  },
  "daemon": {
    "running": true,
    "pid": 12345
  }
}

Compact Format Reference

精简格式参考

When
compact: true
, responses use abbreviated keys:
Full KeyCompact KeyDescription
query
q
Search query or symbol
results
r
Results array
total
t
Total count
count
c
Count
score
s
Similarity score
file
f
File path
line
l
Line number(s)
mode
m
Trace mode
depth
d
Graph depth
name
n
Node name
children
c
Child nodes
stats
s
Statistics
function
fn
Function name
当设置
compact: true
时,响应使用缩写键:
完整键名精简键名描述
query
q
搜索查询或符号
results
r
结果数组
total
t
总数量
count
c
数量
score
s
相似度分数
file
f
文件路径
line
l
行号
mode
m
追踪模式
depth
d
调用图深度
name
n
节点名称
children
c
子节点
stats
s
统计信息
function
fn
函数名称

Token Efficiency

Token效率

Compact mode reduces tokens significantly:
Response TypeFullCompactSavings
Search (5 results)~800~15081%
Trace callers (10)~600~12080%
Trace graph (depth 3)~1200~25079%
精简模式可显著减少Token使用量:
响应类型完整模式精简模式节省比例
搜索(5条结果)~800~15081%
调用者追踪(10条)~600~12080%
调用图追踪(深度3)~1200~25079%

Error Responses

错误响应

Index Not Found

索引未找到

json
{
  "error": "Index not found. Run 'grepai watch' first.",
  "code": "INDEX_NOT_FOUND"
}
json
{
  "error": "Index not found. Run 'grepai watch' first.",
  "code": "INDEX_NOT_FOUND"
}

Embedder Connection Failed

嵌入服务连接失败

json
{
  "error": "Cannot connect to embedding provider. Is Ollama running?",
  "code": "EMBEDDER_UNAVAILABLE"
}
json
{
  "error": "Cannot connect to embedding provider. Is Ollama running?",
  "code": "EMBEDDER_UNAVAILABLE"
}

Symbol Not Found

符号未找到

json
{
  "error": "Symbol 'FunctionName' not found in index.",
  "code": "SYMBOL_NOT_FOUND"
}
json
{
  "error": "Symbol 'FunctionName' not found in index.",
  "code": "SYMBOL_NOT_FOUND"
}

Invalid Parameters

参数无效

json
{
  "error": "Parameter 'query' is required.",
  "code": "INVALID_PARAMETERS"
}
json
{
  "error": "Parameter 'query' is required.",
  "code": "INVALID_PARAMETERS"
}

Best Practices for AI Integration

AI集成最佳实践

  1. Use compact mode: Reduces token usage by ~80%
  2. Limit results: Request only what you need
  3. Check status first: Use
    grepai_index_status
    before searches
  4. Handle errors: Check for error responses
  5. Combine tools: Search + trace for full understanding
  1. 使用精简模式:减少约80%的Token使用量
  2. 限制结果数量:只请求需要的内容
  3. 先检查状态:在搜索前使用
    grepai_index_status
  4. 处理错误:检查错误响应
  5. 组合工具使用:搜索+追踪以全面了解代码

MCP Protocol Details

MCP协议细节

Request Format

请求格式

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "grepai_search",
    "arguments": {
      "query": "authentication",
      "limit": 5,
      "compact": true
    }
  }
}
json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "grepai_search",
    "arguments": {
      "query": "authentication",
      "limit": 5,
      "compact": true
    }
  }
}

Response Format

响应格式

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "{\"q\":\"authentication\",\"r\":[...],\"t\":5}"
      }
    ]
  }
}
json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "{\"q\":\"authentication\",\"r\":[...],\"t\":5}"
      }
    ]
  }
}

Output Format

输出格式

MCP tools reference summary:
📚 GrepAI MCP Tools Reference

Tools available:

1. grepai_search
   - Semantic code search
   - Params: query*, limit, compact

2. grepai_trace_callers
   - Find function callers
   - Params: symbol*, compact

3. grepai_trace_callees
   - Find function callees
   - Params: symbol*, compact

4. grepai_trace_graph
   - Build call graph
   - Params: symbol*, depth, compact

5. grepai_index_status
   - Check index health
   - Params: verbose

* = required parameter

Compact mode: ~80% token reduction
MCP工具参考摘要:
📚 GrepAI MCP工具参考文档

可用工具:

1. grepai_search
   - 语义代码搜索
   - 参数:query*, limit, compact

2. grepai_trace_callers
   - 查找函数调用者
   - 参数:symbol*, compact

3. grepai_trace_callees
   - 查找函数被调用者
   - 参数:symbol*, compact

4. grepai_trace_graph
   - 构建调用图
   - 参数:symbol*, depth, compact

5. grepai_index_status
   - 检查索引健康状态
   - 参数:verbose

* = 必填参数

精简模式:约80% Token节省