Set up backends

Set up backends

Learn how to use the agentgateway UI or a configuration file to create and delete targets.

Before you begin

  1. Set up a listener.
  2. Create a route on the listener.

Create backends

You can create backends by using the agentgateway UI or a configuration file.

  1. Start your agentgateway.

    agentgateway
  2. Open the agentgateway target UI.

  3. Click Add Backend and configure your backend details, such as follows:

    • Backend Type: MCP
    • Name: default
    • Weight: 1
    • Route: Select the route on the listener that you want to use to route to the backend.
    • Click Add Target.
    • Target Name: everything
    • Target Type: From the dropdown, select the target type that you want to use, such as Stdio.
    • Command: npx
    • Arguments: @modelcontextprotocol/server-everything
    • Environment Variables: Optionally add any environment variables that you need the target to run.
    • To add more targets, click Add Target and repeat the previous steps.
    • Click Add MCP Backend to save your configuration.
ℹ️
To connect to an OpenAPI server, use the MCP target type.
  1. Create a configuration file for your agentgateway.

    cat <<EOF > config.yaml
    binds:
    - port: 3000
      listeners:
      - routes:
        - policies:
            cors:
              allowOrigins:
                - &#34;*&#34;
              allowHeaders:
                - mcp-protocol-version
                - content-type
          backends:
          - mcp:
              name: default
              targets:
              - name: everything
                stdio:
                  cmd: npx
                  args: [&#34;@modelcontextprotocol/server-everything&#34;]
    EOF

    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.
  2. Run the agentgateway.

    agentgateway -f config.yaml
  3. Open the agentgateway backend UI and verify that your target is added successfully.

Delete targets

Remove agentgateway backends with the UI.

  1. Run the agentgateway from which you want to remove a backend.

    agentgateway -f config.yaml
  2. Open the agentgateway backends UI and find the backend that you want to remove.

  3. Click the trash icon to remove the backend.

Update the configuration file to remove the backend.

  1. Remove the backend from your configuration file.

  2. Apply the updated configuration file to your agentgateway.

    agentgateway -f config.yaml