
REST API to MCP: FastMCP vs. AgentCore Gateway
I built two MCP servers over the same REST API — self-hosted FastMCP and managed AgentCore Gateway — then measured latency, auth, and the real trade-off.
REST API to MCP: FastMCP vs. AgentCore Gateway
You already have a REST API. An agent wants to call it. The Model Context Protocol (MCP) is the connector that gets you there — but how do you host the MCP server? There are lots of ways to build that connector on AWS. I wanted to know how using native AWS services compared to an open source software approach in terms of latency, auth, and feature sets.
So I built both. Same underlying API, same region, both live and verified end-to-end against the real backend:
- Self-hosted — the open-source FastMCP library, containerized and run on AWS App Runner .
- Fully managed — Amazon Bedrock AgentCore Gateway , a declarative resource that turns an OpenAPI spec into MCP tools with no server to run.
The headline: both exposed all 8 API operations and returned byte-identical business data. The decision isn't about capability. It's about latency vs. managed operations, and how much of the auth/credential machinery you want to own. There's also a war story about a one-line setting that saved me from an unwinnable debugging session — more on that below.
The two paths, side by side
Both front the exact same REST API. The difference is everything that sits between the agent and that API.

Path A — OSS FastMCP (self-hosted)
FastMCP.from_openapi(spec, httpx_client) reads your OpenAPI document and generates one MCP tool per operation. I wrapped it in ~100 lines of glue, built a container, pushed it to Amazon ECR , and ran it on App Runner. The downstream API key is supplied as an environment variable at startup; the server holds it in memory and attaches it to every outbound call. Inbound auth is whatever you configure.Path B — AgentCore Gateway (managed)
A declarative AWS resource. You upload an OpenAPI spec to Amazon S3 , create an API Key Credential Provider (which stores the downstream key in a managed token vault), then create a Gateway + Target pointing at the spec and the provider. There is no container and no code to run. Inbound auth is either AWS_IAM (SigV4) or a JWT authorizer — and that JWT path is IdP-agnostic: it validates OAuth 2.0 tokens from any OIDC-compatible provider (Amazon Cognito, Okta, Auth0, Microsoft Entra ID, and so on) by pointing an
authorizerType=CUSTOM_JWT config at the provider's OIDC discovery URL ( .well-known/openid-configuration ) and an allowed client ID or audience. Cognito is just the easiest AWS-native example, not a requirement. Outbound, the gateway fetches the stored key and injects it ( Authorization: Bearer … ) on each call.
What one tool call actually does
The architecture diagram hides the interesting part: what happens on every single call. This is where the latency difference comes from, and it's structural — not a cold-start artifact.
Path A — a thin proxy hop

The key was loaded once at startup. Each call is essentially one HTTP hop plus a memory read. Fast.
Path B — managed auth on every call

Steps 1–3 are the price of "managed." Inbound signature verification, workload-identity token minting, and a credential-vault retrieval happen on AWS-owned infrastructure per call. That's the ~950ms delta — and it buys you audited, rotatable, per-call credential injection you never touch.
Latency, measured
Ten warm calls, the same list-datasets operation, both servers hitting the same backend in us-east-1:

Metric | OSS FastMCP | AgentCore Gateway |
|---|---|---|
Min | 55ms | 903ms |
Median | 57ms | 1020ms |
Avg | 79ms | 1031ms |
Max | 232ms | 1215ms |
All ten AgentCore calls sat in a tight 900–1215ms band — no warm-up curve, so this is structural overhead, not cold start.
A correction worth being honest about. An earlier draft of my notes claimed AgentCore was ~20% faster. That was wrong, and instructively so: those "fast" numbers were measured while every AgentCore tool call was actually failing — fast error responses, not fast work. Once real data started flowing (after the fix below), the true per-call cost showed up. Always confirmisError=falsebefore you trust a latency number.
The blocker that nearly ate the whole experiment
This is the part I most want you to remember, because it's a trap you can fall into with any managed service.
Out of the box, once the gateway reached
READY , tools/list worked fine — but every tools/call failed with HTTP 200 and this:"An internal error occurred. Please retry later."isError=true , no CloudWatch log group, no stack trace, nothing to grep. The managed runtime is invisible by design, so a misconfiguration presents as a generic, unactionable error.The unlock is a single setting:
exceptionLevel=DEBUG on the gateway. Set that, and the real cause appears inside the tool-call response under result._meta.debug :
The root cause: the gateway execution role had only S3 read access. At call time the gateway assumes that role and needs outbound-credential permissions it was missing. Three of them, and one has a genuinely non-obvious scoping rule:

That
GetResourceApiKey line cost me the most time. Intuition says authorize it against the token vault where the key lives — but the IAM action is authorized against the workload-identity resource ARN, and scoping it to token-vault/* still returns 403. After adding all three (and baking exceptionLevel=DEBUG into the deploy script so a fresh deploy is debuggable from the start), every tool call returned real data.The lesson generalizes past this one service: managed convenience hides the runtime, so under-provisioned IAM shows up as a generic error instead of a clear
AccessDenied . The self-hosted server, by contrast, fails loudly in its own logs — you trade that debuggability for the ops burden.
Two things I didn't expect: naming and schema fidelity
Both servers exposed all 8 operations, but they present them differently.
Tool naming. FastMCP derives readable names from the OpenAPI
summary :
AgentCore uses the
operationId , prefixed with the target name and a triple-underscore delimiter. And it requires an operationId on every operation — target creation fails validation without one. My original spec had none; I had to add them. FastMCP works with summary alone.Schema fidelity. This one matters for how well a model calls your tools:

AgentCore drops
default , minimum , and maximum from the exposed input schema. Clients of those tools see a looser contract and push more validation onto the backend. If you rely on schema constraints to guide the model, that's a real consideration.
When to choose which

Choose OSS FastMCP when per-call latency matters (agent loops, interactive tools), you want readable tool names or preserved schema constraints, you need custom logic (caching, rate limiting, merging multiple APIs into one server), you need an inbound auth model the gateway doesn't offer (neither SigV4 nor an OIDC/JWT authorizer fits — e.g. mutual TLS, a bespoke header scheme, or your own opaque tokens), and you're comfortable owning a container — builds, patching, scaling, monitoring.
Choose AgentCore Gateway when you want zero runtime to operate and no code to maintain (spec in, MCP out), SigV4 or an OIDC/JWT authorizer covers your inbound auth (which, since the JWT path takes any OAuth 2.0 IdP via a discovery URL, is most SSO setups — Cognito, Okta, Auth0, Entra ID), you'd rather keep the downstream credential in a managed vault than an env var, traffic is spiky/low so pay-per-use beats an always-on container, your OpenAPI spec is clean (
operationId on every op), and ~1s per call is acceptable.Rule of thumb: OSS trades operational ownership for speed and control. AgentCore trades speed and control for zero ops and built-in AWS-native auth (SigV4 or any OIDC provider). Both faithfully expose the same API as MCP — this is a trade-off, not a winner.
Cost shape
Different curves, not just different numbers. The self-hosted App Runner container has a baseline cost even when idle (roughly a small always-on instance plus a little ECR storage). AgentCore Gateway is pay-per-use with no idle cost. Low, spiky traffic favors the managed path; steady high-volume traffic tilts back toward the container you already run.
Takeaways
- Both paths work and return identical data. Capability is not the deciding factor.
- Latency is structural. ~57ms (self-hosted proxy) vs. ~1020ms (managed per-call auth). Know which one your workload can afford.
- Managed hides the runtime — and its failure modes. If you use AgentCore Gateway, set
exceptionLevel=DEBUGearly, and provision the three outbound-credential IAM permissions (watch theGetResourceApiKeyscoping gotcha).
- Mind the schema. AgentCore drops defaults and numeric constraints; FastMCP keeps them.
- Always verify
isError=falsebefore trusting a benchmark. Fast failures look like fast successes on a stopwatch.
Related reading
- OIDC Auth from Claude Code to an AgentCore Gateway — if you go the AgentCore route and want JWT/OIDC inbound auth instead of raw IAM, this walks the full browser-based login flow, including PKCE.
- Give Your AI Agent an HPC Cluster Through MCP Tools — a from-scratch MCP server when you need custom logic that no spec-to-tools generator can express.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article