feat(mcp): let a deployment declare local MCP tools (#6330)

* feat(mcp): let a deployment declare local MCP tools

Tools served by a user-configured MCP server are absent from
TOOL_CAPABILITIES, so they are unknown and fail high. For a server with
both a read and a write tool that is unusable: the read result arms the
post-external gate, because an unknown result is not SYSTEM integrity,
and the write that follows is refused until separately authorized. Every
second call needs an approval, for a server that never leaves the host.

Add ODYSSEUS_LOCAL_MCP_READ_TOOLS and ODYSSEUS_LOCAL_MCP_WRITE_TOOLS.
Declared read tools become READ_PRIVATE with SYSTEM integrity, so their
output no longer arms the gate; declared write tools become WRITE_PRIVATE
and stay inside POST_EXTERNAL_BLOCKED_EFFECTS, so a run tainted by real
external content still requires the approval. Unset variables keep the
current behaviour exactly.

Fixes #6329

* fix(mcp): secure local MCP authorization and preserve external taint gate

Keep declared local MCP read tool results untrusted with EXTERNAL_UNTRUSTED
integrity so they continue to arm the external-context gate. Introduce a
narrowly scoped continuation exception for declared local MCP writes on
the same server when no external taint or explicit error payloads enter
the run. Preserves gate protection for shell execution, network egress,
email, and cross-server actions.

Fixes #6329

* fix(mcp): resolve local continuation against stdio transport and enforce built-in classifications

Resolve declared local MCP continuation operations against connected stdio
servers and enforce established built-in tool security classifications.
Ensure remote HTTP and SSE servers, unverified transports, replaced sessions,
stale configurations, and operations with dangerous effects or missing request
grants fail closed.

* fix(mcp): require sealed authority for local continuation

* fix(mcp): seal local tool admission and synchronize GPU stacks

---------

Co-authored-by: Alexandre Teixeira <general@alexandreteixeira.dev>
This commit is contained in:
JulianFriedle
2026-11-01 03:19:59 +00:00
committed by GitHub
co-authored by Alexandre Teixeira
parent 6f2b58c896
commit 6fced41220
13 changed files with 1478 additions and 8 deletions
+11
View File
@@ -105,6 +105,17 @@ SEARXNG_INSTANCE=http://localhost:8080
# trusted single-user setups that accept injected content reaching side-effect tools. # trusted single-user setups that accept injected content reaching side-effect tools.
# ODYSSEUS_TOOL_APPROVAL_GATE=1 # ODYSSEUS_TOOL_APPROVAL_GATE=1
# Comma-separated list of exact qualified MCP read and write tool names
# on host-local servers. Only explicitly configured stdio MCP servers qualify.
# Declarations do not override built-in tool effects. Declared reads remain
# untrusted (EXTERNAL_UNTRUSTED) to prevent prompt injections from reaching shell
# or network tools, but allow continuation to declared non-destructive write tools
# on the exact same stdio server without repeated approvals. Stdio transport does
# not guarantee network isolation. Authorization must still originate from the
# trusted request. Automatic same-store writes carry residual prompt-injection risk.
# ODYSSEUS_LOCAL_MCP_READ_TOOLS=mcp__notes__search_notes,mcp__notes__read_note
# ODYSSEUS_LOCAL_MCP_WRITE_TOOLS=mcp__notes__create_note,mcp__notes__update_note
# Mark session cookies Secure. Left unset, this follows the request scheme: # Mark session cookies Secure. Left unset, this follows the request scheme:
# an HTTPS login gets a Secure cookie, a plain-HTTP one does not. Set true to # an HTTPS login gets a Secure cookie, a plain-HTTP one does not. Set true to
# force it on, or false to force it off while you still serve plain HTTP. # force it on, or false to force it off while you still serve plain HTTP.
+2 -1
View File
@@ -66,10 +66,11 @@ External content that reaches the LLM is treated as untrusted via `src/prompt_se
It is on unless `ODYSSEUS_TOOL_APPROVAL_GATE` is set to a falsy value (`0`/`false`/`no`/`off`). Request authority narrows which tool families a turn may use, but within an admitted family it does not bind the exact action: a request to read email admits `send_email` and `delete_email`, and agent processes inherit the host network. Until those are covered by their own boundaries, this gate is what stops an injected instruction from reaching them. Turning it off lets a successful injection reach `bash`, `host_shell`, `send_email` and `delete_email` without a separate confirmation. It is on unless `ODYSSEUS_TOOL_APPROVAL_GATE` is set to a falsy value (`0`/`false`/`no`/`off`). Request authority narrows which tool families a turn may use, but within an admitted family it does not bind the exact action: a request to read email admits `send_email` and `delete_email`, and agent processes inherit the host network. Until those are covered by their own boundaries, this gate is what stops an injected instruction from reaching them. Turning it off lets a successful injection reach `bash`, `host_shell`, `send_email` and `delete_email` without a separate confirmation.
Two exemptions apply even when the gate is on, both deliberate: Three exemptions apply even when the gate is on, all deliberate:
- Sources in `_CONTROL_PLANE_CONTEXT_SOURCES` (skills, runtime descriptors, the open editor document, the open email, uploaded files) are treated as control-plane metadata and still permit read-only tools. - Sources in `_CONTROL_PLANE_CONTEXT_SOURCES` (skills, runtime descriptors, the open editor document, the open email, uploaded files) are treated as control-plane metadata and still permit read-only tools.
- A TUI run that advertises a host shell bridge and declares `unattended_mode` exempts the local execution set in `TUI_CLIENT_TOOL_NAMES`. Personal, network and deployment-local tools are never exempted. - A TUI run that advertises a host shell bridge and declares `unattended_mode` exempts the local execution set in `TUI_CLIENT_TOOL_NAMES`. Personal, network and deployment-local tools are never exempted.
- Narrow continuation for local MCP tools declared via `ODYSSEUS_LOCAL_MCP_READ_TOOLS` and `ODYSSEUS_LOCAL_MCP_WRITE_TOOLS`: Only explicitly configured stdio MCP servers qualify; remote HTTP and SSE servers fail closed. Declarations never override built-in tool effects, so built-in email, browser, memory, image generation, and other built-in servers cannot receive continuation exceptions. Declared read tools remain untrusted (`EXTERNAL_UNTRUSTED`) to ensure that prompt injections in local data cannot reach shell, network, or unrelated tools without approval. Stdio transport does not guarantee network isolation, as local processes may still reach the host network. However, declared non-destructive write tools on the exact same stdio MCP server are permitted to continue without an approval prompt if the only untrusted context in the run was produced by declared local reads on that same server, without any explicit error or external taint. Genuinely external content (web search, web fetch, emails, external message context) blocks these writes. Authorization must still originate from the trusted request: request authority must permit the tool and retain the sealed backend resource grant. The residual same-store write risk (the agent writing to the same local store after reading a local prompt injection) remains subject to the user's initial request authority.
## Security Headers ## Security Headers
+2
View File
@@ -73,6 +73,8 @@ services:
- ODYSSEUS_CAPTURE_MODEL_REQUESTS=${ODYSSEUS_CAPTURE_MODEL_REQUESTS:-0} - ODYSSEUS_CAPTURE_MODEL_REQUESTS=${ODYSSEUS_CAPTURE_MODEL_REQUESTS:-0}
- ODYSSEUS_MCP_EMAIL_OWNER=${ODYSSEUS_MCP_EMAIL_OWNER:-} - ODYSSEUS_MCP_EMAIL_OWNER=${ODYSSEUS_MCP_EMAIL_OWNER:-}
- ODYSSEUS_SCRIPT_HOST=${ODYSSEUS_SCRIPT_HOST:-localhost} - ODYSSEUS_SCRIPT_HOST=${ODYSSEUS_SCRIPT_HOST:-localhost}
- ODYSSEUS_LOCAL_MCP_READ_TOOLS=${ODYSSEUS_LOCAL_MCP_READ_TOOLS:-}
- ODYSSEUS_LOCAL_MCP_WRITE_TOOLS=${ODYSSEUS_LOCAL_MCP_WRITE_TOOLS:-}
- ODYSSEUS_CHAT_UPLOAD_MAX_BYTES=${ODYSSEUS_CHAT_UPLOAD_MAX_BYTES:-10485760} - ODYSSEUS_CHAT_UPLOAD_MAX_BYTES=${ODYSSEUS_CHAT_UPLOAD_MAX_BYTES:-10485760}
- ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES:-104857600} - ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES:-104857600}
- ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES:-26214400} - ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES:-26214400}
+2
View File
@@ -72,6 +72,8 @@ services:
- ODYSSEUS_CAPTURE_MODEL_REQUESTS=${ODYSSEUS_CAPTURE_MODEL_REQUESTS:-0} - ODYSSEUS_CAPTURE_MODEL_REQUESTS=${ODYSSEUS_CAPTURE_MODEL_REQUESTS:-0}
- ODYSSEUS_MCP_EMAIL_OWNER=${ODYSSEUS_MCP_EMAIL_OWNER:-} - ODYSSEUS_MCP_EMAIL_OWNER=${ODYSSEUS_MCP_EMAIL_OWNER:-}
- ODYSSEUS_SCRIPT_HOST=${ODYSSEUS_SCRIPT_HOST:-localhost} - ODYSSEUS_SCRIPT_HOST=${ODYSSEUS_SCRIPT_HOST:-localhost}
- ODYSSEUS_LOCAL_MCP_READ_TOOLS=${ODYSSEUS_LOCAL_MCP_READ_TOOLS:-}
- ODYSSEUS_LOCAL_MCP_WRITE_TOOLS=${ODYSSEUS_LOCAL_MCP_WRITE_TOOLS:-}
- ODYSSEUS_CHAT_UPLOAD_MAX_BYTES=${ODYSSEUS_CHAT_UPLOAD_MAX_BYTES:-10485760} - ODYSSEUS_CHAT_UPLOAD_MAX_BYTES=${ODYSSEUS_CHAT_UPLOAD_MAX_BYTES:-10485760}
- ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES:-104857600} - ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES:-104857600}
- ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES:-26214400} - ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES:-26214400}
+2
View File
@@ -61,6 +61,8 @@ services:
- ODYSSEUS_CAPTURE_MODEL_REQUESTS=${ODYSSEUS_CAPTURE_MODEL_REQUESTS:-0} - ODYSSEUS_CAPTURE_MODEL_REQUESTS=${ODYSSEUS_CAPTURE_MODEL_REQUESTS:-0}
- ODYSSEUS_MCP_EMAIL_OWNER=${ODYSSEUS_MCP_EMAIL_OWNER:-} - ODYSSEUS_MCP_EMAIL_OWNER=${ODYSSEUS_MCP_EMAIL_OWNER:-}
- ODYSSEUS_SCRIPT_HOST=${ODYSSEUS_SCRIPT_HOST:-localhost} - ODYSSEUS_SCRIPT_HOST=${ODYSSEUS_SCRIPT_HOST:-localhost}
- ODYSSEUS_LOCAL_MCP_READ_TOOLS=${ODYSSEUS_LOCAL_MCP_READ_TOOLS:-}
- ODYSSEUS_LOCAL_MCP_WRITE_TOOLS=${ODYSSEUS_LOCAL_MCP_WRITE_TOOLS:-}
- ODYSSEUS_CHAT_UPLOAD_MAX_BYTES=${ODYSSEUS_CHAT_UPLOAD_MAX_BYTES:-10485760} - ODYSSEUS_CHAT_UPLOAD_MAX_BYTES=${ODYSSEUS_CHAT_UPLOAD_MAX_BYTES:-10485760}
- ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES:-104857600} - ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_UPLOAD_MAX_BYTES:-104857600}
- ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES:-26214400} - ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES=${ODYSSEUS_GALLERY_TRANSFORM_UPLOAD_MAX_BYTES:-26214400}
+19
View File
@@ -492,6 +492,25 @@ VARIABLE_NOTES: dict[str, tuple[str, str, str]] = {
"tools that execute code, mutate state or cause external side effects need " "tools that execute code, mutate state or cause external side effects need "
"a separate approval. Set to 0 to opt out.", "a separate approval. Set to 0 to opt out.",
), ),
"ODYSSEUS_LOCAL_MCP_READ_TOOLS": (
"Agent loop and tool execution", USER,
"Security-relevant. Comma-separated exact MCP read-tool names "
"on configured stdio MCP servers. Only stdio servers qualify. "
"Declarations do not override built-in tool effects. Output remains "
"untrusted to prevent privilege escalation, but allows continuation to "
"declared write tools on the same stdio server without external taint. "
"Stdio transport does not guarantee network isolation. Automatic "
"same-store writes carry residual prompt-injection risk.",
),
"ODYSSEUS_LOCAL_MCP_WRITE_TOOLS": (
"Agent loop and tool execution", USER,
"Security-relevant. Comma-separated exact MCP write-tool names "
"on configured stdio MCP servers. Only stdio servers qualify. "
"Declarations do not override built-in tool effects. Allowed to execute "
"after declared local reads on the same stdio server, but blocked once "
"external untrusted context enters the run. Authorization must still "
"originate from the trusted request grant.",
),
"ODYSSEUS_MCP_ALLOWED_COMMANDS": ( "ODYSSEUS_MCP_ALLOWED_COMMANDS": (
"Agent loop and tool execution", USER, "Agent loop and tool execution", USER,
"Security-relevant. Comma-separated allowlist of MCP launcher basenames the " "Security-relevant. Comma-separated allowlist of MCP launcher basenames the "
+96
View File
@@ -371,6 +371,101 @@ def interpret_request(request_text, *, history=(), workspace=None, active_docume
return SemanticIntent(families, selected, required_read_operation_for_request(request_text, history)) return SemanticIntent(families, selected, required_read_operation_for_request(request_text, history))
def _trusted_local_mcp_request_tools(request_text: str, intent: SemanticIntent) -> set[str]:
"""Seal local MCP operations from operator declarations and trusted request intent.
Discovery validates an operator-declared tool but cannot grant it. For the
notes family, only an explicit request for local notes admits matching
read operations and explicitly requested non-destructive write verbs. Other
MCP domains require the user to name the qualified operation explicitly.
"""
from src.tool_capabilities import (
LOCAL_MCP_READ_TOOLS_ENV, LOCAL_MCP_WRITE_TOOLS_ENV,
_local_mcp_tools, _is_declared_local_mcp_read_tool,
_is_declared_local_mcp_write_tool, capabilities_for_tool, ToolEffect,
)
from src.tool_utils import get_mcp_manager
manager = get_mcp_manager()
if manager is None:
return set()
request = request_text.casefold()
local_notes = (
intent.selected_tools is None
and intent.required_read is None
and "notes" in intent.capabilities
and re.search(r"\b(?:local|on my computer|on this machine)\b", request)
)
write_verbs = {
"create": r"\b(?:create|add|make)\b",
"add": r"\b(?:add|create)\b",
"write": r"\bwrite\b",
"save": r"\bsave\b",
"update": r"\b(?:update|edit|modify|change)\b",
"edit": r"\b(?:edit|update|modify|change)\b",
"append": r"\bappend\b",
"modify": r"\b(?:modify|edit|update|change)\b",
}
negative_write = re.search(
r"\b(?:do not|don't|never|without|no)\s+(?:\w+\s+){0,2}"
r"(?:create|add|make|write|save|update|edit|append|modify)\b",
request,
)
declared = _local_mcp_tools(LOCAL_MCP_READ_TOOLS_ENV) | _local_mcp_tools(LOCAL_MCP_WRITE_TOOLS_ENV)
admitted = set()
for name in sorted(declared):
parts = name.split("__", 2)
if len(parts) != 3 or parts[0] != "mcp":
continue
_, server, bare = parts
if manager.is_builtin(server):
continue
conn = manager.get_server_status(server)
if conn.get("status") != "connected" or conn.get("transport") != "stdio":
continue
resource = manager.resource_identity(name)
if resource is None or resource.namespace != "mcp" or resource.endpoint_id != f"stdio:{server}":
continue
rows = manager._tools.get(server, [])
row = next((item for item in rows if item.get("name") == bare), None)
if row is None:
continue
read_ok = _is_declared_local_mcp_read_tool(name)
write_ok = _is_declared_local_mcp_write_tool(name)
if not (read_ok or write_ok):
continue
caps = capabilities_for_tool(name)
if not caps.known or caps.effects != frozenset({
ToolEffect.READ_PRIVATE if read_ok else ToolEffect.WRITE_PRIVATE
}):
continue
ann = row.get("annotations") or {}
destructive = ann.get("destructiveHint") if isinstance(ann, dict) else getattr(ann, "destructiveHint", None)
if destructive is True:
continue
if write_ok and re.match(r"^(?:delete|remove|erase|destroy|drop|purge)(?:_|$)", bare, re.I):
continue
# Exact qualified names in the trusted request permit any configured
# and validated local operation. Model/tool content is not an input.
explicitly_named = bool(re.search(
r"(?<![A-Za-z0-9_])" + re.escape(name.casefold()) + r"(?![A-Za-z0-9_])",
request,
))
if not explicitly_named:
if not local_notes or not re.search(r"(?:^|_)notes?(?:_|$)", bare, re.I):
continue
if write_ok:
action = bare.split("_", 1)[0].casefold()
if action not in write_verbs or not re.search(write_verbs[action], request):
continue
if negative_write:
continue
admitted.add(name)
return admitted
def create_request_authority(request_text, *, owner=None, session_id=None, workspace=None, def create_request_authority(request_text, *, owner=None, session_id=None, workspace=None,
history=(), policy=None, active_document=False, history=(), policy=None, active_document=False,
image_attachment=False, capabilities=None, client_runtime_context=None): image_attachment=False, capabilities=None, client_runtime_context=None):
@@ -393,6 +488,7 @@ def create_request_authority(request_text, *, owner=None, session_id=None, works
tools = {canonical_tool(operation.tool)} tools = {canonical_tool(operation.tool)}
else: else:
operation = None operation = None
tools.update(_trusted_local_mcp_request_tools(request_text, intent))
grants = [] grants = []
for name in sorted(tools | {"ask_user", "update_plan"}): for name in sorted(tools | {"ask_user", "update_plan"}):
name = canonical_tool(name) name = canonical_tool(name)
+4 -1
View File
@@ -770,8 +770,11 @@ class McpManager:
qualified.add(f"mcp__{server_id}__{tool['name']}") qualified.add(f"mcp__{server_id}__{tool['name']}")
return disabled_map, qualified return disabled_map, qualified
def is_builtin(self, server_id: str) -> bool: @staticmethod
def is_builtin(server_id: str) -> bool:
"""Check if a server is a built-in (auto-registered) server.""" """Check if a server is a built-in (auto-registered) server."""
if not isinstance(server_id, str):
return False
return server_id.startswith("builtin_") or server_id in { return server_id.startswith("builtin_") or server_id in {
"image_gen", "image_gen",
"memory", "memory",
+317
View File
@@ -334,6 +334,142 @@ _BROWSER_MCP_READ_TOOLS = frozenset(
) )
LOCAL_MCP_READ_TOOLS_ENV = "ODYSSEUS_LOCAL_MCP_READ_TOOLS"
LOCAL_MCP_WRITE_TOOLS_ENV = "ODYSSEUS_LOCAL_MCP_WRITE_TOOLS"
_LOCAL_MCP_READ_CAPABILITIES = _capabilities(
ToolEffect.READ_PRIVATE,
result_integrity=ResultIntegrity.EXTERNAL_UNTRUSTED,
)
_LOCAL_MCP_WRITE_CAPABILITIES = _capabilities(
ToolEffect.WRITE_PRIVATE,
result_integrity=ResultIntegrity.EXTERNAL_UNTRUSTED,
)
def _local_mcp_tools(variable: str) -> frozenset[str]:
"""Tool names a deployment declares as touching only the local store.
Tools served by a user-configured MCP server are absent from the registry
above, so they are classified as unknown and fail high. For a server with
both a read and a write tool that is unusable: the read result arms the
post-external gate, because an unknown result is not SYSTEM integrity, and
the write that follows is refused until separately authorized. Every
second call needs an approval, for a server that never leaves the host.
Declaring the tools resolves that without widening the gate:
ODYSSEUS_LOCAL_MCP_READ_TOOLS=mcp__<server>__search_notes,mcp__<server>__read_note
ODYSSEUS_LOCAL_MCP_WRITE_TOOLS=mcp__<server>__create_note
Read tools become READ_PRIVATE with EXTERNAL_UNTRUSTED integrity. Their
results remain untrusted and still arm the gate, preventing prompt
injections from reaching shell, network, or unrelated tools. However,
declared write tools on the exact same MCP server receive a narrowly
scoped continuation exception as long as no external or error taint has
entered the run. Once genuinely external content has entered the run,
approvals remain required.
"""
raw = os.getenv(variable, "") or ""
return frozenset(name.strip() for name in raw.split(",") if name.strip())
def _current_mcp_manager():
"""Retrieve the current McpManager instance safely without hard circular binds."""
try:
from src import tool_execution
if hasattr(tool_execution, "get_mcp_manager"):
mgr = tool_execution.get_mcp_manager()
if mgr is not None:
return mgr
except Exception:
pass
try:
from src.tool_utils import get_mcp_manager
return get_mcp_manager()
except Exception:
return None
def _is_declared_local_mcp_tool(
tool_name: Any, server_id: str | None = None
) -> bool:
"""Return whether tool_name is an exact, well-formed declared local MCP tool."""
if not isinstance(tool_name, str) or not tool_name:
return False
parts = tool_name.split("__", 2)
if not (
len(parts) == 3
and parts[0] == "mcp"
and bool(parts[1])
and bool(parts[2])
and not any(char.isspace() for part in parts[1:] for char in part)
):
return False
sid = parts[1]
if server_id is not None and sid != server_id:
return False
from src.mcp_manager import McpManager
if McpManager.is_builtin(sid):
return False
if tool_name in TOOL_CAPABILITIES:
return False
declared_read = tool_name in _local_mcp_tools(LOCAL_MCP_READ_TOOLS_ENV)
declared_write = tool_name in _local_mcp_tools(LOCAL_MCP_WRITE_TOOLS_ENV)
return (declared_read or declared_write) and (declared_read != declared_write)
def _is_declared_local_mcp_read_tool(
tool_name: Any, server_id: str | None = None
) -> bool:
if not _is_declared_local_mcp_tool(tool_name, server_id):
return False
declared_read = tool_name in _local_mcp_tools(LOCAL_MCP_READ_TOOLS_ENV)
declared_write = tool_name in _local_mcp_tools(LOCAL_MCP_WRITE_TOOLS_ENV)
if not (declared_read and not declared_write):
return False
parts = tool_name.split("__", 2)
mgr = _current_mcp_manager()
if mgr is not None:
tools = mgr._tools.get(parts[1], [])
tool_row = next((r for r in tools if r.get("name") == parts[2]), None)
if tool_row is not None:
from src.mcp_manager import mcp_tool_is_readonly
if not mcp_tool_is_readonly(tool_row):
return False
else:
from src.mcp_manager import _MCP_READONLY_VERBS
if not parts[2].lower().startswith(_MCP_READONLY_VERBS):
return False
return True
def _is_declared_local_mcp_write_tool(
tool_name: Any, server_id: str | None = None
) -> bool:
if not _is_declared_local_mcp_tool(tool_name, server_id):
return False
declared_read = tool_name in _local_mcp_tools(LOCAL_MCP_READ_TOOLS_ENV)
declared_write = tool_name in _local_mcp_tools(LOCAL_MCP_WRITE_TOOLS_ENV)
if not (declared_write and not declared_read):
return False
parts = tool_name.split("__", 2)
mgr = _current_mcp_manager()
if mgr is not None:
tools = mgr._tools.get(parts[1], [])
tool_row = next((r for r in tools if r.get("name") == parts[2]), None)
if tool_row is not None:
ann = tool_row.get("annotations") or {}
destructive = (
ann.get("destructiveHint")
if isinstance(ann, dict)
else getattr(ann, "destructiveHint", None)
)
if destructive is True:
return False
return True
def capabilities_for_tool(tool_name: Any) -> ToolCapabilities: def capabilities_for_tool(tool_name: Any) -> ToolCapabilities:
"""Return deterministic capabilities; malformed and unknown tools fail high.""" """Return deterministic capabilities; malformed and unknown tools fail high."""
if not isinstance(tool_name, str) or not tool_name: if not isinstance(tool_name, str) or not tool_name:
@@ -348,6 +484,10 @@ def capabilities_for_tool(tool_name: Any) -> ToolCapabilities:
return capabilities return capabilities
if tool_name in _BROWSER_MCP_READ_TOOLS: if tool_name in _BROWSER_MCP_READ_TOOLS:
return _BROWSER_MCP_READ_CAPABILITIES return _BROWSER_MCP_READ_CAPABILITIES
if _is_declared_local_mcp_read_tool(tool_name):
return _LOCAL_MCP_READ_CAPABILITIES
if _is_declared_local_mcp_write_tool(tool_name):
return _LOCAL_MCP_WRITE_CAPABILITIES
return _UNKNOWN_CAPABILITIES return _UNKNOWN_CAPABILITIES
@@ -785,6 +925,149 @@ def delegated_tool_is_blocked(tool_name: Any, content: Any = None) -> bool:
) )
_SERVER_OWNED_CONTROL_PLANE_SOURCES = frozenset(
{
"skills",
"client runtime context",
"backend runtime context",
"integrations",
"mcp tools",
"agents.md",
}
)
_PROHIBITED_CONTINUATION_EFFECTS = frozenset(
{
ToolEffect.NETWORK_EGRESS,
ToolEffect.EXTERNAL_SIDE_EFFECT,
ToolEffect.EXECUTE_CODE,
ToolEffect.ADMIN_CHANGE,
ToolEffect.UI_SIDE_EFFECT,
ToolEffect.DESTRUCTIVE,
ToolEffect.READ_WORKSPACE,
ToolEffect.WRITE_WORKSPACE,
ToolEffect.BROKERED_NETWORK_READ,
ToolEffect.READ_PUBLIC,
}
)
def _is_authorized_local_mcp_continuation(
tool_name: Any,
external_sources: Iterable[str],
content: Any = None,
) -> bool:
"""Evaluate narrowly scoped continuation for declared local MCP tools.
Allows a declared local MCP write or read tool when the tool is verified
against an explicitly configured and connected stdio MCP server, and the
only untrusted sources observed in the run are declared local MCP tools
belonging to the exact same MCP server (plus server-owned control plane
metadata).
"""
if not isinstance(tool_name, str) or not tool_name:
return False
parts = tool_name.split("__", 2)
if len(parts) != 3 or parts[0] != "mcp" or not parts[1] or not parts[2]:
return False
server_id = parts[1]
from src.mcp_manager import McpManager
if McpManager.is_builtin(server_id):
return False
if not _is_declared_local_mcp_tool(tool_name, server_id=server_id):
return False
capabilities = capabilities_for_action(tool_name, content)
if not capabilities.known:
return False
if capabilities.effects & _PROHIBITED_CONTINUATION_EFFECTS:
return False
if capabilities.effects - {ToolEffect.WRITE_PRIVATE, ToolEffect.READ_PRIVATE}:
return False
manager = _current_mcp_manager()
if manager is None:
return False
if manager.is_builtin(server_id):
return False
conn = manager.get_server_status(server_id)
if conn.get("status") != "connected":
return False
if conn.get("transport") != "stdio":
return False
resource_id = manager.resource_identity(tool_name)
if resource_id is None or resource_id.namespace != "mcp":
return False
if resource_id.endpoint_id != f"stdio:{server_id}":
return False
tools_list = manager._tools.get(server_id, [])
tool_row = next((r for r in tools_list if r.get("name") == parts[2]), None)
if not tool_row:
return False
ann = tool_row.get("annotations") or {}
destructive = (
ann.get("destructiveHint")
if isinstance(ann, dict)
else getattr(ann, "destructiveHint", None)
)
if destructive is True:
return False
from src.agent_runtime.authority import active_request_authority, ExactOperation, RequestAuthority
authority = active_request_authority()
if not isinstance(authority, RequestAuthority):
return False
if authority is not None:
try:
operation_input = content if isinstance(content, str) else "{}"
operation = ExactOperation.normalize(tool_name, operation_input)
if not authority.permits(operation):
return False
except (ValueError, TypeError):
return False
if resource_id not in authority.backend_resources:
return False
sources = list(external_sources or ())
if not sources:
return False
from src.mcp_manager import mcp_tool_is_readonly
has_local_tool = False
for source in sources:
if source in _SERVER_OWNED_CONTROL_PLANE_SOURCES:
continue
if not _is_declared_local_mcp_tool(source, server_id=server_id):
return False
source_caps = capabilities_for_tool(source)
if not source_caps.known or (source_caps.effects & _PROHIBITED_CONTINUATION_EFFECTS):
return False
if source_caps.effects - {ToolEffect.READ_PRIVATE, ToolEffect.WRITE_PRIVATE}:
return False
source_resource = manager.resource_identity(source)
if source_resource is None or source_resource.endpoint_id != resource_id.endpoint_id:
return False
if not str(source_resource.endpoint_id).startswith("stdio:"):
return False
source_parts = source.split("__", 2)
source_row = next((r for r in tools_list if r.get("name") == source_parts[2]), None)
if not source_row:
return False
if _is_declared_local_mcp_read_tool(source, server_id=server_id) and not mcp_tool_is_readonly(source_row):
return False
has_local_tool = True
return has_local_tool
@dataclass @dataclass
class ToolRunSecurityContext: class ToolRunSecurityContext:
"""Server-owned integrity state for one agent run.""" """Server-owned integrity state for one agent run."""
@@ -804,6 +1087,19 @@ class ToolRunSecurityContext:
# Driven by a bearer API token, not a person at a browser. Privileged # Driven by a bearer API token, not a person at a browser. Privileged
# tools are refused outright and no approval can lift that. # tools are refused outright and no approval can lift that.
delegated_credential: bool = False delegated_credential: bool = False
explicit_untrusted_seen: bool = False
prompt_external_untrusted_seen: bool = False
def __post_init__(self) -> None:
if self.external_untrusted_context_seen and (
not self.external_sources
or any(
not _is_declared_local_mcp_tool(s)
and s not in _SERVER_OWNED_CONTROL_PLANE_SOURCES
for s in self.external_sources
)
):
self.prompt_external_untrusted_seen = True
def observe_messages(self, messages: Iterable[dict]) -> None: def observe_messages(self, messages: Iterable[dict]) -> None:
"""Apply server-owned chat scope and promote untrusted prompt context.""" """Apply server-owned chat scope and promote untrusted prompt context."""
@@ -834,8 +1130,10 @@ class ToolRunSecurityContext:
if source and source not in self.external_sources: if source and source not in self.external_sources:
self.external_sources.append(source) self.external_sources.append(source)
self.external_untrusted_context_seen = True self.external_untrusted_context_seen = True
self.prompt_external_untrusted_seen = True
if messages_contain_external_untrusted_context(message_list): if messages_contain_external_untrusted_context(message_list):
self.external_untrusted_context_seen = True self.external_untrusted_context_seen = True
self.prompt_external_untrusted_seen = True
def decision_for(self, tool_name: Any, content: Any = None) -> ToolGateDecision: def decision_for(self, tool_name: Any, content: Any = None) -> ToolGateDecision:
# Checked before the bypasses below, because neither may lift it, and # Checked before the bypasses below, because neither may lift it, and
@@ -858,6 +1156,20 @@ class ToolRunSecurityContext:
if not self.external_untrusted_context_seen: if not self.external_untrusted_context_seen:
return ToolGateDecision(True) return ToolGateDecision(True)
# Scoped continuation exception for explicitly declared local MCP tools:
# A declared write or read tool on the same MCP server is allowed if
# the run's only untrusted context was introduced by declared local
# tools on that server, without any explicit/error taint or external
# message context.
if (
not self.prompt_external_untrusted_seen
and not self.explicit_untrusted_seen
and _is_authorized_local_mcp_continuation(
tool_name, self.external_sources, content=content
)
):
return ToolGateDecision(True)
# Skills and other server-owned descriptors are control-plane metadata # Skills and other server-owned descriptors are control-plane metadata
# rather than external result content; web/document/tool-result taint # rather than external result content; web/document/tool-result taint
# still gates actions that can mutate state or execute code. # still gates actions that can mutate state or execute code.
@@ -906,6 +1218,11 @@ class ToolRunSecurityContext:
if not tool_result_should_arm_gate(tool_name, result, content): if not tool_result_should_arm_gate(tool_name, result, content):
return return
self.external_untrusted_context_seen = True self.external_untrusted_context_seen = True
if isinstance(result, dict) and (
result.get("untrusted_content") is True
or not tool_result_is_successful(result)
):
self.explicit_untrusted_seen = True
if isinstance(tool_name, str) and tool_name not in self.external_sources: if isinstance(tool_name, str) and tool_name not in self.external_sources:
self.external_sources.append(tool_name) self.external_sources.append(tool_name)
+11 -4
View File
@@ -1917,10 +1917,17 @@ async def execute_tool_block(
) )
if isinstance(security_context, ToolRunSecurityContext) and not approval_claimed: if isinstance(security_context, ToolRunSecurityContext) and not approval_claimed:
decision = security_context.decision_for( if isinstance(authority, RequestAuthority):
getattr(block, "tool_type", None), with bind_request_authority(authority):
getattr(block, "content", None), decision = security_context.decision_for(
) getattr(block, "tool_type", None),
getattr(block, "content", None),
)
else:
decision = security_context.decision_for(
getattr(block, "tool_type", None),
getattr(block, "content", None),
)
if not decision.allowed: if not decision.allowed:
logger.warning( logger.warning(
"External-context policy blocked tool=%r", "External-context policy blocked tool=%r",
+6
View File
@@ -6440,6 +6440,12 @@ def resolve_turn_contract(*, capabilities: Iterable[str], schemas: Iterable[dict
if 'search_emails' in selected: if 'search_emails' in selected:
selected.update({'read_email', 'download_attachment', 'list_email_accounts'}) selected.update({'read_email', 'download_attachment', 'list_email_accounts'})
selected.update(canonical_tool(n) for n in always_available_tools) selected.update(canonical_tool(n) for n in always_available_tools)
# Offer only dynamic MCP operations already sealed by trusted request
# admission. Tool discovery and model routing never create these grants.
from src.agent_runtime.authority import active_request_authority
sealed_authority = active_request_authority()
if sealed_authority is not None:
selected.update(g.tool for g in sealed_authority.grants if g.tool.startswith("mcp__"))
selected.update(canonical_tool(n) for n in warm_tools if str(n or "").strip()) selected.update(canonical_tool(n) for n in warm_tools if str(n or "").strip())
# Controls are neutral; enabling Web is permission, never a requested family. # Controls are neutral; enabling Web is permission, never a requested family.
if selected: if selected:
File diff suppressed because it is too large Load Diff
+4 -2
View File
@@ -21,7 +21,7 @@ described as a switch that turns something off, the read rejects `0`, `false`,
`no` and `off` and treats everything else as on. The `Default` column is the `no` and `off` and treats everything else as on. The `Default` column is the
value the code falls back to when the variable is unset, quoted from the source. value the code falls back to when the variable is unset, quoted from the source.
The source tree reads **147** `ODYSSEUS_*` variables: 90 an operator may want to set, and 57 that are internal - sentinels, fixture switches, capture hooks and development tooling. The internal ones are listed too, in their own section, so this page can be checked against the source mechanically. The source tree reads **149** `ODYSSEUS_*` variables: 92 an operator may want to set, and 57 that are internal - sentinels, fixture switches, capture hooks and development tooling. The internal ones are listed too, in their own section, so this page can be checked against the source mechanically.
> This page is generated. Edit `scripts/generate_env_reference.py` and > This page is generated. Edit `scripts/generate_env_reference.py` and
> re-run it; `tests/test_env_reference.py` enforces that the committed page > re-run it; `tests/test_env_reference.py` enforces that the committed page
@@ -77,6 +77,8 @@ The source tree reads **147** `ODYSSEUS_*` variables: 90 an operator may want to
| Variable | Default | Read in | What it does | | Variable | Default | Read in | What it does |
|---|---|---|---| |---|---|---|---|
| `ODYSSEUS_DISABLE_MCP` | `''` | `src/builtin_mcp.py` | Truthy disables MCP entirely, as an escape hatch for compatibility problems with a server. | | `ODYSSEUS_DISABLE_MCP` | `''` | `src/builtin_mcp.py` | Truthy disables MCP entirely, as an escape hatch for compatibility problems with a server. |
| `ODYSSEUS_LOCAL_MCP_READ_TOOLS` | *unset* | `src/tool_capabilities.py` | Security-relevant. Comma-separated exact MCP read-tool names on configured stdio MCP servers. Only stdio servers qualify. Declarations do not override built-in tool effects. Output remains untrusted to prevent privilege escalation, but allows continuation to declared write tools on the same stdio server without external taint. Stdio transport does not guarantee network isolation. Automatic same-store writes carry residual prompt-injection risk. |
| `ODYSSEUS_LOCAL_MCP_WRITE_TOOLS` | *unset* | `src/tool_capabilities.py` | Security-relevant. Comma-separated exact MCP write-tool names on configured stdio MCP servers. Only stdio servers qualify. Declarations do not override built-in tool effects. Allowed to execute after declared local reads on the same stdio server, but blocked once external untrusted context enters the run. Authorization must still originate from the trusted request grant. |
| `ODYSSEUS_MAX_VISUAL_EVIDENCE_FRAMES` | `'3'` | `src/agent_loop.py` | How many video frames one tool result may contribute. Clamped to 1-8. | | `ODYSSEUS_MAX_VISUAL_EVIDENCE_FRAMES` | `'3'` | `src/agent_loop.py` | How many video frames one tool result may contribute. Clamped to 1-8. |
| `ODYSSEUS_MAX_VISUAL_EVIDENCE_IMAGES` | `'1'` | `src/agent_loop.py` | How many images one tool result may contribute to the model turn. Clamped to 1-8. | | `ODYSSEUS_MAX_VISUAL_EVIDENCE_IMAGES` | `'1'` | `src/agent_loop.py` | How many images one tool result may contribute to the model turn. Clamped to 1-8. |
| `ODYSSEUS_MCP_ALLOWED_COMMANDS` | `''` | `src/agent_tools/admin_tools.py` | Security-relevant. Comma-separated allowlist of MCP launcher basenames the agent may start. Empty by default, and the deny list still wins. | | `ODYSSEUS_MCP_ALLOWED_COMMANDS` | `''` | `src/agent_tools/admin_tools.py` | Security-relevant. Comma-separated allowlist of MCP launcher basenames the agent may start. Empty by default, and the deny list still wins. |
@@ -300,7 +302,7 @@ reads three ways, because no single pattern covers the codebase:
lines, so one read lives inside a string literal. lines, so one read lives inside a string literal.
The three passes are not redundancy. A line-based grep for a direct The three passes are not redundancy. A line-based grep for a direct
`os.environ.get("ODYSSEUS_...` call finds 117 of the 147 variables on this `os.environ.get("ODYSSEUS_...` call finds 117 of the 149 variables on this
page. What it misses is reads through an env-reader helper, reads whose call page. What it misses is reads through an env-reader helper, reads whose call
spans more than one line, reads whose variable name is held in a module spans more than one line, reads whose variable name is held in a module
constant, and reads through a mapping passed in as an argument - which is the constant, and reads through a mapping passed in as an argument - which is the