Skip to content

Commit 5bb8f1a

Browse files
committed
Update codebase_search to return XML string instead of dictionary.
1 parent d6d1df4 commit 5bb8f1a

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/tests/test_search_tool.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
@pytest.mark.asyncio
1010
@patch('tools.search.get_api_key_from_context')
11-
async def test_codebase_search_returns_dict(mock_get_api_key):
12-
"""Test that codebase_search returns a dictionary with structured_content."""
11+
async def test_codebase_search_returns_xml_string(mock_get_api_key):
12+
"""Test that codebase_search returns an XML string directly."""
1313
# Mock the API key function
1414
mock_get_api_key.return_value = "test_key"
1515

@@ -56,15 +56,9 @@ async def test_codebase_search_returns_dict(mock_get_api_key):
5656
include_content=False
5757
)
5858

59-
# Verify result is a dictionary
60-
assert isinstance(result, dict), "codebase_search should return a dictionary"
61-
62-
# Verify it has structured_content field
63-
assert "structured_content" in result, "Result should have structured_content field"
64-
65-
# Verify the structured_content is a string (XML)
66-
assert isinstance(result["structured_content"], str), "structured_content should be a string"
59+
# Verify result is a string (XML)
60+
assert isinstance(result, str), "codebase_search should return an XML string"
6761

6862
# Verify it contains expected XML structure
69-
assert "<results>" in result["structured_content"], "Should contain results tag"
70-
assert "<search_result" in result["structured_content"], "Should contain search_result tag"
63+
assert "<results>" in result, "Should contain results tag"
64+
assert "<search_result" in result, "Should contain search_result tag"

src/tools/search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Search tool implementation."""
22

3-
from typing import Dict, List, Optional, Union
3+
from typing import Any, Dict, List, Optional, Union
44
from urllib.parse import urljoin
55

66
import httpx
@@ -16,7 +16,7 @@ async def codebase_search(
1616
data_source_ids: Optional[Union[str, List[str]]] = None,
1717
mode: str = "auto",
1818
include_content: bool = False
19-
) -> Dict:
19+
) -> Union[str, Dict[str, Any]]:
2020
"""
2121
Use `codebase_search` tool to search for code in the codebase.
2222
@@ -154,8 +154,8 @@ async def codebase_search(
154154
# Transform the response to XML format for better LLM processing
155155
xml_content = transform_search_response_to_xml(search_results, include_content)
156156

157-
# Return as a dictionary with structured_content field for MCP compatibility
158-
return {"structured_content": xml_content}
157+
# Return XML string directly
158+
return xml_content
159159

160160
except (httpx.HTTPStatusError, Exception) as e:
161161
error_msg = await handle_api_error(ctx, e, "code search")

0 commit comments

Comments
 (0)