Two MCP servers, because the network is the boundary
We already had a server in production for MCP, the Model Context Protocol an AI client uses to discover and call tools, so adding a new set of internal tools to it would have been a small diff, one deploy, no new terraform. In practice an MCP server is an HTTP service with a tool list and a handler for each one.
The server we had is public and read-only. It serves an architecture catalog: our services, which service calls which, and which events and queues each one produces and consumes. It exists so that an outside vendor's incident-response agent can answer "what does this thing depend on" during an outage, without a human transcribing it.
Then a second need arrived. Engineers wanted their own AI clients to reach operational data. Look up a user by email. Resolve a workspace by domain. Check which features a workspace is entitled to. Read a billing profile before answering a support question. And eventually change feature rollout flags in bulk, which is a write.
Same protocol, same repository. The obvious move was to add the new tools to the server we already had.
Scopes were not the problem
The reflex is to argue this as an authorization design. Tag the internal tools with a scope, issue the vendor a token that does not carry it, put a roles table behind the whole thing. One server, one hostname, fine-grained permissions.
I spent a day inside that argument before noticing that it answers a different question. A scope tells you what a caller may do once it has reached you. It says nothing about who can reach you in the first place.
Both of our requirements were about reaching.
The vendor's agent runs on the vendor's infrastructure. It is never going to be inside our network. No policy of ours changes where their code executes.
The internal tooling requirement said the opposite in as many words: internal network only, plus a superadmin check on the human behind the client.
One hostname cannot satisfy both. Every single-server design I sketched resolved the conflict by quietly weakening one side. Either the write-capable surface becomes reachable from the open internet with a token check as the only thing in front of it, or the vendor gets network access nobody wanted to grant.
Two surfaces satisfy both literally: a public read-only deployment for machines that cannot get inside, and a second one behind an internal-only load balancer with no public address at all, carrying the same catalog tools, the operational reads and the writes.
One codebase, two deployments. Once the split is made on network position rather than on how sensitive each tool feels, most of the arguments that follow stop being arguments. The internal surface is allowed to have write tools precisely because it is unreachable from outside. The public surface is low-risk in a way you can check, rather than low-risk because we were careful.
We did consider serving both audiences from one hostname and splitting internally. That reverses the property the whole design rests on, since a shared public front door puts the write-capable surface back on a public address with authentication as the only thing in front of it. Split-horizon DNS, where the same name resolves to different addresses inside and outside the network, was the other variant. It produces debugging sessions where two engineers see different truths, and the only beneficiary is a machine that gets configured once and never looks again.
The ingress decides the auth
The two surfaces ended up with different authentication mechanics, and not because we wanted variety. By ingress I mean whatever terminates the request before any of our code sees it.
The public surface sits behind API Gateway REST v1. We picked the older REST flavour over the newer HTTP APIs for one reason, which is that a web application firewall rule set attaches to REST v1 and not to the newer one. A Lambda request authorizer validates the token inside our VPC. The authorizer is a small function API Gateway runs before anything else, and its verdict decides whether the request reaches the handler at all. By the time the handler executes, an unauthenticated request has already been rejected by infrastructure.
The internal surface sits behind an internal-only Application Load Balancer, and an ALB has no authorizer concept for Lambda targets. There is nothing to attach. So the token has to be validated inline, as the first statement of the handler, before any tool dispatch.
Identity itself is the same on both surfaces. One token type, stored as a SHA-256 hash in a dedicated collection, accepted either as a static header or as Authorization: Bearer. Accepting two header shapes is deliberate rather than sloppy. Some third-party MCP clients can send exactly one static header of arbitrary name and have no OAuth support at all. Others can only emit a bearer token. Supporting one shape would have excluded clients we needed.
The proposal that could not work
We wrote three competing implementation plans and checked each one against the actual source rather than against its own description. That exercise paid for itself.
The most attractive plan was the one with the most reuse: clone the existing server, keep the identity extraction as it is, register more tools. It could not work, and the reason is a single property of the event object.
// API Gateway REST v1 gives you this, populated by the authorizer:
event.requestContext.authorizer.tokenId
// An ALB target invocation gives you this instead:
event.requestContext.elb.targetGroupArn
// There is no `authorizer` key. Reading through it yields undefined.
The copied line would have read undefined as the caller identity on the one surface that can write. There would be no crash and no 500, just an absent value flowing into authorization checks and audit records on the write-capable deployment. That was the highest-severity finding in the review, and it came from reading the event shape rather than from reading the plan.
The fix is small once you see it. The handler takes an explicit ingress mode, and each mode reads identity from the place its own event shape puts it.
const identity =
ingress === 'alb'
? await validateTokenInline(tokenHeaderFrom(event))
: event.requestContext.authorizer;
if (!identity?.tokenId) {
return unauthorized();
}
The guard at the bottom matters as much as the branch above it. An undefined identity has to fail closed and loudly, because the failure we nearly shipped was silence.
Guarantees instead of conventions
Two things here are enforced by structure, because I do not trust a convention to survive a year of other people's commits.
The public server refuses at registration time to expose any tool outside a fixed read-only allowlist. This is a startup refusal, not a runtime check on every call. If someone adds an operational tool to the shared tool module and deploys the public surface, the process does not boot.
for (const tool of tools) {
if (surface === 'public' && !PUBLIC_READONLY_TOOLS.has(tool.name)) {
throw new Error(`Refusing to register ${tool.name} on the public surface`);
}
server.registerTool(tool);
}
The second guarantee is in IAM. The public surface's execution role can read exactly one object in S3, the catalog file, and nothing else. The internal role has no kms:Decrypt permission and no access to the secrets store whatsoever.
That last one I will defend as a rule rather than a preference. A tool an LLM can call must never hold decryption keys. Not "should be careful with", must not hold. Prompt injection means the risk is wider than an attacker with a stolen token. An engineer's own session can read hostile text out of a support ticket, and from that moment every tool the session holds is available to whoever wrote that text. The protection is the absence of an IAM permission, because an absent permission cannot be forgotten during code review.
The attack I cannot prevent
The worst case I take seriously is the confused deputy, where a legitimate actor is steered into using its own authority on an attacker's behalf. A real admin, on the VPN, holding a valid token, is talked into calling a write tool in a way they did not intend. Nothing was stolen. Every check passed.
You cannot design that away, so the design contains it instead. A single write call is bounded in how much it can change. Every write is attributed to a specific token and a specific human, and it can be undone. The audit record is written in two different trust domains, so covering tracks means scrubbing both. A monitor watches for bursts, because a run of injected writes has a different shape from a person working.
None of that prevents the call. It decides whether I can reconstruct what happened on Monday morning and reverse it.
The spike that passed and was shelved anyway
I built a throwaway prototype against a managed gateway product, AWS Bedrock AgentCore Gateway, and evaluated it properly. It passed all eight checks I had set for it. Warm calls took roughly 390ms, cost was negligible at the request rates we were testing, and per-tool authorization was expressible through a request interceptor.
We deferred it anyway.
Its distinctive value is semantic tool discovery, which lets an agent search for the right tool by meaning instead of receiving a static list. That does not pay for itself until the static list is large enough to crowd the agent's context window. We are nowhere near that. So the design doc records the conditions that would send us back to it, and the gateway stayed out of the stack. We revisit it when a surface exceeds roughly 50 to 100 tools, or when several separate teams need to search across tools by meaning. Our Lambdas remain valid gateway targets, so adopting it later is additive rather than a rewrite.
One detail from that prototype is easy to miss and worth writing down. The gateway's ingress is public by default, and making it private requires PrivateLink, which moves the endpoint inside our own network and would then block the external vendor whose access is the entire reason the public surface exists. The managed option, configured the safe way, breaks the requirement that started all of this.
Four small things that each cost an afternoon
Authorizer result caching is set to zero, explicitly. Both the terraform default and the omitted-value default are 300 seconds, and with caching on, a revoked token keeps working for the length of the cache window. That silently defeats the kill switch, which is the one control you reach for when something has already gone wrong.
identity_source is omitted on purpose so that either header shape can be extracted, and that only holds while caching is off. The two settings are coupled, so the terraform needs a comment saying so.
The ALB Lambda path caps request and response bodies at 1MB, against roughly 6MB through the REST API. Any tool registered on both surfaces has to stay under the smaller cap, which is a real constraint on catalog responses.
One pure AWS quirk ate twenty minutes. A load balancer name may not begin with internal-. The resource is therefore named the opposite way round from the hostname it serves, which looks like a mistake in the terraform until you know why.
What I ask first now
When someone proposes adding tools to an existing server, my first question is where the caller's code physically runs. What the tools do, and who should be allowed to call them, comes after that.
If two sets of callers run in places with different network reachability, that difference is already a boundary. You can put your architecture on it, or you can spend the design fighting it with tokens.