> For the complete documentation index, see [llms.txt](https://docs.mediafier.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediafier.ai/platform/gateway.md).

# The Gateway

What the gateway checks before a tool runs (identity, organization context, authorization, rate limits, billing), and how calls are traced and audited.

> **Identity · Organization · Authorization · Rate limits · Billing — checked before any tool runs.** The gateway is the single enforcement chain. Every tool call, every surface, every caller converges here.

***

## What the gateway is

A single deterministic enforcement chain in front of every runtime. Calls enter on the canonical public ingress; only after the gateway's checks pass does the call reach the runtime that owns the tool.

```
Client → Gateway checks:
  Identity · Organization context · Authorization · Rate limits · Billing
                                    ↓
                       The owning runtime executes
                                    ↓
   Response (with X-Trace-Id) → back to client; audit keyed by trace ID
```

The gateway is where "can this call run at all?" is decided — the only place in the system that answers the question.

***

## What the gateway checks

| Check                    | What it enforces                                                                                                                                        | Failure mode                                                                             |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **Identity**             | Auth0 bearer token verified server-side. Auth0 is the sole identity provider.                                                                           | 401 with trace ID.                                                                       |
| **Organization context** | Tenant boundary derived from the authenticated principal — never from a client header.                                                                  | Structured refusal with trace ID.                                                        |
| **Authorization**        | Per-tool, per-org permission check against the governed authorization model.                                                                            | 403 with trace ID.                                                                       |
| **Rate limiting**        | Per-org throttling, per server and per tool. Protects shared capacity from a single tenant burst.                                                       | 429 with trace ID.                                                                       |
| **Billing**              | Credit ledger check against the organization's wallet. Calls that would exceed available credits are stopped here, before the runtime sees the request. | Deterministic billing-failure envelope with trace ID; the agent can re-plan or escalate. |
| **Dispatch**             | Hands the approved call to the runtime that owns the tool.                                                                                              | Transport-error envelope with trace ID.                                                  |

Audit is not a single step in that list: when a call is refused or completes, the audit trail is designed to hold a record of it, correlated by trace ID.

***

## How credentials flow

Credentials are handled by the platform, resolved inside the gateway before dispatch. The contract is:

* **Credentials are resolved server-side per call and injected by the gateway, scoped to a single invocation.** Tools and agents never receive access to Mediafier's credential stores.
* **Tools never return credential material.** The narrow exception is a pair of approval-gated provisioning surfaces whose purpose is to issue a credential: each returns a newly issued secret exactly once, to its owner, after organization-admin approval — and never re-reveals it.
* **Secrets stay out of agent payloads and runtime logs.**

## What the gateway always enforces

Three commitments that hold for every call:

* **Server-derived tenant context.** Organization is resolved from the authenticated principal, never from a client-supplied header. The boundary is decided by the platform, not by the caller.
* **One enforcement chain.** Calls from people, agents, and partner integrations go through the same checks — which is what makes the chain auditable end to end.
* **Credential isolation.** Credentials are resolved where tools, agents, and runtimes cannot reach them, and secrets stay out of agent payloads and runtime logs — see "How credentials flow" above.

***

## Trace correlation

Every response — success or error — carries an `X-Trace-Id` header. The same ID:

* Correlates the call's audit record, where one is written.
* Threads through the billing ledger.
* Propagates as a header to the runtime that executes the call, so its logs pivot on the same key.
* Appears inside structured error envelopes returned to the agent.

A customer-support engineer who has the trace ID can use the call's records to reconstruct who, when, which org, which tool, the outcome, and what it cost.

***

## Public endpoints

```
POST https://mcp.mediafier.ai/mcp
```

The canonical multiplexed ingress, callable from any MCP-aware client. All public traffic is JSON-RPC over HTTPS. (An advanced scoped per-server form exists for harnesses that need a single-server session — see [MCP Access](https://docs.mediafier.ai/connect/mcp-access.md).)

***

## Where to go next

| If you're…                           | Read next                                                                                                                                                                                          |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| New to the platform                  | [What is Mediafier?](https://docs.mediafier.ai/overview/what-is-mediafier.md)                                                                                                                      |
| Looking for the broader architecture | [Platform Architecture](https://docs.mediafier.ai/platform/platform-architecture.md)                                                                                                               |
| Looking for client integration       | [Agent-First Access (CLI + MCP)](https://docs.mediafier.ai/connect/agent-first-access.md)                                                                                                          |
| Studying the discovery model         | [Governed Resources & Discovery](https://docs.mediafier.ai/platform/governed-resource-substrate.md)                                                                                                |
| Auditing identity and tenancy        | [Identity & Authentication](https://docs.mediafier.ai/trust/identity-and-authentication.md), [Multi-Tenant Organization Model](https://docs.mediafier.ai/trust/multi-tenant-organization-model.md) |
