fix(context-hub): filtrage per-agent scope infra (bruit mcp-nas non pertinent pour Gemini/Hermes) + purge cle obsolete mcp_nas_heredoc_piege_confirme

This commit is contained in:
2026-08-16 21:35:05 +00:00
parent 39ee17dcac
commit 210669ef00
+5 -4
View File
@@ -11,7 +11,7 @@ except ImportError:
from mcp.types import Tool, TextContent from mcp.types import Tool, TextContent
from app.auth import get_current_agent from app.auth import get_current_agent
from app.scopes import has_scope_access, ALL_SCOPES from app.scopes import has_scope_access, ALL_SCOPES
from app.models import (get_rule, get_all_rules, get_all_ports, get_port, set_rule, get_agent_by_key, update_key_last_used, add_memory_entry, list_memory_entries) from app.models import (get_rule, get_all_rules, get_all_ports, get_port, set_rule, get_agent_by_key, update_key_last_used, add_memory_entry, list_memory_entries, filter_content_for_agent)
from app.git_sync import push_scope_markdown from app.git_sync import push_scope_markdown
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -141,7 +141,7 @@ async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
rule = await get_rule(scope) rule = await get_rule(scope)
if not rule: if not rule:
return [TextContent(type="text", text=json.dumps({"error": "Scope not found"}))] return [TextContent(type="text", text=json.dumps({"error": "Scope not found"}))]
return [TextContent(type="text", text=json.dumps(rule))] return [TextContent(type="text", text=json.dumps(filter_content_for_agent(rule, caller_agent)))]
elif name == "get_ports": elif name == "get_ports":
if not has_scope_access(caller_agent, "infra"): if not has_scope_access(caller_agent, "infra"):
@@ -156,6 +156,7 @@ async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
for scope, content_ in all_rules.items(): for scope, content_ in all_rules.items():
if not has_scope_access(caller_agent, scope): if not has_scope_access(caller_agent, scope):
continue continue
content_ = filter_content_for_agent(content_, caller_agent)
if query in json.dumps(content_).lower(): if query in json.dumps(content_).lower():
results.append({"scope": scope, "content": content_}) results.append({"scope": scope, "content": content_})
return [TextContent(type="text", text=json.dumps(results))] return [TextContent(type="text", text=json.dumps(results))]
@@ -165,7 +166,7 @@ async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
config = {} config = {}
for scope in ALL_SCOPES: for scope in ALL_SCOPES:
if has_scope_access(caller_agent, scope): if has_scope_access(caller_agent, scope):
config[scope] = all_rules.get(scope, {}) config[scope] = filter_content_for_agent(all_rules.get(scope, {}), caller_agent)
return [TextContent(type="text", text=json.dumps(config))] return [TextContent(type="text", text=json.dumps(config))]
elif name == "check_port": elif name == "check_port":
@@ -183,7 +184,7 @@ async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
result = {} result = {}
for scope in ALL_SCOPES: for scope in ALL_SCOPES:
if has_scope_access(caller_agent, scope): if has_scope_access(caller_agent, scope):
result[scope] = all_rules.get(scope, {}) result[scope] = filter_content_for_agent(all_rules.get(scope, {}), caller_agent)
return [TextContent(type="text", text=json.dumps({"agent": caller_agent, "scopes": result}))] return [TextContent(type="text", text=json.dumps({"agent": caller_agent, "scopes": result}))]
elif name == "update_rule": elif name == "update_rule":