For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Set up downstream-only login
Front an MCP server with the gateway’s OAuth issuer so users authenticate with the downstream IdP only.
Use downstream-only login to require users to sign in through your identity provider (IdP) when an MCP client connects to the gateway. The gateway validates the user’s token and forwards the request to the MCP server. The backend does not require a per-user upstream OAuth credential.
This example uses the Everything MCP resource created by brokered setup. Sign in through Keycloak at connection time, then call the Echo tool.
Before you begin
- Complete Set up brokered elicitation. Reuse its running STS, Keycloak, OAuth issuer, and Everything MCP resource. Keep
GATEWAY_URLexported. - Install Node.js 22.19 or later to run MCP Inspector locally.
- Make sure that local ports
6274and6275are available. Keep the gateway port-forward running if you selected that connection method.
Step 1: Review the downstream-only resource
Brokered setup creates the Everything backend as an EnterpriseAgentgatewayBackend, and creates its route. The sample already selects downstream-only login, so you can continue without changing the resources. The backend has no upstream OAuth elicitation mapping or backend token exchange policy. The issuer therefore completes this resource’s flow after downstream login. For the complete resource and route example, see Register the MCP resource.
Review the authentication settings under the spec.policies.mcp section.
spec:
policies:
mcp:
authentication:
mode: Strict
issuer: "${KEYCLOAK_ISSUER}"
audiences: [agw-issuer]
jwks:
backendRef:
group: agentgateway.dev
kind: AgentgatewayBackend
name: keycloak-jwks
cacheDuration: 5m
jwksPath: /realms/downstream-mcp/protocol/openid-connect/certs
resourceMetadata:
agentgateway.dev/issuer-proxy: "http://enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777/oauth-issuer"
resource: "${GATEWAY_URL}/mcp"
authorizationServers: ["${GATEWAY_URL}/mcp"]| Setting | Purpose |
|---|---|
authentication.mode | Requires a Keycloak token for MCP requests. |
issuer, audiences, and jwks | Validate the token issuer, audience, and signature against the Keycloak realm from setup. |
resourceMetadata.agentgateway.dev/issuer-proxy | Registers the resource for the brokered issuer. The issuer reads this value from an EnterpriseAgentgatewayBackend or an EnterpriseAgentgatewayPolicy (not the upstream AgentgatewayBackend or AgentgatewayPolicy APIs). To register multiple backends with the same brokered issuer, use an EnterpriseAgentgatewayPolicy that targets the backends. |
resource and authorizationServers | Identify the public MCP URL, including its path and any non-default port. |
Step 2: Check authentication discovery
Before signing in, check that the gateway rejects an unauthenticated request and advertises its OAuth issuer. These checks diagnose routing and authentication configuration; browser login in the next step completes the brokered flow.
Send a request without a bearer token.
curl -i "${GATEWAY_URL}/mcp"Expect
401 Unauthorizedwith aWWW-Authenticateheader pointing to${GATEWAY_URL}/.well-known/oauth-protected-resource/mcp.Read the protected resource metadata.
curl -fsS "${GATEWAY_URL}/.well-known/oauth-protected-resource/mcp" | jq '{resource, authorization_servers}'Both values must identify
${GATEWAY_URL}/mcp. For the local port-forward example:{ "resource": "http://localhost:3000/mcp", "authorization_servers": ["http://localhost:3000/mcp"] }Read the authorization server metadata.
curl -fsS "${GATEWAY_URL}/.well-known/oauth-authorization-server/mcp" | jq '{issuer, authorization_endpoint, token_endpoint, registration_endpoint}'The
issuermust identify${GATEWAY_URL}/mcp. The endpoint URLs use${GATEWAY_URL}/oauth-issuer. For the local port-forward example:{ "issuer": "http://localhost:3000/mcp", "authorization_endpoint": "http://localhost:3000/oauth-issuer/authorize", "token_endpoint": "http://localhost:3000/oauth-issuer/token", "registration_endpoint": "http://localhost:3000/oauth-issuer/register" }
Step 3: Sign in and call a tool
For the local port-forward, use the Inspector URL shown in the following steps. For a LoadBalancer, use your public MCP URL in the Inspector’s URL field:
echo "${GATEWAY_URL}/mcp"Connect through MCP Inspector to complete the browser login and call the backend. These steps use MCP Inspector 2.9.0.
In a separate terminal, start the Inspector.
npx -y @modelcontextprotocol/inspector@2.9.0Open http://localhost:6274 or the
http://127.0.0.1:6274URL from the startup output. The example allows callbacks to either address.Click Add Servers > Add manually.


Enter the following values and click Add.
Field Value Server ID downstream-mcpTransport streamable-httpURL http://localhost:3000/mcpTurn on the connection switch for
downstream-mcp. The browser redirects to Keycloak. Sign in asalicewith passwordalice-password.If the gateway returns
redirect_uri is not allowed, compare the request’sredirect_uriwith the callback allowlist in brokered setup. For example, a127.0.0.1callback does not match alocalhostentry. Add the missing callback URI, restart STS (or upgrade the controller Helm values in Kubernetes mode), and start a new connection from the Inspector.Verify that the browser returns to the Inspector and the server status changes to Connected. The flow completes after the Keycloak login, without an upstream provider login or an elicitation consent screen.


Open Tools, select Echo Tool, and enter
Hello from downstream-only loginin the message field. Click Execute Tool.Expected result:
Echo: Hello from downstream-only loginThe STS log also confirms the selected flow:
"msg":"downstream callback processed, completing downstream-only flow"
Optional backend authentication
A backend that requires a shared service credential can still use downstream-only login. Configure API key backend authentication on that backend. The Everything MCP server in this example needs no credential.
If your backend is an HTTP API, follow OpenAPI to MCP to expose its operations as tools. OpenAPI conversion is independent of the downstream login flow.
Clean up
Disconnect and remove downstream-mcp in the Inspector, then stop the Inspector with Ctrl+C. Keep the sample MCP resource, shared issuer, and IdP while another brokered guide uses them. Otherwise, clean up the shared infrastructure.