Introduction
An agent gateway earns its keep on agent traffic, and the most common kind is the Model Context Protocol (MCP) — the calls an agent makes to discover and invoke tools. This tutorial puts an MCP server behind the gateway you installed in part 2, then discovers and calls its tools through one endpoint.
You will deploy a sample MCP server, expose it with an AgentgatewayBackend, attach a route, and call a tool through the proxy.
Step 1 — Deploy a sample MCP server
This MCP server exposes a single fetch tool that retrieves a web page. Note the appProtocol: agentgateway.dev/mcp on the Service — that tells agentgateway the backend speaks MCP.
kubectl apply -f- <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcp-website-fetcher
spec:
selector:
matchLabels:
app: mcp-website-fetcher
template:
metadata:
labels:
app: mcp-website-fetcher
spec:
containers:
- name: mcp-website-fetcher
image: ghcr.io/peterj/mcp-website-fetcher:main
imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: mcp-website-fetcher
labels:
app: mcp-website-fetcher
spec:
selector:
app: mcp-website-fetcher
ports:
- port: 80
targetPort: 8000
appProtocol: agentgateway.dev/mcp
EOF
Step 2 — Expose it with an AgentgatewayBackend
The AgentgatewayBackend resource is how you register an agent backend. For MCP, you list one or more targets; here a single static target points at the Service:
kubectl apply -f- <<'EOF'
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
name: mcp-backend
spec:
mcp:
targets:
- name: mcp-target
static:
backendRef:
name: mcp-website-fetcher
port: 80
protocol: SSE
EOF
Confirm it is accepted:
kubectl get agentgatewaybackend mcp-backend
NAME ACCEPTED AGE
mcp-backend True 4s
Step 3 — Attach a route
Route requests under /mcp on the gateway to the backend. Because the backend is an AgentgatewayBackend, the backendRef names its group and kind:
kubectl apply -f- <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mcp
spec:
parentRefs:
- name: agentgateway-proxy
namespace: agentgateway-system
rules:
- matches:
- path:
type: PathPrefix
value: /mcp
backendRefs:
- name: mcp-backend
group: agentgateway.dev
kind: AgentgatewayBackend
EOF
Step 4 — Connect to the MCP endpoint
Port-forward the proxy:
kubectl port-forward deployment/agentgateway-proxy -n agentgateway-system 8080:80
The gateway now serves MCP over Streamable HTTP at http://localhost:8080/mcp. A raw initialize call confirms the server is reachable through the proxy:
curl -s -X POST localhost:8080/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}'
data: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":false}},"serverInfo":{"name":"mcp-website-fetcher","version":"1.14.1"}}}
Step 5 — Discover and call a tool
Use the MCP Inspector CLI to list the tools the gateway exposes:
npx @modelcontextprotocol/inspector@0.21.2 --cli http://localhost:8080/mcp \
--transport http --method tools/list
{
"tools": [
{
"name": "fetch",
"description": "Fetches a website and returns its content",
"inputSchema": {
"type": "object",
"properties": { "url": { "type": "string", "description": "URL to fetch" } },
"required": [ "url" ]
}
}
]
}
Now call the tool through the gateway:
npx @modelcontextprotocol/inspector@0.21.2 --cli http://localhost:8080/mcp \
--transport http --method tools/call --tool-name fetch --tool-arg url=https://example.com
{
"content": [
{ "type": "text", "text": "<!doctype html><html lang=\"en\"><head><title>Example Domain</title>..." }
],
"isError": false
}
The tool ran and returned the page, routed through agentgateway.
What the gateway adds
A single AgentgatewayBackend can list several MCP targets, so the gateway federates many MCP servers behind one endpoint. Agents connect to that one endpoint and discover every tool, and you get a single point to apply access control and audit logging — the subject of part 6 of this series.
Clean up
kubectl delete httproute mcp
kubectl delete agentgatewaybackend mcp-backend
kubectl delete deployment,service mcp-website-fetcher
What’s next
You routed a tool call through the gateway. Next, the gateway sits in front of model providers: you will route LLM traffic across providers — including a model running on your own machine — without changing your application.
Next in this series: Routing LLM Traffic Across Providers.
Summary
- An
AgentgatewayBackendwithmcp.targetsregisters one or more MCP servers; mark the backend Service withappProtocol: agentgateway.dev/mcp. - An
HTTPRoutewhosebackendRefnames theagentgateway.dev/AgentgatewayBackendgroup/kind attaches it to the Gateway. - The gateway serves MCP over Streamable HTTP; clients
initialize,tools/list, andtools/callthrough one endpoint. - One endpoint for many servers is where access control and audit logging later attach.
