Nick George — AI Agents & Automation
Open source · mcp-gatehouse

Decide what an AI can touch. Keep a record of everything it did.

mcp-gatehouse is a small Python library for MCP servers, the layer that lets an AI work inside your business systems. You label each tool by what it could break. Lookups run on their own. Anything you can't take back waits for a person to say yes. And every call, allowed or refused, lands in a log you can still read six months from now.

pip install mcp-gatehouse

Open sourceMITPython 3.10+MCP SDK v2v0.6.0

A real terminal session with the 0.6.0 demo server that ships in the package: the install, a tier and a policy on every tool, someone else's order kept out and refused, a cancel refused and one approved, and the audit log they left, naming who each call was for. 1:33, no sound. Also on YouTube.
Nick George, Charlotte, NC

Why I built it

An AI that can read an order can usually cancel one too.

I build and run MCP servers for a mid-market reverse logistics-tech company. More than 50 people use them every day to look up inventory, move orders and check truckloads.

Wiring the AI in was quick. Deciding what it could do once it got there was most of the work, because when you're moving real inventory, a confident wrong move is expensive. Get that wrong and you've handed a very fast intern the keys to every room.

Most MCP servers I come across skip that step. They hand the model every tool at full strength and keep no record of what it did. That's fine for a demo. It stops being fine the day an agent can write to your CRM, your books or your order system.

So every server I build has the same gate in it. mcp-gatehouse is that gate, pulled out of my production work into a library you can drop into your own server.

I had a second reason, too. If you're thinking about letting me connect AI to your business, your technical people should be able to read how I keep it in bounds before we talk. The code is public, tests included.

Nick George · Charlotte, NC

How it works

Every tool call goes through the gate first.

You build your MCP server the way the SDK docs show, but you create the gatehouse first and register every tool through it, with a policy that decides who may use it and a tier: READ for lookups, WRITE for creating or updating records, DESTRUCTIVE for deleting, sending or paying, the things that are hard or impossible to take back. From then on, every call takes the same path.

  1. 01

    Who is it for?

    Every call needs a verified caller: the identity in the access token the MCP SDK checked for that request. Over stdio, where nobody signs in, it's the local_caller your server declares. No caller, no call. A tool on your denylist is refused too, whatever its tier.

  2. 02

    Load the record, ask the policy.

    The gate loads the record the call is about from the model's arguments, say the order behind an order number, and hands it to the policy you gave that tool. The policy answers Allow, Deny or Ask. A record that doesn't exist, one that isn't the caller's, a policy that crashes or one that takes longer than five seconds: all refused.

  3. 03

    Does it need a yes?

    By default DESTRUCTIVE tools do, and one line adds WRITE. A policy that says Ask needs one too. The yes comes from an approver: a form in the MCP client itself or a terminal prompt, both shipped with the library, or a function you write that asks in Slack or opens a ticket. No approver, a broken approver or no answer before your time limit means no.

  4. 04

    Run it, or say why not.

    Allowed calls run, and the tool gets the same record the policy saw. Every refusal on authorization reads the same to the model, not permitted for this caller, so it can't probe which records exist. Your policy can tell it more when that's safe to say.

  5. 05

    Write it down.

    One line in the audit log whatever happens, even if the client gives up partway: the tool, its tier, who the call was for, the arguments with secrets masked, the outcome, how long each stage took, and the real reason for every refusal.

What the log looks like

The README's sample: a list with one order the caller couldn't see held back, a note with its API key masked, a cancel the policy refused because the order was someone else's, and one the approver turned down. The first line is in full; the README trims the rest. This is what you pull up when someone asks what the AI did, and for whom.

{"ts": "2026-11-06T14:02:11+00:00", "call_id": "4b1e0c9a6f2d47f1a3c85e0d2b7f9a61", "request_id": "7", "trace_id": "0af7651916cd43dd8448eb211c80319c", "span_id": "b7ad6b7169203331", "tool": "list_orders", "tier": "read", "outcome": "ok", "arguments": {}, "duration_ms": 0.31, "timings_ms": {"authorize": 0.05, "tool": 0.31, "filter": 0.04, "total": 0.42}, "withheld": 1, "caller": {"client_id": "local", "subject": "alice", "issuer": null, "scopes": [], "source": "local"}, "authz": "open"}
{"ts": "2026-11-06T14:02:38+00:00", "call_id": "…", "request_id": "8", "tool": "add_note", "tier": "write", "outcome": "ok", "arguments": {"order_id": "4417", "note": "call back", "api_key": "«redacted»"}, "duration_ms": 1.08, "caller": {…}, "authz": "allow", "resources": {"order": {"order_id": "4417"}}, "consistency": "conditional"}
{"ts": "2026-11-06T14:03:05+00:00", "tool": "cancel_order", "tier": "destructive", "outcome": "denied", "reason": "policy: someone else's order", "arguments": {"order_id": "4420"}, "caller": {…}, "authz": "deny", "resources": {"order": {"order_id": "4420"}}, "consistency": "conditional"}
{"ts": "2026-11-06T14:05:40+00:00", "tool": "cancel_order", "tier": "destructive", "outcome": "denied", "reason": "approver refused", "arguments": {"order_id": "4417"}, "caller": {…}, "authz": "ask", "resources": {"order": {"order_id": "4417"}}, "consistency": "conditional"}

What you get

What's in the library.

Permission tiers

Every tool is READ, WRITE or DESTRUCTIVE. The tier also sets the readOnlyHint and destructiveHint annotations that MCP clients read, and the wrapper won't let you override them to claim something the tier doesn't. A denylist switches a tool off by name, whatever its tier, without deleting its code.

Approval gates

Pick the tiers that need a sign-off. An approver is any function, sync or async, that gets the request and returns True to allow it. Two come with the library: a form in the MCP client, and a terminal prompt. Sync approvers get worker threads of their own, so a person taking their time doesn't hold up anyone else's calls. Set a time limit and an unanswered request becomes a no.

Say yes in the client

ElicitationApprover puts a form with one box to tick in the MCP client itself: Claude Code, Cursor or VS Code. The model can't fill it in, and only a ticked box is a yes. It works under both versions of the MCP protocol in use, and if the client can't show forms, the fallback approver you set decides, or the call is refused. One honest limit: it trusts the client to put the form in front of a person, so for the tools that matter most, ask somewhere the client can't answer, like Slack or a ticket.

An audit log you can read

Append-only JSONL by default, one line per call, allowed, refused, failed or cancelled, with a UTC timestamp, who the call was for and how long it took. A call waiting on a yes in the client gets a pending line, and its verdict follows on a line of its own.

Secrets stay out of it

Arguments named api_key, password, token, client_secret and a dozen more are masked before they reach the log or the approver, however they're spelled. apiKey and API-Key both count. Error messages are left out too, and only the error's type is kept, because error text loves to repeat the very value you just masked.

Nothing else to run

No proxy and no external policy service. It depends only on the official MCP Python SDK and opentelemetry-api, which the SDK already requires. It's a few small classes and a JSONL file.

The code

Every tool through the gate, each with a policy.

Build your MCPServer as usual, but create the gatehouse first and register every tool with @gatehouse.tool instead of the server's own decorator. That's the whole integration.

from typing import Annotated

from mcp.server.mcpserver import MCPServer
from pydantic import BaseModel

from mcp_gatehouse import (
    AccessTier, Allow, AuditLog, AuthorizationRequest, Caller, ConditionalWrite, Deny,
    ElicitationApprover, Gatehouse, Load, Policy, terminal_approver,
)

class Order(BaseModel):
    """Your record. Any Pydantic model, dataclass or mapping will do."""
    id: str
    owner: str
    status: str

mcp = MCPServer("order-desk")
gatehouse = Gatehouse(
    mcp,
    # Ask in the client's own UI; prompt on the terminal if it can't show a form.
    policy=Policy(approver=ElicitationApprover(fallback=terminal_approver)),
    audit=AuditLog(path="~/order-desk/audit.jsonl"),
    # Over stdio nobody signs in, so say who the calls are for.
    local_caller=Caller(client_id="local", subject="alice"),
)

def load_order(order_id: str) -> Order | None:
    """Your system of record. None means there's no such order."""
    ...

def owner_only(request: AuthorizationRequest) -> Allow | Deny:
    order = request.resources["order"]
    return Allow() if order.owner == request.caller.subject else Deny("not the owner")

@gatehouse.tool(tier=AccessTier.READ, authorize=owner_only)
def lookup_order(order_id: str, order: Annotated[Order, Load(load_order)]) -> str:
    """Look up an order's status."""
    return order.status

@gatehouse.tool(
    tier=AccessTier.DESTRUCTIVE,
    authorize=owner_only,
    consistency=ConditionalWrite(),  # the cancel's UPDATE checks the order's version
)
def cancel_order(order_id: str, order: Annotated[Order, Load(load_order)]) -> str:
    """Cancel an order. Runs only if it's the caller's and the approver says yes."""
    ...

mcp.run()

The model sees order_id and nothing else. The gate loads the order, your policy decides on it, and the tool gets the order the policy saw. Because the cancel loads a record and then writes, it also says how the gap between the check and the write is closed: ConditionalWrite() here, an update that only matches the version that was checked. The other choices are Transaction(...), which runs the load, the policy, the tool and the commit in your own database transaction, and AcceptRace("why"), whose reason goes on every audit line.

Schema generation, parameter descriptions and transports all work the way they did before. Sync tools still run in a worker thread, the same as on a plain MCPServer.

To make writes wait for a yes as well, it's one line: Policy(require_approval=frozenset({AccessTier.WRITE, AccessTier.DESTRUCTIVE})). To mask a key of your own without losing the defaults: Policy(redact=DEFAULT_REDACT | {"card_pin"}).

The full README on GitHub ↗

New in 0.6

No caller, no policy, no call.

0.6.0 is a breaking release. Authorization is now a runtime invariant: every call needs a verified caller, an explicit policy, and a decision on the record it acts on, made by the server before the tool runs. Anything missing fails closed. A tool without authorize= doesn't register, and over stdio a server without local_caller= refuses every call.

Upgrading from 0.5? Pin mcp-gatehouse<0.6 until you've migrated. The steps are one short list in the 0.6.0 release notes ↗.

A policy on the record itself

Every tool names a policy with authorize=. A Load parameter tells the gate to load the record from the model's arguments; your policy decides on it and returns Allow(), Deny(reason) or Ask(reason); and the tool gets that same object. The model can't describe a record into existence or reach one that isn't the caller's.

Approvals tied to what was approved

The approval form and the terminal prompt now show who the call is for and the record as the server loaded it, not only the arguments the model chose. The approval is bound to that record's state: if the record changes while a person decides, the call is refused rather than run on something they never saw.

A five-second deadline

Loading the records and reaching a decision get five seconds together. Past that the call is refused, the tool doesn't run, and the model is told it can retry, so “not now” doesn't read like “no”. You can change it per tool, or set on_authorization_timeout=Ask so a slow policy's call goes to a person instead of being lost.

Who every call was for

Every audit line names the caller: the client, the user, the issuer and the scopes from the token the SDK verified, never the token itself. Over stdio it's the local caller, marked "source": "local". Approvers get the same, so whoever signs off knows whose request it is.

The log goes where you want it

Hand records to a file, a function, your logging pipeline or OpenTelemetry logs. BufferedSink moves a slow sink off the request path; when its queue is full the call never waits, and the record goes to stderr instead. Every line carries a call_id, and the OpenTelemetry trace_id and span_id when the call runs in a trace, all in a documented JSON Schema.

Your policy engine, if you run one

Examples for OPA and Cerbos send the caller, the tool, the action and the loaded record to the engine and turn its answer into a decision. An engine that can't be reached is a refusal the model is told it can retry, or, with on_unavailable=Ask, a question for a person.

The approval form in Claude Code, naming who the call is for and the order as the server loaded it (GIF on GitHub) ↗

Try it

A demo order desk, with the gate closed.

The package comes with a small order-desk server: four tools across all three tiers. Every order has an owner. Over stdio the server declares that calls are for you, the person running it, so you see and change only your own orders. Order 4420 is someone else's. Add it to any MCP client that runs servers over stdio. In Claude Code it's one command: claude mcp add gatehouse-demo -- uvx mcp-gatehouse --audit-log /tmp/gatehouse-audit.jsonl

For Claude Desktop, it goes in claude_desktop_config.json:

{
  "mcpServers": {
    "gatehouse-demo": {
      "command": "uvx",
      "args": ["mcp-gatehouse", "--audit-log", "/tmp/gatehouse-audit.jsonl"]
    }
  }
}

Ask the model to list the orders, look up 4420, and cancel one, then watch each verdict land in the audit log, with the policy's reason when it says no. The cancel refuses an order that has shipped and needs your yes for the rest, and above $500 the approval says so. In Claude Code, Cursor or VS Code, that yes is a form in the client: tick the box and it runs. Other clients get the terminal prompt instead, a yes typed into a terminal. Claude Desktop doesn't show approval forms yet and starts the server with no terminal to ask, so there the cancel is always refused, while lookups and notes work as anywhere else. It's refused in a client with a full-screen terminal UI too, because the prompt would draw over its screen. That's the gate failing closed.

Whether the terminal prompt can reach you depends on how the client starts the server. Clients built on the MCP TypeScript SDK keep it in the terminal you started them from, so the prompt shows up there, as long as that terminal isn't running a full-screen program. Clients built on the MCP Python SDK start it cut off from your terminal, even when you run them in one, so it can't ask and the cancel is refused. The client in the video keeps the server in its terminal for that reason.

Where neither the form nor a terminal prompt can reach you, use a different approver. It's any function, so it can ask in Slack instead. Leave an approval unanswered for two minutes and it's a no. Either way, the verdict ends up in the audit log, and the server prints the log's path when it starts.

Design choices

Why the gate lives inside your server.

A proxy in front of your server can't see what your tools do. A separate policy service is one more thing to deploy and keep running, and a 40-person plant doesn't have a platform team to run it. The place that knows a lookup from a cancel is the tool itself, so that's where the tier is declared and where the gate is enforced.

It fails closed everywhere it can, because a security default that quietly allows is worse than none. A tool without a policy doesn't register. A call with no verified caller means no. A policy that crashes, or answers with anything but a decision, means no. A missing approver means no. An approver that crashes means no. A client that can't show the approval form, with no fallback set, means no. A request still unanswered at its time limit means no. A value the redactor can't take apart is swapped for a placeholder instead of going into the log as it is.

What it isn't

  • Authentication. It reads the caller the MCP SDK's auth verified, or the local caller a stdio server declares, and refuses a call with neither. It doesn't sign anyone in itself.
  • A judge of intent. A manipulated agent can still do anything the user is allowed to do, so keep permissions narrow and put a person in front of what can't be undone.
  • A wall around your data. A script or service that reaches the database behind your tools directly never meets the gate, so enforce the same checks in the backend too.
  • Transport encryption.
  • A sandbox for your tool code.
  • Protection from a server author with bad intentions. Give a third-party MCP server the same scrutiny as any software you install.

It's a gate inside your server, for what an AI that's already connected is allowed to do. If you find a security problem, email nick@nickgeorgeai.com instead of opening a public issue. You'll hear back within 72 hours.

Compatibility

SDK v2 today, v1 still covered.

Which mcp-gatehouse versions work with which MCP Python SDK
mcp-gatehouseMCP Python SDKServer class
0.6.xmcp>=2.3,<3MCPServer
0.5.xmcp>=2,<3MCPServer
0.4.xmcp>=2,<3MCPServer
0.3.xmcp>=2,<3MCPServer
0.2.xmcp>=2,<3MCPServer
0.1.xmcp>=1.27,<2FastMCP

Tested in CI on every Python from 3.10 to 3.14. 0.6 needs SDK 2.3 or newer: the gate guards the SDK's tool registry through 2.3's internals, and on an SDK without them, creating a Gatehouse raises rather than run unguarded. The public API (Gatehouse, Policy, AuditLog, AccessTier) hasn't changed across those versions, as promised when SDK v2 was still on its way, with one deliberate exception: 0.6.0's authorization invariant, whose migration steps are in the release notes. Moving a server from SDK v1 to v2 is two import edits. Staying on v1 takes no action at all: 0.1.x pins mcp<2, and it still gets security fixes.

mcp-gatehouse on PyPI ↗Release notes ↗

Common questions

Questions about mcp-gatehouse.

Is mcp-gatehouse free?

Yes. It's open source under the MIT license. Install it with pip install mcp-gatehouse. It needs Python 3.10 or newer and the official MCP Python SDK. Its only other dependency, opentelemetry-api, is one the SDK already requires.

What breaks when I upgrade from 0.5 to 0.6?

0.6.0 is a breaking release, and it fails closed. A tool without authorize= doesn't register, and over stdio a server without local_caller= refuses every call. A write or destructive tool that loads a record also needs consistency=, authorization that takes longer than five seconds is refused, and the MCP Python SDK must be 2.3 or newer. Pin mcp-gatehouse<0.6 until you've migrated. The migration steps are one short list in the 0.6.0 section of CHANGELOG.md on GitHub.

Does it work with FastMCP or version 1 of the MCP Python SDK?

Yes, through the 0.1.x line, which targets mcp>=1.27,<2 and FastMCP. Version 0.2 and later target SDK v2 and its MCPServer class, and 0.6 needs mcp 2.3 or newer. Moving a server from SDK v1 to v2 is two import edits.

Can I approve from inside Claude Code or Cursor?

Yes, since version 0.5. ElicitationApprover shows a form with one box to tick inside the MCP client: the tool, its tier, who the call is for, its arguments with secrets masked, and the record the call acts on, as the server loaded it. It works in Claude Code, Cursor and VS Code, and the model can't answer it. Only a ticked box approves; anything else is a no. Since 0.6, an approval is bound to the record's state, so if the record changes while you decide, the call is refused. If the client can't show forms, the fallback approver you set decides, or the call is refused. It trusts the client to show the form to a person, so a client set to accept forms on its own could approve. For a yes from outside the client, use an approver that asks in Slack or opens a ticket.

Can approvals go to Slack or a ticket instead of a terminal?

Yes. An approver is any function, sync or async, that receives the request and returns True to allow it. The library ships one that asks in the MCP client and one that asks on the terminal; a Slack or ticket approver is a function you write. Either way, the approver sees who the call is for, the record it acts on and the arguments with secrets already masked, and if it fails, or nobody answers before the time limit you set, the call is refused and logged.

What does the AI see when a call is refused?

Every refusal on authorization reads the same to the model: the tool is not permitted for this caller. That covers a record that doesn't exist, one that isn't theirs, and a loader or policy that failed, so the model can't probe which records exist. Your policy can tell it more when that's safe, with Deny(reason, message=...). A call that ran out of time is told it can be retried. The audit log always keeps the real reason, such as "policy: not the owner".

Does it handle authentication?

No. It doesn't sign anyone in, but it does require a caller: every call needs a caller the MCP SDK's auth verified, or over stdio the local caller the server declares, and a call with neither is refused. It doesn't encrypt transports or sandbox tool code. It's a gate inside your server that decides what an AI that's already connected is allowed to do, and records what it did and for whom.

Why put the gate inside the server instead of using an MCP proxy?

A proxy can't see what your tools do or the record a call is about, and a separate policy service is one more system to deploy and keep running. Inside the server, the gate loads the record and your policy decides on it at the moment the tool is called. If you already run a policy engine, your policy can call it: the project has examples for OPA and Cerbos.

Is it on the official MCP Registry?

Yes, as io.github.nickgeorgeseo/gatehouse, installed from PyPI. That entry is the demo order-desk server, which runs with uvx mcp-gatehouse.

Testing an agent before it gets near real data? fieldtwin, my open-source Jobber and QuickBooks twins →

Want this around your own systems?

I build MCP servers with the gate already in.

If you want AI working in your CRM, your books or your order system, and you want to know what it's allowed to do there, that's the work I do.

MCP server development →

New to MCP? The plain-English guide →