Runtime security for MCP agents

Identity proves who an agent is. Aegis decides what it's allowed to do.

A deterministic capability-enforcement layer for AI agents on the Model Context Protocol. Every tool call is checked against a spec before it reaches the server. There is no LLM anywhere in the enforcement path.

v0.2.1 · MIT · pip-installable · Python 3.10+
$ python -m tools.demo_end_to_end
TOOL-CALL SEQUENCE — one agent run

1 SPEC_LOADED  opens run
2 OK          read_text_file  action-items.txt
3 OK          read_text_file  agenda.txt
4 OK          read_text_file  meeting-notes.txt
5 DENIED      read_text_file  project-update.txtrule-7-value-not-allowed

The injected instruction asked for a fourth file.
The MCP server never saw the request.
0
LLM calls in the enforcement path
9
ordered rules, deny by default
240
tests in the library
1 line
to wrap a Pydantic AI toolset

The problem

Prompt injection is a when, not an if.

Any agent that reads files, web pages, tickets or email will eventually read text written by someone else. If that text tells the model to do something, sometimes the model will do it.

Asking a second model whether a call "looks right" has the same weakness as the first one. Aegis takes a different route. It doesn't try to spot the injection. It makes sure that when an injection works, it can't cause anything outside the task.

Filters & classifiers
Guess whether text is malicious. A new phrasing gets past them.
LLM-as-judge
A model reviewing tool calls reads the same untrusted text the agent did.
OAuth scopes
Say which tools an agent may call. They don't limit the paths, targets or URLs passed to those tools.
Aegis
Fixes the exact (server, tool, argument, value) set before the run starts, then enforces it with plain code.

How it works

How a tool call gets evaluated

The full model
01trusted
Request
A user or operator describes the task in plain language.
02LLM · once
Proposer
Reads the request once, before the run, and drafts a minimum-capability spec. It never sees tool output.
03frozen
Spec
Validated, hashed and frozen. Nothing can widen it after this point.
04deterministic
Enforcement
Plain, deterministic code checks every tool call against the spec.
05MCP
Tool
Allowed calls reach the MCP server. Denied calls never do.

The enforcement path contains no LLM. The proposer runs once, on trusted input, before the run starts. After that, every decision takes microseconds and can be verified by reading the code.

Integration

Drops into the agent you already have.

Pass any Pydantic AI MCPToolset to wrap_toolset(). The spec can come from a plain-language request through propose_spec(), or from YAML an operator wrote, through load_spec(). Nothing else in the agent changes.

agent.py
from aegis import wrap_toolset, AegisConfig, propose_spec

config = AegisConfig(sandbox_root=sandbox)
spec = propose_spec(
    f"Read {sandbox / 'notes.txt'} and summarise it",
    sandbox_root=sandbox, run_id=config.run_id,
)

# every call through fs is now evaluated first
wrap_toolset(fs, "filesystem", spec=spec, config=config)

Capabilities

What it does today

Product overview

Deterministic enforcement

Every MCP tool call is checked against a capability spec before it reaches the server. Values must match exactly. No globs, no regex, no guessed scope.

Generated specs

A plain-language request becomes a minimum-capability YAML spec. It is generated once and validated before use. You can also write specs by hand.

Human approval

Intercept rules defined by the operator pause sensitive calls until someone signs off, through a callback you control. An intercept can't rescue a call that was denied.

Response inspection

Rule-based scanning catches leaked secrets before a response reaches the model: private keys, AWS keys, Luhn-valid card numbers and SSNs.

Forensic audit trail

Each decision is logged with its run_id, the spec_hash of the policy that made it, and the rule that fired. You can search for waivers and denials by rule.

OTLP export

Audit events go to your existing observability stack as OTLP spans: Datadog, Jaeger, Splunk, or any OTLP-compatible tool. If the collector is down, tool calls are never blocked.

Position in the stack

Downstream of identity. Upstream of the server.

Identity vendors answer one question: is this agent allowed in? Aegis answers the next one: once it's in, what is it allowed to do on this task? Aegis doesn't compete with your identity provider. It handles what comes after.

It works with any identity system and any observability stack, and it adds one line of code to an existing Pydantic AI agent.

Identity provider
Authenticates the agent: who it is
Aegis
Decides what the authenticated agent may do on this task, down to argument values
MCP server
Only sees the calls Aegis let through
Observability
Receives every decision as an OTLP span

Honest coverage

Mapped against the OWASP MCP Top 10

One control can't cover a ten-category taxonomy, and Aegis doesn't claim to. Here is what it covers, what it partly covers, and what you need something else for.

See every category
3 covered5 partial2 not covered: supply chain, shadow servers

Building agents with real tool access?

Aegis is pre-production and open source. If "prove what the agent did" is a requirement for you, I'd like to hear what your team is running into.