Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix search tool parser
  • Loading branch information
AlecHenx committed Jun 18, 2025
commit 95f0429c9ba095ec19d16c0cbee480abc77dfeca
17 changes: 14 additions & 3 deletions verl/tools/mcp_search_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import json
import logging
import os
import re
from typing import TypeVar

from verl.tools.mcp_base_tool import MCPBaseTool
Expand Down Expand Up @@ -44,9 +45,19 @@ def post_process(self, content: list):
for part in content:
if part.type != "text":
continue
# FIXME(hechanghao): use json load for parsing result string
res += part.text
res_cnt += 1
text = part.text.replace("'", '"')
query_match = re.search(r'query"\s*:\s*"([^"]+)"', text)
query = query_match.group(1) if query_match else ""
query_list.append(query)

title_matches = re.findall(r'"title"\s*:', text)
title_count = len(title_matches)

results_match = re.search(r'"results"\s*:\s*(\[.*?\])', text, re.DOTALL)
results_content = results_match.group(1) if results_match else ""

res += results_content
res_cnt += title_count
except json.JSONDecodeError:
err_msg = "json parse error."
logger.error(err_msg)
Expand Down