Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion Detection/context_providers/source_code_analyzer_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,22 @@ def search_code_patterns(pattern_description: str, server_categories: List[str]
else:
filtered_servers = servers

# Provide clean metadata without cheating indicators: registry paths
# name the dataset directory (benign/vulnerable/environment split).
available_servers = [
{
"name": server.get("name"),
"category": server.get("category"),
"description": server.get("description"),
"capabilities": server.get("capabilities", []),
}
for server in filtered_servers
]

return {
"search_pattern": pattern_description,
"server_categories": server_categories or "all",
"available_servers": filtered_servers,
"available_servers": available_servers,
"analysis_guidance": f"Search for the pattern '{pattern_description}' in the source code of the listed servers"
}

Expand Down
32 changes: 32 additions & 0 deletions Detection/tests/test_source_code_analyzer_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,35 @@ def test_non_text_codec_preserves_entrypoint_and_other_dependencies(
assert [item["path"] for item in row["source_files"]] == ["server.py", "good.py"]
assert row["source_files"][1]["source_code"] == "VALUE = 2\n"
assert row["source_bundle_complete"] is False


def test_search_code_patterns_omits_registry_paths(monkeypatch):
"""Registry paths name the dataset split (e.g. mcp_servers_1) and must not
reach the reasoning agent; list_mcp_servers already strips them."""
monkeypatch.setattr(
analyzer,
"source_registry",
{
"mcp_servers": [
{
"name": "example",
"path": "source_codes/mcp_servers_1/example/example.py",
"category": "test",
"description": "example server",
"capabilities": ["read"],
}
]
},
)

result = analyzer.search_code_patterns("network calls", ["test"])

assert result["available_servers"] == [
{
"name": "example",
"category": "test",
"description": "example server",
"capabilities": ["read"],
}
]
assert "mcp_servers_1" not in repr(result)