Dynamic MCP
Route traffic to MCP servers dynamically using label selectors so backends can be updated without changing the Backend resource.
Route to a Model Context Protocol (MCP) server dynamically by using a label selector. This way, unlike a static backend, you can update the backing MCP server without having to update the Backend resource. For more information, see the About MCP topic.
Before you begin
Install and set up an agentgateway proxy.Step 1: Deploy an MCP server
Deploy an MCP server that you want agentgateway to proxy traffic to. The following example sets up an MCP server that provides various utility tools.
Create an MCP server (
mcp-server) that provides various utility tools. Notice the following details about the Service:appProtocol(required): Configure your service to use the MCP protocol, so that the agentgateway proxy uses MCP when it connects to the service. Setagentgateway.dev/mcpfor the Streamable HTTP transport, as in this example, oragentgateway.dev/mcp-ssefor the SSE transport.agentgateway.dev/mcp-pathannotation (optional): The default values are/ssefor the SSE protocol or/mcpfor the Streamable HTTP protocol. If you need to change the path of the MCP target endpoint, set this annotation on the Service.
kubectl apply -f- <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: mcp-server-everything labels: app: mcp-server-everything spec: replicas: 1 selector: matchLabels: app: mcp-server-everything template: metadata: labels: app: mcp-server-everything spec: containers: - name: mcp-server-everything image: node:26-alpine command: ["npx"] args: ["-y", "@modelcontextprotocol/server-everything@2.4.0", "streamableHttp"] env: - name: HOST value: "0.0.0.0" ports: - containerPort: 3001 --- apiVersion: v1 kind: Service metadata: name: mcp-server-everything labels: app: mcp-server-everything spec: selector: app: mcp-server-everything ports: - protocol: TCP port: 3001 targetPort: 3001 appProtocol: agentgateway.dev/mcp type: ClusterIP EOFCreate a AgentgatewayBackend for your MCP server that uses label selectors to select the MCP server.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayBackend metadata: name: mcp-backend spec: mcp: targets: - name: mcp-server-everything selector: services: matchLabels: app: mcp-server-everything EOF
Step 2: Route with agentgateway
Create an HTTPRoute resource that routes to the Backend that you created in the previous step.
kubectl apply -f- <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mcp
labels:
example: mcp-route
spec:
parentRefs:
- name: agentgateway-proxy
namespace: agentgateway-system
rules:
- backendRefs:
- name: mcp-backend
group: agentgateway.dev
kind: AgentgatewayBackend
matches:
- path:
type: PathPrefix
value: /mcp
EOFStep 3: Verify the connection
Use the MCP Inspector tool to verify that you can connect to your MCP server through agentgateway.
Get the agentgateway address.
export INGRESS_GW_ADDRESS=$(kubectl get gateway agentgateway-proxy -n agentgateway-system -o=jsonpath="{.status.addresses[0].value}") echo $INGRESS_GW_ADDRESSFrom the terminal, run the MCP Inspector. The MCP Inspector opens in your browser. If the browser does not open, open the URL that the command prints, including the
MCP_INSPECTOR_API_TOKENquery parameter. The MCP Inspector requires Node.js 22.23.4 or a later 22.x release, 24.22.1 or a later 24.x release, or 26.12.1 or later. To check your version, runnode -v.npx @modelcontextprotocol/inspector@2.17.0Add your agentgateway address as a server, and connect to it.
- Click Add Servers > + Add manually.
- Enter the following details, and click Add.
- Server ID: Enter a name for the server, such as
agentgateway. - Transport: Select
streamable-http. - URL: Enter the agentgateway address, port, and the
/mcppath. If your agentgateway proxy is exposed with a LoadBalancer server, usehttp://<lb-address>/mcp. In local test setups where you port-forwarded the agentgateway proxy on your local machine, usehttp://localhost:8080/mcp.
- Server ID: Enter a name for the server, such as
- On the
agentgatewayserver card, click the toggle. Verify that the card shows Connected.
From the menu bar, click Tools. Verify that you see the tools of the MCP server.


Test the tools: Select a tool, such as
echo. In the message field, enter a message, such asHello, world!, and click Execute Tool. Verify that the Results pane shows the echoed message.

Cleanup
You can remove the resources that you created in this guide.kubectl delete Deployment mcp-server-everything
kubectl delete Service mcp-server-everything
kubectl delete AgentgatewayBackend mcp-backend
kubectl delete HTTPRoute mcp