Stdio

An MCP backend allows exposing MCP servers through the agentgateway.

Want to use agentgateway in a Kubernetes environment with the Gateway API? Check out the kgateway docs.

Before you begin

Install the agentgateway binary.

Configure the agentgateway

  1. Download an MCP configuration for your agentgateway.

    curl -L https://raw.githubusercontent.com/agentgateway/agentgateway/refs/heads/main/examples/basic/config.yaml -o config.yaml
  2. Review the configuration file.

    cat config.yaml
    binds:
    - port: 3000
      listeners:
      - routes:
        - policies:
            cors:
              allowOrigins:
                - "*"
              allowHeaders:
                - mcp-protocol-version
                - content-type
                - cache-control
          backends:
          - mcp:
              targets:
              - name: everything
                stdio:
                  cmd: npx
                  args: ["@modelcontextprotocol/server-everything"]
    Review the following table to understand this configuration.
    Field Description
    binds Binds set up each port on which the agentgateway listens for incoming requests. This example configures one port.
    port The port to listen on, such as 3000.
    listeners Listeners configure how agentgateway accepts and processes incoming requests. They do this by grouping together resources such as routes and the backends that serve traffic.
    routes Routes configure advanced routing features, such as traffic policies, that control how traffic is sent to the backends. In the example, the route matches all traffic.
    policies Policies configure traffic policies on routes that shape how traffic is sent to the backends. In the example, a basic CORS policy is configured to allow all origins and the mcp-protocol-version header. This way, the configuration works with the MCP inspector tool.
    backends Backends configure the backing destination where the traffic is sent to. Backends can be MCP servers, A2A agents, or OpenAPI servers. In this example, the backend is an MCP server.
    targets Targets configure the details of the backend, such as the MCP server. In this example, the target is the sample, open source MCP test server, server-everything. The server runs a bunch of tools in a single process that are useful for testing.
    stdio To run the server, you use the standard input/output (stdio) capability of the agentgateway, which allows you to pass in the command and command arguments that you want to use. In this example, the npx command is used. The npx command utility lets you run a Node.js package (@modelcontextprotocol/server-everything) without installing it. If you do not have npx on your machine, follow the instructions to install Node.js.
  3. Run the agentgateway.

    agentgateway -f config.yaml

Verify access to tools

  1. Open the agentgateway UI to view your listener and backend configuration.

  2. Connect to the MCP test server with the agentgateway UI playground.

    1. From the navigation menu, click Playground.

    2. In the Testing card, review your Connection details and click Connect. The agentgateway UI connects to the target that you configured and retrieves the tools that are exposed on the target.

    3. Verify that you see a list of Available Tools.

  3. Verify access to a tool.

    1. From the Available Tools list, select the echo tool.

    2. In the message field, enter any string, such as This is my first agentgateway setup., and click Run Tool.

    3. Verify that you see your message echoed in the Response card.