Last modified December 1, 2026
Connect your own app to an agent
Your application’s backend can send messages to an agent and get its answers, using the A2A protocol (version 1.0, JSON-RPC). The application signs in as itself with an OAuth client credentials token. The agent then runs as your application, not as one of your users. When the agent calls a tool on your MCP server, your server can still tell which of your users the call is for. Your application sends that information with each message, and the platform passes it on to the tool call unchanged.
Before you start
Giant Swarm turns this on for your installation. Send us:
- A name for your application. It must not contain
@and must differ from the name of every other application on the installation. The platform uses this name as your application’s identity, so pick something likeorders-assistant. - The address of your MCP server and how it authenticates, so we can connect it to your agent.
- The agent’s instructions and the model it should use, if the agent doesn’t exist yet.
You get back:
- A client ID and a client secret for your application. Keep the secret on your backend only.
- The address of your agent:
https://agentgateway.<base domain>/a2a/<organization>/<agent>.
<base domain> is your installation’s base domain, the same one in your other Giant Swarm addresses.
Get a token
Ask the installation’s identity provider (Dex) for a token with the client credentials grant. Request the scopes openid and profile, and the audience klaus-gateway-app. Dex takes the audience as a scope:
curl -s https://dex.<base domain>/token \
-u "<client ID>:<client secret>" \
-d grant_type=client_credentials \
-d "scope=openid profile audience:server:client_id:klaus-gateway-app"
The answer is a JSON object. Send its id_token as the bearer token on every call to the agent. Without profile, the token doesn’t carry your application’s name and the agent refuses it.
Get a new token before the old one expires. The platform refuses a token that has less than 25 minutes left, because a turn of the agent can take that long.
Send a message
Send SendMessage to your agent’s address. Every call needs the header A2A-Version: 1.0.
curl -s https://agentgateway.<base domain>/a2a/<organization>/<agent> \
-H "Authorization: Bearer <id_token>" \
-H "A2A-Version: 1.0" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "SendMessage",
"params": {
"message": {
"role": "ROLE_USER",
"messageId": "6f1c2d1e-8a51-4c7e-9a3b-2f4d5e6a7b8c",
"parts": [{"text": "Export my last three orders as CSV."}]
},
"metadata": {
"com.example/session": "user-session-42",
"format": "csv"
}
}
}'
A message without a context ID starts a new conversation. The answer is a task. Keep its contextId and its id (the task ID):
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"task": {
"id": "<task ID>",
"contextId": "<context ID>",
"status": {"state": "TASK_STATE_COMPLETED"}
}
}
}
The real answer also carries the agent’s reply and the task’s history.
If you send the same messageId again, for example after a timeout, you get the same conversation, not a second one.
Continue the conversation
To send a follow-up, put the context ID in the message:
"message": {
"role": "ROLE_USER",
"messageId": "<a new ID>",
"contextId": "<context ID>",
"parts": [{"text": "Now only the orders from November."}]
}
You can also put a task ID in the message as taskId, for example to answer a task that’s waiting for input. The platform finds the conversation from the task. If you send both a task ID and a context ID, they must belong together. If they don’t, the call is refused with the JSON-RPC error -32602, invalid parameters.
Keep context IDs on your server
All your users share your application’s identity on the platform. The platform can’t tell your users apart, so it accepts any context ID or task ID your application sends. Keeping each user’s conversations apart is your application’s job:
- Store each context ID and task ID on your backend, tied to your own user’s session.
- Never send them to the browser, and never accept them from the browser or any other value your users can change.
Pass your user’s session to your MCP server
Put values for your MCP server in the request’s metadata, next to message, as in the first example. When the agent calls a tool, the platform adds these entries to the tool call’s _meta, unchanged. For that message, your MCP server receives a tools/call request like this:
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "export_orders",
"arguments": {"count": 3},
"_meta": {
"com.example/session": "user-session-42",
"format": "csv"
}
}
}
What to know about these values:
- Only
tools/callrequests carry them. Connecting, listing tools and other requests carry none. - They never reach the model. They aren’t part of the prompt or of the tool’s arguments. If your tool returns them in its result, though, the model sees that result.
- Each message carries its own values. A follow-up without
metadatasends nothing to the tool calls of that turn; it doesn’t reuse the values of an earlier message. - Every MCP server the agent calls during the turn receives the same values. Give your agent only the MCP servers that should see them.
- Name your keys with a prefix you own, such as
com.example/session. The platform refuses a message whose metadata uses a key reserved by MCP: any key whose prefix hasmcpormodelcontextprotocolas its second part (such asio.modelcontextprotocol/ordev.mcp/), orprogressToken,traceparent,tracestateorbaggage. - The values are data, never credentials. Don’t put tokens or passwords in them.
Your MCP server must trust your application to name the right user: the platform passes the values on without checking them. Your server should accept these values only on calls that come from the platform for your application.
What doesn’t work for an application
- Sign-ins and approvals. Some tools ask a person to sign in or to approve a call before they run. No person stands behind an application, so nobody can complete that step, and such a tool doesn’t run for your application. Connect your MCP server with an authentication that doesn’t need a person to sign in.
- One identity per user. The agent sees one caller, your application, for all your users. Anything the agent remembers or can reach, it can reach for every one of your users.
Errors
| What you see | Why |
|---|---|
| HTTP 401 | No token, an expired token, or a token for another audience than klaus-gateway-app. |
| HTTP 403 | The token belongs to a client that isn’t allowed to call agents. |
JSON-RPC -32009 | The call has no A2A-Version: 1.0 header. |
JSON-RPC -32602 | The context ID doesn’t match the task, or the metadata uses a reserved key. |
UNAUTHORIZED or UNAUTHENTICATED | A tool or the platform needs a sign-in, which an application can’t do. Contact Giant Swarm. |
Need help, got feedback?
We listen to your Slack support channel. You can also reach us at support@giantswarm.io. And of course, we welcome your pull requests!