Configure GW-to-GW authentication and routing
By the end of this guide, you will have validated Caller Context, Target Authentication, and Policy enforcement across a live GW-to-GW MCP connection, with log evidence confirming behaviour at each hop.
This guide adds a Caller Context element with an API Key (secret store) method and a Policy element to Agent GW 1’s MCP surface, and a Caller Context element and a Target Authentication configuration to Agent GW 2’s MCP surface, then works through scenarios that exercise each combination end-to-end. For background on how two gateways route traffic to each other, see Gateways →.
Without validating these independently, a mismatched HTTP Header Name, a missing Policy element, or an incorrect secret between the two gateways is only visible in a live cross-organisation failure. Each scenario isolates one failure mode so problems are caught in a controlled environment before they reach production traffic.
Use this guide when:
- You have connected two gateways and need to confirm authentication behaviour end-to-end.
- You are building a cross-organisation MCP workflow and need a validation checklist before deployment.
To validate routing on its own, before adding authentication, run Scenario 2 first. It says which parts of the steps to complete before it.
What you are building
- Company A hosts Agent GW 1 with MCP surface A.
- Company B hosts Agent GW 2 with MCP surface B.
- Gateways are connected through a DIDComm gateway connection.
- Agent GW 2 routes requests to Agent GW 1.
- Agent GW 1 forwards to an MCP backend service.
This pattern supports automated AI-driven workflows across company boundaries while keeping authentication and policy controls explicit.
Architecture overview
flowchart LR
C[Client or Agent in Company B] --> B[Agent GW 2\nMCP Surface B]
B -->|Gateway connection routing| A[Agent GW 1\nMCP Surface A]
A -->|Target endpoint| M[MCP backend service]
subgraph Auth checks
S1[Caller Context + Policy on Surface A]
T1[Target Authentication on Surface B's Managed Agent]
end
B --> T1
A --> S1How authentication is enforced across the two hops
Three elements apply at different points in the request path:
- Caller Context: a canvas element dropped on the Access Point → Managed Agent edge. It extracts and validates an inbound caller’s credentials (JWT, API key, or DID Auth) before any policy or payment gate runs. mTLS is visible in the Authentication Method dropdown and the Add method menu but not currently selectable. On a closed Access Point, the default for surfaces created from version 1.0.4, a missing or invalid credential gets
401before policy runs, and a surface without Caller Context answers every request with503, including requests that arrive over a gateway connection. See Access Point readiness. - Policy: a canvas element on the same edge that reads the Caller Context result (
input.source_auth) and decides whether to allow or deny the request. On a public or legacy Access Point, a missing or invalid credential is recorded asinput.source_auth.method == "failed"and the request reaches the Managed Agent unless a Policy element denies it explicitly. See OPA policies reference for the fullinput.source_authschema. - Target Authentication: a section on the Managed Agent node. It injects credentials into outbound traffic before the gateway forwards to a target endpoint, whether that target is a direct URL or another gateway reached via a gateway connection.
This guide sends a fixed API key from a gateway secret. A caller’s delegated credentials from Credential Delegation are handled separately: they cross a gateway connection only when the route’s Send delegated credentials over Fabric switch is on, and it is off by default. See Managed Agent and Transit Points.
In GW-to-GW MCP flows, use this mental model:
- Agent GW 2 receives a request on MCP surface B. Surface B’s own Caller Context authenticates the caller.
- Agent GW 2 removes the header its Caller Context read, and any
Authorizationheader, from the request. If surface B’s Managed Agent node has Target Authentication configured, Agent GW 2 adds the configured header, then forwards the request over the gateway connection. - Agent GW 1 receives the forwarded request on MCP surface A. Surface A’s Caller Context validates the credential it reads. A closed surface A refuses a missing or invalid credential with
401. The Policy element then decides whether to allow or deny an authenticated caller. - If the request is allowed, Agent GW 1 forwards it to the MCP backend using its own Managed Agent node’s endpoint configuration.
- MCP backend logs show the request and any injected header values expected by your test.
Because Agent GW 2 removes the header its own Caller Context read, the two surfaces read different headers in this guide: X-Client-Key on Surface B and X-API-Key on Surface A.
Prerequisites
- You are logged in to the Agent Gateway dashboard for both Agent GW 1 and Agent GW 2, with permission to create and edit surfaces.
- Agent GW 1 and Agent GW 2 are already connected: open Connections → Gateways on either gateway and confirm the connection status badge reads ACTIVE.
- Agent GW 1 exposes Surface A to Agent GW 2: on Agent GW 1, the Publishing tab of Agent GW 2’s gateway record has Selected surfaces with Surface A checked, or All surfaces. A newly paired gateway reaches no surface until one is exposed. See Connect two gateways.
- Both gateways have MCP surfaces created:
- Surface A on Agent GW 1.
- Surface B on Agent GW 2.
- MCP backend service reachable from Agent GW 1’s Managed Agent target endpoint.
- You can view:
- Gateway logs/monitoring.
- MCP backend logs.
- Gateway secrets that hold the test API key values, each with Secret Type
ApiKeyso that the Caller Context element lists it. Follow Secrets to create them:- On Agent GW 1, a secret holding Surface A’s key (for example,
keyA). You select it in Step 1. - On Agent GW 2, a secret holding Surface B’s key (for example,
keyB). You select it in Step 2. - If you are testing Scenario 7 or 8 (Target Authentication), a secret on Agent GW 2 holding
keyAtoo.
- On Agent GW 1, a secret holding Surface A’s key (for example,
Steps
Configure Agent GW 1’s MCP surface A
Open Surfaces on Agent GW 1’s dashboard and select MCP surface A.
Select the Managed Agent node and set Target Endpoint URL to your MCP backend address.
In the left palette, drag a Caller Context element onto the Access Point → Managed Agent edge.
Select the Caller Context node. On the method row, select Configure ↗ to open the full editor.
In Authentication Method, select API Key (secret store), then set:
- HTTP Header Name: the header callers must include in every request, for example
X-API-Key. - Secret ID: the secret holding
keyAthat you created in Prerequisites.
- HTTP Header Name: the header callers must include in every request, for example
Close the editor.
Add a Policy element from the Security & Policy palette category and drop it on the same edge as Caller Context. Set Policy Definition to a policy with this rule.
package surface.policy default allow = false allow if { input.source_auth.method == "api_key" }A closed Access Point refuses a missing or invalid key before this policy runs. The policy also denies such a caller if Surface A’s Access Point is public or legacy, where a failed key would otherwise reach the MCP backend.
Select the disk-icon Save button (tooltip: Save changes).
Configure Agent GW 2’s MCP surface B
- Open Surfaces on Agent GW 2’s dashboard and select MCP surface B.
- Select the Managed Agent node.
- Set Endpoint Type to via Gateway Connection.
- Select Agent GW 1 from the Gateway dropdown, then select Surface A from the Agent Surface on Gateway dropdown.
- Drag a Caller Context element onto the Access Point → Managed Agent edge. Select it, and on the method row, select Configure ↗. In Authentication Method, select API Key (secret store), set HTTP Header Name to
X-Client-Key, and select the secret holdingkeyBin Secret ID. Close the editor. Surface B needs its own caller authentication to accept callers, and a header different from Surface A’s, because Agent GW 2 removes the header this element reads before forwarding. - For scenarios that exercise target-side authentication (Scenarios 7 and 8): under Target Authentication, set Authentication Type to API Key, then select Configure….
- In the full editor, set:
- Credential Source: Static secret.
- Secret: the secret holding
keyAon Agent GW 2 (see Prerequisites). - Header Name: must match the HTTP Header Name configured on Surface A’s Caller Context element, for example
X-API-Key.
- Close the editor.
- Select the disk-icon Save button (tooltip: Save changes).

Never hardcode the API key value in a request script or commit it to source control. Store it only as a gateway secret, rotate it through the secrets manager once a scenario run is finished, and confirm your test logs and monitoring output never echo the raw secret value.
Scenario playbooks
Each scenario below is written as a runbook: setup, action, expected outcome, and validation checks.
Scenario 1: Target Authentication and secret injection
Given: Agent GW 1’s MCP surface A has Target Authentication configured (Authentication Type: API Key) on its own Managed Agent node, pointing at the MCP backend.
When: A request with a valid X-API-Key is sent through Agent GW 1’s MCP surface A.
Then:
- The gateway injects the configured header before the backend call.
- MCP backend logs include the expected header value.
Validate:
- Send an MCP request through Agent GW 1’s MCP surface A.
- Confirm the request succeeds.
- Check the backend log for the configured header name and value pattern.
Scenario 2: Gateway-to-Gateway communication
Given: Agent GW 2 is connected to Agent GW 1, and MCP surface B routes to MCP surface A. Neither surface has a Caller Context, Policy, or Target Authentication yet, so run this scenario before you add them in Steps 1 and 2:
- Set Surface A’s Target Endpoint URL (Step 1, item 2) and Surface B’s gateway route (Step 2, items 3 and 4).
- A closed surface without caller authentication answers every request with
503, so switch on Public access on both Access Points and save. - After this scenario, switch Public access off on both Access Points, then complete Steps 1 and 2 and save.
When: Agent GW 2 sends a request to Agent GW 1.
Then:
- The request is processed successfully end to end.
- MCP backend logs are visible.
Validate:
- Send a request to Agent GW 2’s MCP surface B.
- Confirm the response is a success.
- Confirm Agent GW 1’s logs show the routed inbound request.
- Confirm the MCP backend request log exists.
Scenario 3: Missing source authentication
Given: Agent GW 1’s MCP surface A has a Caller Context element (API Key (secret store)) and a Policy element that denies when authentication fails.
When: A request is sent without the API key header.
Then:
- Surface A refuses the caller before the Policy element runs.
- The caller receives
401with “Caller credential missing or invalid”.
Validate:
- Remove the
X-API-Keyheader from the test request. - Send the request through Agent GW 1 directly, or through Agent GW 2 routing to Surface A with a valid
X-Client-Key. - Confirm the response is
401. - Confirm Agent GW 1’s logs show the failed source authentication for Surface A.
If Surface A’s Access Point is public or legacy, the request reaches policy instead, recorded as input.source_auth.method == "failed", and the Policy element denies it with 403. See Troubleshooting.
Scenario 4: Valid source authentication
Given: Agent GW 1’s MCP surface A has a Caller Context element (API Key (secret store)) and a Policy element, as in Scenario 3.
When: A request is sent with a valid API key.
Then:
- Caller Context records
input.source_auth.method == "api_key"; the Policy element allows the request. - The request is processed successfully.
Validate:
- Send a request with the correct header, for example
X-API-Key: keyA(or your configured header name). - Confirm a success response.
- Confirm Agent GW 1’s logs show the allowed Policy decision.
Scenario 5: Cross-gateway request with valid API key
Given:
- Agent GW 1’s MCP surface A requires
keyAinX-API-Key(Caller Context and Policy, as in Scenario 3). - Agent GW 2’s MCP surface B requires
keyBinX-Client-Key.
When: A client sends a request to Agent GW 2’s MCP surface B with both keys, and Agent GW 2 forwards it to Agent GW 1.
Then:
- The request succeeds end to end.
Validate:
- Send a request to MCP surface B with
X-Client-Key: keyBandX-API-Key: keyA. The client can setX-API-Keyitself, or Target Authentication can inject it (see Scenario 7). - Confirm the response is a success.
- Confirm Agent GW 1’s Policy decision is an allow.
Scenario 6: Cross-gateway request without API key
Given:
- Agent GW 1’s MCP surface A requires
keyA(Caller Context and Policy, as in Scenario 3). - Agent GW 2’s MCP surface B requires
keyB, and has no Target Authentication.
When: A client sends a request to MCP surface B with keyB but without keyA.
Then:
- Surface A on Agent GW 1 refuses the request with
401before policy runs.
Validate:
- Send a request to MCP surface B with
X-Client-Key: keyBand noX-API-Key. - Confirm the response is
401. - Confirm Agent GW 1’s logs show the failed source authentication for Surface A.
Scenario 7: Target Authentication configuration
Given:
- Agent GW 1’s MCP surface A requires API key
keyA(Caller Context and Policy, as in Scenario 3). - Agent GW 2’s MCP surface B Managed Agent node has Target Authentication configured: Authentication Type API Key, Header Name matching Surface A’s HTTP Header Name, Secret holding
keyA.
When: A client sends a request to MCP surface B with X-Client-Key: keyB, without setting X-API-Key itself.
Then:
- Agent GW 2 injects the header automatically before forwarding.
- The request succeeds without the client manually adding an API key on every call.
Validate:
- Confirm Target Authentication is configured on Surface B’s Managed Agent node with the matching secret.
- Send a request to MCP surface B with
X-Client-Key: keyBand noX-API-Keyheader. - Confirm a success response.
- Confirm Agent GW 1’s Policy decision is an allow.
Scenario 8: Incorrect authentication configuration
Given:
- Agent GW 1’s MCP surface A requires API key
keyA(Caller Context and Policy, as in Scenario 3). - Agent GW 2’s MCP surface B Target Authentication is misconfigured (wrong Header Name, wrong Secret, or an Authentication Type Surface A does not expect).
When: A request is sent.
Then:
- The response is
401, because Surface A refuses the missing or wrong credential before policy runs.
Validate:
- Misconfigure one field intentionally on Surface B’s Target Authentication (wrong Header Name, wrong Secret, or wrong Authentication Type).
- Send the request with
X-Client-Key: keyB. - Confirm the response is
401. - Confirm Agent GW 1’s logs show the failed source authentication for Surface A.
If Surface A’s Access Point is public or legacy, the mismatch reaches policy instead, and only the Policy element turns it into a 403. Without that element, an incorrect key reaches the backend with no error.
Confirm
Test 1: cross-gateway request without a valid key returns 401
From Scenario 3 or Scenario 6, Surface A should have refused the request with 401 when the X-API-Key header was absent. Confirm Agent GW 1’s logs show the failed source authentication for that request.
Test 2: cross-gateway request with a valid key succeeds end-to-end
From Scenario 4 or Scenario 5, the request with the correct API key header should have succeeded. Confirm that Agent GW 2, Agent GW 1, and the MCP backend all show the request reaching the backend.
Test 3: Target Authentication injection is visible in backend logs
From Scenario 1 or Scenario 7, the MCP backend logs should include the expected header and its value. If the header is absent, Target Authentication is not configured on the correct hop’s Managed Agent node.
Logging and observability
Before running the scenarios, confirm a successful request produces one log trail on Agent GW 2 (outbound) and Agent GW 1 (inbound/forward), and that the MCP backend logs include request receipt. Configuration changes made in the surface builder apply immediately through hot reload after you save, so you can move straight from a save action to a test request.
Use logs from three places for every test:
- Agent GW 2 logs: request accepted, routing decision to the gateway connection, outbound attempt, and any Target Authentication header injection.
- Agent GW 1 logs: Caller Context validation result, Policy decision, inbound handling, forward decision.
- MCP backend logs: request arrival and expected injected header behaviour.
Best practices:
- Keep a consistent correlation key in request payload/metadata for traceability.
- Validate both status code and log trail before marking a test as passed.
- Store auth-related logs in your runbook evidence for operational audits.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Request from B to A fails with 401 unexpectedly | HTTP Header Name or Secret ID on Surface A’s Caller Context does not match what Surface B sends | Confirm the HTTP Header Name and Secret ID configured on Surface A’s Caller Context match the Header Name and Secret configured in Surface B’s Target Authentication, then resend. |
Request from B to A fails with 401 although the client sends keyA | Surface B’s Caller Context reads the same header as Surface A’s, so Agent GW 2 removes it before forwarding | Set a different HTTP Header Name on Surface B’s Caller Context, such as X-Client-Key, or inject keyA with Surface B’s Target Authentication. |
503 with “This Access Point is not available.” | The surface that answered has no caller authentication, so it is not ready for external access | Add a Caller Context element to that surface and save. Over a gateway connection, the 503 can come from Surface A. |
Request succeeds with 200 even though the API key is missing or wrong | Surface A’s Access Point is public or legacy, and no Policy element denies input.source_auth.method == "failed" | Switch off Public access on Surface A, or select Close Access Point in its legacy notice, and save. Alternatively, add the Policy element from Configure Agent GW 1’s MCP surface A. |
| Request fails after enabling Target Authentication | Secret mismatched, or the wrong Header Name/Authentication Type is set on Surface B’s Managed Agent node | Re-check the Secret and Header Name in Surface B’s Target Authentication editor. |
| No logs in backend | Routing not pointing to the intended target endpoint | Re-check Surface A’s Managed Agent Target Endpoint URL, and Surface B’s Gateway / Agent Surface on Gateway selection. |
| Surface A is missing from the Agent Surface on Gateway dropdown on Agent GW 2 | Agent GW 1 doesn’t expose Surface A to Agent GW 2 | On Agent GW 1, open Agent GW 2’s gateway record, select Selected surfaces with Surface A checked (or All surfaces) on the Publishing tab, and select Save Exposure. |
| Intermittent pass/fail in tests | Mixed test inputs and stale browser/session state | Use explicit test payloads and rerun with clean request inputs. |
Implementation notes from field experience
- Start with one strict, Policy-enforced boundary first (Caller Context and Policy on Agent GW 1), then layer Target Authentication injection on Agent GW 2.
- Use one canonical API key per scenario set during initial testing to reduce false negatives.
- Keep the HTTP Header Name explicit and documented across teams. Most cross-company failures come from a header name or secret mismatch, not routing.
- On a public or legacy Access Point, a Caller Context element without a Policy element is the most common false negative: the scenario looks like it passed because nothing crashed, but the key was never actually enforced.
- Validate with logs at every hop, not just response status.
Next steps
- Connect two gateways: review the connection setup if any gateway-level failures were encountered during scenario testing.
- Apply OPA policies to your gateway and surfaces: add further OPA Rego access control rules on top of the Caller Context and Target Authentication you have validated.
Related
- Connect two gateways: create and approve the gateway connection tunnel first.
- OPA policies reference: the full
input.source_authschema and the Policy element’s fields. - Secrets: store the credentials used by Caller Context and Target Authentication.
- Observability: understand how to monitor runtime request and auth behaviour.
Glad to hear it. Thanks for letting us know.
Sorry to hear that. Thanks for letting us know.
Still stuck? Ask the community on Discord or contact us.