Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(mcp): accept max_results as an alias for top_k in retrieve_context (#1826)
Maxia06aef9201b5
diff --git a/semantica_mcp/mcp/schemas.py b/semantica_mcp/mcp/schemas.pyindex b5827384..f7e89409 100644--- a/semantica_mcp/mcp/schemas.py+++ b/semantica_mcp/mcp/schemas.py@@ -363,6 +363,12 @@ RETRIEVE_CONTEXT = {"maximum": 10,"description": "Maximum number of chunks to return (default: 5, capped at 10)",},+ "max_results": {+ "type": "integer",+ "minimum": 1,+ "maximum": 10,+ "description": "Alias for top_k, as in the Python retrieve_context API; top_k wins if both are set",+ },"project": {"type": "string","description": "Only return chunks stored under this project namespace (optional)",diff --git a/semantica_mcp/mcp/tools/retrieval.py b/semantica_mcp/mcp/tools/retrieval.pyindex 52a53fec..aabe5c52 100644--- a/semantica_mcp/mcp/tools/retrieval.py+++ b/semantica_mcp/mcp/tools/retrieval.py@@ -418,7 +418,11 @@ def handle_retrieve_context(args: dict) -> dict:if not query:return {"error": "query is required", "results": []}try:- top_k = max(1, min(int(args.get("top_k", 5)), MAX_TOP_K))+ # max_results is the name the Python retrieve_context API uses+ limit = args.get("top_k")+ if limit is None:+ limit = args.get("max_results", 5)+ top_k = max(1, min(int(limit), MAX_TOP_K))except (TypeError, ValueError):top_k = 5project = str(args.get("project", "")).strip() or Nonediff --git a/tests/test_mcp_semantic_retrieval.py b/tests/test_mcp_semantic_retrieval.pyindex c847ea2c..5223c963 100644--- a/tests/test_mcp_semantic_retrieval.py+++ b/tests/test_mcp_semantic_retrieval.py@@ -311,6 +311,16 @@ class TestRetrieveContext(InmemoryBackendTestBase):result = handle_retrieve_context({"query": "k01", "top_k": 99})self.assertEqual(result["count"], 10)+ def test_max_results_is_an_alias_for_top_k(self):+ result = handle_retrieve_context({"query": "collateral", "max_results": 1})+ self.assertEqual(result["count"], 1)++ def test_top_k_wins_over_max_results(self):+ result = handle_retrieve_context(+ {"query": "collateral", "top_k": 1, "max_results": 3}+ )+ self.assertEqual(result["count"], 1)+def test_project_filter_narrows_results(self):result = handle_retrieve_context({"query": "collateral", "project": "billing"})for r in result["results"]: