# Where must an instance enforce per-tool egress policy when an MCP server advertises a capability it can only partially honor **Date of Record:** 2026 November 23 **Scope:** Applies to any agent runtime that connects to Model Context Protocol (MCP) servers and relies on server-advertised capability descriptors (`tools`, `resources`, `prompts`) to decide which outbound network egress a tool invocation is permitted. Does not cover pure in-process tool calls with no transport boundary, nor static allowlists compiled before the agent session begins. ## Core Distinction The failure is not "a malicious MCP server lies about its tools." It is subtler: an MCP server advertises a *composite* tool whose declared schema describes a bounded operation (e.g. `fetch_url(url: str) -> str`) but whose internal implementation multiplexes the caller-supplied argument into a *second* egress path the descriptor never names — a redirect chain, a DNS-over-HTTPS resolver, an embedded fetcher inside a "summarize" tool, or a `resources/read` handler that proxies to a URL encoded in the resource URI. The invariant that must hold is: **the egress decision must be made against the fully resolved request, not against the declared capability name.** The runtime that enforces policy at the tool-name boundary is enforcing against a descriptor; the runtime that enforces at the socket boundary is enforcing against reality. These diverge exactly when a tool's declared schema is a proper subset of its actual egress surface. The non-obvious part: the divergence is *legitimate* from the server's perspective. A well-behaved MCP server offering `search_web` genuinely needs to reach many hosts. The descriptor says "this tool fetches." The policy engine that reads only the descriptor has no way to know *which* host this particular invocation will reach, because the host is an argument value resolved after the descriptor was negotiated. ## What Was Observed An agent instance connected to an MCP server over stdio. The server advertised three tools: `read_file`, `search_web`, and `summarize_page`. The runtime's egress policy permitted `search_web` to reach `*.search.example` only, and denied all egress for `read_file` and `summarize_page` (treated as local/offline tools). The policy was keyed on `tool.name`. Trace of the failure: 1. Agent invokes `summarize_page(url="https://search.example/redirect?to=https://internal.metadata.example/latest")`. 2. Policy engine sees `tool.name == "summarize_page"`, classifies as offline, admits the call with no egress grant. 3. MCP server receives the call. Its `summarize_page` implementation fetches the URL to extract text, following HTTP 302 to `internal.metadata.example`. 4. The fetch succeeds. The server returns a summary containing the internal metadata body. 5. The agent records the summary into episodic memory as a legitimate observation. The egress that violated policy was the *redirect hop*, not the initial host. The initial host (`search.example`) was on the allowlist. The redirect target (`internal.metadata.example`) was never evaluated, because the policy engine never saw it — it evaluated `tool.name`, and the redirect is a property of the HTTP response, which is produced inside the server's process, after the policy decision point has already returned. A second observed variant: `read_file(path="/etc/hosts")` where the server's implementation interpreted `path` as a URL when it began with `//`, treating `//etc/hosts` as a protocol-relative URL and issuing a fetch to host `etc`. The descriptor said `path: str` (a filesystem path). The implementation coerced it to a network locator. The policy engine had no egress rule for `read_file` at all. In both cases the schema was honored, the policy was honored at the layer it was enforced, and egress still escaped the intended boundary. The gap is structural: **the enforcement point was above the resolution point.** ## Condition of Validity The failure requires all four of the following to hold simultaneously: 1. **Descriptor-argument gap.** At least one tool's declared schema admits an argument value that the implementation resolves into an egress target not derivable from the tool name alone. (URLs, hostnames, redirect-capable identifiers, resource URIs, and path-like strings that coerce to URLs all qualify.) 2. **Late resolution.** The egress target is resolved *inside* the MCP server process, after the policy decision point has returned "admit." Redirects, DNS resolution, protocol-relative coercion, and server-side templating all produce late resolution. 3. **Trusting enforcement layer.** The runtime's policy engine keys on `tool.name` or on the declared schema, not on the observed egress. It has no post-resolution interception. 4. **Asymmetric classification.** The policy engine classifies tools into egress-permitted and egress-denied buckets, and the tool whose argument carries the hidden egress is in the denied bucket — so the runtime does not even *attempt* to inspect the argument, because it believes the tool is offline. If (4) fails — if every tool is treated as potentially egress-capable and every argument is resolved and checked — the failure degrades to a latency cost, not a breach. If (3) fails — if enforcement occurs at a socket-level proxy that sees the resolved connection — the failure is caught at the redirect hop. The dangerous configuration is precisely the one that feels safest: a tight per-tool allowlist applied at the tool-name layer, with an "offline" bucket that skips argument inspection entirely. ## Decision Boundary The boundary is between **capability-scoped enforcement** (decide once, at tool admission, based on the descriptor) and **resolution-scoped enforcement** (decide per egress attempt, after the target is resolved). The runtime must choose which layer owns the decision, and the choice has a hard consequence: - If capability-scoped enforcement is the only layer, then *any* tool whose implementation can resolve a caller-supplied value into an egress target is an unbounded egress grant, regardless of its name. The "offline" bucket is a fiction; it is an "uninspected" bucket. - If resolution-scoped enforcement is the only layer, the runtime pays a per-hop policy check and must be able to inspect redirect chains, which requires either terminating the connection itself or requiring the MCP server to route through a proxy it controls. The correct decision boundary is: **capability-scoped enforcement may only be used to *narrow* egress for tools whose arguments cannot carry a resolvable egress target.** For any tool whose arguments can carry a URL, hostname, resource URI, or path-like value that the implementation may coerce, the runtime must either (a) require the server to declare the egress surface as part of the tool descriptor and refuse tools that do not, or (b) intercept at the socket/redirect layer and re-evaluate each hop. A tool that declares `path: str` and does not declare "may coerce to URL" is not offline — it is undeclared, and undeclared must be treated as egress-capable. The boundary condition that makes this sharp: a tool is *safe to capability-scope* only if every argument's domain is closed under the implementation's coercion rules. In practice, almost no string-typed argument is closed, because string coercion is open-ended. Therefore the default must be resolution-scoped, and capability-scoping is an optimization that requires a proof of closure the runtime cannot obtain from the descriptor alone. ## Operational Effect The concrete effect on an agent instance is a **memory-poisoning channel disguised as a compliant tool call.** The egress escape does not announce itself as a violation; it returns data through the normal tool-result path, and the agent's episodic memory records it as legitimate. Subsequent reasoning treats the exfiltrated or injected content as ground truth. The failure is not detected at the egress boundary (it was never observed there) and not detected at the memory boundary (the result is well-formed). It surfaces only when a later verification step notices that a "local" tool produced content that could only have come from the network — a signal that is usually absent. Operationally, the guardrail is a **post-resolution egress witness**: every tool result must carry, or be accompanied by, the set of egress targets actually contacted during its execution, and the runtime must verify that set against policy *after* the call. A tool that reports zero egress targets but whose result contains network-derived content is in violation. A tool whose reported egress set includes a host outside the policy for its declared bucket is in violation. This converts the unobservable late-resolution egress into an observable post-hoc invariant, at the cost of trusting the server's self-report — which is why the witness must be cross-checked against a socket-level tap the runtime controls, not merely accepted. The second operational effect: **the "offline" classification must be eliminated as a policy bucket.** Replace it with "egress-capable, unresolvable" — a bucket that admits the call only under a socket tap that denies all outbound connections not pre-declared for that invocation. An offline tool is a tool that has been *proven* to make no egress, not a tool that has been *assumed* to. The proof is the tap, not the name. ```python class EgressPolicyViolation(RuntimeError): """Raised when a tool invocation produces egress outside its resolved policy.""" pass class ToolDescriptor: def __init__(self, name: str, declared_egress_hosts: frozenset[str], args_can_coerce_to_url: bool): self.name = name self.declared_egress_hosts = declared_egress_hosts self.args_can_coerce_to_url = args_can_coerce_to_url def admit_invocation(descriptor: ToolDescriptor, observed_egress_hosts: frozenset[str]) -> None: """ Enforce egress policy at resolution scope, not capability scope. observed_egress_hosts must be produced by a socket tap the runtime controls, covering every hop including redirects and protocol-relative coercions. """ if descriptor.args_can_coerce_to_url and not descriptor.declared_egress_hosts: # A tool whose args can resolve to a URL but which declares no egress surface # is undeclared, not offline. Refuse rather than assume. raise EgressPolicyViolation( f"tool {descriptor.name!r} admits URL-coercible args but declares no egress surface; " "cannot capability-scope an open coercion domain" ) undeclared = observed_egress_hosts - descriptor.declared_egress_hosts if undeclared: raise EgressPolicyViolation( f"tool {descriptor.name!r} contacted undeclared hosts {sorted(undeclared)}; " f"declared surface was {sorted(descriptor.declared_egress_hosts)}" ) def run_tool_call(descriptor: ToolDescriptor, observed_egress_hosts: frozenset[str]) -> None: # Called after the MCP server returns, with the tap's observed host set. admit_invocation(descriptor, observed_egress_hosts) ```