antgroup / antgroup/YASA-Engine
[OSS26] 关键词搜索代码 search_code_by_keyword
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 323
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
接口介绍
在指定代码仓库内按关键词检索代码,支持普通字符串与正则两种模式,返回所有命中的文件路径、行号与代码片段(含上下文行)。
工具名
search_code_by_keyword
背景与目标
很多程序分析场景的第一步是定位代码:LLM Agent 接到一个安全审计任务时,先要找到"潜在风险关键词"出现的位置(例如 Runtime.exec、eval、SELECT *)。这是程序分析 MCP 的基础能力,要求在指定本地仓库范围内可用,不依赖外部 SaaS。
目标:实现一个 MCP tool,接收关键词和(可选的)路径前缀,返回所有匹配位置 + 命中行片段。
输入参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
keyword |
string | 是 | 搜索关键词,支持普通字符串,可选支持正则(由 is_regex 控制) |
repository_path |
string | 是 | 仓库本地绝对路径 |
path_prefix |
string | 否 | 限定搜索的子目录前缀,如 src/main/java/ |
is_regex |
bool | 否 | 默认 false,true 时 keyword 按 ECMAScript 正则解释 |
max_results |
int | 否 | 默认 100,最大 1000 |
case_sensitive |
bool | 否 | 默认 false |
输出结构
{
"total_matches": 42,
"results": [
{
"file_path": "src/main/java/com/example/UserController.java",
"line_number": 87,
"column_start": 12,
"column_end": 28,
"line_content": " Runtime.exec(userInput);",
"context_before": [" public void run(String userInput) {"],
"context_after": [" }"]
}
]
}
验收标准
- 在 1k-file 中等仓库上搜索高频词响应 < 2s
- 二进制文件、
.git/、node_modules/、target/默认排除 - 支持
path_prefix过滤 - 单元测试覆盖:正则模式、大小写、空结果、超过 max_results 截断
- 与
bootstrap_mcp_framework的注册机制对齐
预估工作量
1-2 人日
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the MCP tool registration mechanism used by bootstrap_mcp_framework and the project's unit-test layout. Implement the search_code_by_keyword entry point according to the listed inputs and output, then add tests for regex, case sensitivity, empty results, and max_results truncation. Done means the exclusions, path_prefix filtering, registration, and stated response-time target are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100