[yasamcp] get_file_by_keyword / keywords 在 use_regex=True 且传入多关键词(或列表)时必现 TypeError 崩溃
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read yasamcp/src/yasa_mcp/tools/ripgrep/ripgrep_tool.py around search_keywords_with_line, especially how it builds the pattern for regex and literal searches. Add tests for regex searches with one and multiple keywords, then run those tests. Done means the searches return matches without a TypeError and preserve the intended behavior for each keyword.
Written by the indexing model from the issue text.
Description
问题描述
使用 yasamcp 的关键字搜索功能(MCP 工具 get_file_by_keyword 或 CLI 命令 yasamcp keywords),在开启正则模式(use_regex=True / --use-regex)且进入批量搜索分支 search_keywords_with_line 时,100% 抛出 TypeError 崩溃:
- MCP 路径:
keyword传入list[str](即使只包含 1 个元素,例如["foo"])且use_regex=True时必现崩溃; - CLI 路径:
yasamcp keywords --use-regex传入 ≥ 2 个关键词时必现崩溃; - 同一组关键词在关闭正则(
use_regex=False)或以单个str传入时均工作正常。
环境信息
- yasamcp 版本:
YASA-MCP 1.2.0 (build 20260924, commit f5965e6)(上游main分支当前最新相关提交59d22349同样存在该问题) - 操作系统:Ubuntu 24.04.4 LTS (x86_64, WSL2)
- ripgrep:
14.1.1(随yasamcptools 分发)
最小复现步骤
mkdir -p /tmp/yasamcp-repro
printf 'def hello():\n return "foo"\n' > /tmp/yasamcp-repro/demo.py
yasamcp init /tmp/yasamcp-repro
# 1. 单关键词 + --use-regex:正常命中(返回 demo.py 第 2 行)
yasamcp keywords -p /tmp/yasamcp-repro --use-regex -j foo
# 2. 多关键词 + 不开正则:正常命中(返回 demo.py 第 1、2 行)
yasamcp keywords -p /tmp/yasamcp-repro -j foo hello
# 3. 多关键词 + --use-regex:100% 必现崩溃
yasamcp keywords -p /tmp/yasamcp-repro --use-regex -j foo hello
实际报错输出:
Traceback (most recent call last):
...
File "yasa_mcp/service/code_search_service.py", line 820, in get_file_by_keyword
File "yasa_mcp/util/timer_util.py", line 166, in wrapper
File "yasa_mcp/tools/ripgrep/ripgrep_tool.py", line 183, in search_keywords_with_line
TypeError: sequence item 0: expected str instance, tuple found
MCP 侧复现:通过 MCP stdio 调用
get_file_by_keyword(project_path="/tmp/yasamcp-repro", keyword=["foo"], use_regex=True)同样在search_keywords_with_line:183抛出完全相同的TypeError。
根因定位
问题位于 yasamcp/src/yasa_mcp/tools/ripgrep/ripgrep_tool.py 第 180–183 行:
values = tuple(value for value in keywords if value)
if not values:
return []
pattern = "(?:" + "|".join(values if use_regex else re.escape(value) for value in values) + ")"
第 183 行生成器表达式中将循环变量 value 误写成了外层元组 values。当 use_regex=True 时,生成器产出的是 tuple[str, ...] 而非 str,导致 "|".join(...) 直接抛出 TypeError: sequence item 0: expected str instance, tuple found。
上游调用路径(yasamcp/src/yasa_mcp/service/code_search_service.py 第 809–822 行)在 isinstance(keyword, str) 为 False 时统一进入 search_keywords_with_line,因此 MCP 传单元素列表(如 ["foo"])与 CLI 传多关键词都会命中此崩溃。
修复建议
- 修正变量名,并对正则分支逐个包裹非捕获分组
(?:...)(避免子模式中的|优先级串扰,同时限制前导内联标志如(?i)foo仅作用于当前分支,而不泄漏到后续分支):
(或改为向pattern = "|".join( f"(?:{value})" if use_regex else re.escape(value) for value in values )rg传入多个-e <pattern>参数并以--终止选项解析。) - 建议为
RipgrepTool.search_keywords_with_line补充use_regex=True的单元测试(覆盖 1 元素列表、多元素列表及含内联标志的场景)。
- Dominant language
- TypeScript
- Stars
- 339
- Forks
- 40
- Avg merge
- 2h 1m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from antgroup/YASA-Engine
-
Difficulty 3/5 1-2 days Newbie friendliness 63/100
antgroup/YASA-Engine#171 ·
-
整个工程扫描,异常退出Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
antgroup/YASA-Engine#166 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
antgroup/YASA-Engine#162 ·
-
pkg 二进制在大中型 Java 项目上因 Node 18.5.0 V8 bug 崩溃May be free again @AntJiuFo claimed this 138 days ago, and no pull request is open. Open
antgroup/YASA-Engine#143 · 1 assignee ·
-
OSS26-Team
Difficulty 5/5 Over a week Newbie friendliness 35/100
antgroup/YASA-Engine#142 ·
All issues in antgroup/YASA-Engine
Similar issues
-
blocklist addition
Difficulty 1/5 Under an hour Newbie friendliness 76/100
MetaMask/eth-phishing-detect#319194 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
continuedev/continue#13533 · 1 comment ·
Maintainers usually reply within 6 days
-
bug codex:automation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
genfeedai/genfeed.ai#12060 ·
Maintainers usually reply within 1 day
-
bounty good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
fitzss/valun-open#15 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day