Route to a Model Context Protocol (MCP) server through a static address. For more information, see the About MCP topic.

Before you begin

  1. Install Gloo Gateway and enable the Solo Enterprise for agentgateway integration.

  2. Verify that the Solo Enterprise for agentgateway integration is enabled.

      helm get values gloo-gateway -n gloo-system -o yaml
      

    Example output:

      
    agentgateway:
      enabled: true
      

Step 1: Deploy an MCP server

Deploy a Model Context Protocol (MCP) server that you want Solo Enterprise for agentgateway to proxy traffic to. The following example sets up a simple MCP server with one tool, fetch, that retrieves the content of a website URL that you pass in.

  1. Create the MCP server workload. Notice the following details about the Service:

    • appProtocol: kgateway.dev/mcp (required): Configure your service to use the MCP protocol. This way, the Solo Enterprise for agentgateway proxy uses the MCP protocol when connecting to the service.
    • kgateway.dev/mcp-path annotation (optional): The default values are /sse for the SSE protocol or /mcp for 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-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: kgateway.dev/mcp
    EOF
      
  2. Create a Backend that sets up the Solo Enterprise for agentgateway target details for the MCP server.

      kubectl apply -f- <<EOF
    apiVersion: gateway.kgateway.dev/v1alpha1
    kind: Backend
    metadata:
      name: mcp-backend
    spec:
      type: MCP
      mcp:
        targets:
        - name: mcp-target
          static:
            host: mcp-website-fetcher.default.svc.cluster.local
            port: 80
            protocol: SSE   
    EOF
      

Step 2: Route with agentgateway

Route to the MCP server with Solo Enterprise for agentgateway.

  1. Create a Gateway resource that uses the agentgateway-enterprise GatewayClass. Kgateway automatically spins up an Solo Enterprise for agentgateway proxy for you.

      kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: agentgateway
    spec:
      gatewayClassName: agentgateway-enterprise
      listeners:
      - protocol: HTTP
        port: 8080
        name: http
        allowedRoutes:
          namespaces:
            from: All
    EOF
      
  2. Verify that the Gateway is created successfully. You can also review the external address that is assigned to the Gateway. Note that depending on your environment it might take a few minutes for the load balancer service to be assigned an external address. If you are using a local Kind cluster without a load balancer such as metallb, you might not have an external address.

      kubectl get gateway agentgateway
      

    Example output:

      NAME            CLASS          ADDRESS                                  PROGRAMMED   AGE
    agentgateway   agentgateway   1234567890.us-east-2.elb.amazonaws.com   True         93s
      
  3. 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
    spec:
      parentRefs:
      - name: agentgateway
      rules:
        - backendRefs:
          - name: mcp-backend
            group: gateway.kgateway.dev
            kind: Backend   
    EOF
      

Step 3: Verify the connection

Use the MCP Inspector tool to verify that you can connect to your sample MCP server through agentgateway.

  1. Get the agentgateway address.

  2. From the terminal, run the MCP Inspector command. Then, the MCP Inspector opens in your browser. If the MCP inspector tool does not open automatically, run mcp-inspector.

      npx modelcontextprotocol/inspector#0.16.2
      
  3. From the MCP Inspector menu, connect to your agentgateway address as follows:

    • Transport Type: Select Streamable HTTP.
    • URL: Enter the agentgateway address, port, and the /mcp path. If your agentgateway proxy is exposed with a LoadBalancer server, use http://<lb-address>:8080/mcp. In local test setups where you port-forwarded the agentgateway proxy on your local machine, use http://localhost:8080/mcp.
    • Click Connect.

  4. From the menu bar, click the Tools tab. Then from the Tools pane, click List Tools and select the fetch tool.

  5. From the fetch pane, in the url field, enter a website URL, such as https://lipsum.com/, and click Run Tool.

  6. Verify that you get back the fetched URL content.

Cleanup

You can remove the resources that you created in this guide.
  kubectl delete Deployment mcp-website-fetcher
kubectl delete Service mcp-website-fetcher
kubectl delete Backend mcp-backend
kubectl delete Gateway agentgateway
kubectl delete HTTPRoute mcp