Set up targets

Set up targets

Learn how to use the Agent Gateway UI, a configuration file, or the Agent Gateway admin API to create and delete targets.

Create targets

You can create targets by using the Agent Gateway UI, a configuration file, or the Agent Gateway admin API.

  1. Start your Agent Gateway.

    agentgateway
  2. Open the Agent Gateway listener UI. You must create a listener before you can create a target.

  3. Add a listener.

    1. From the listener UI, click Add Listener.

    2. Enter a Name for your listener, select a protocol, and configure the Address and Port that you want your listener to be exposed on. To use an address that is compatible with IPv4 and IPv6, enter [::].

    3. Click Add Listener to save your configuration.

  4. Open the Agent Gateway target UI.

  5. Click Add Target and choose your Target Type, such as MCP.

ℹ️
To connect to an OpenAPI server, use the MCP target type.
  1. Confgure your MCP target.
    1. Select the listener you want to attach to the target.

    2. Enter a Target Name. The name is used as a prefix for all the MCP tools that are exposed on the MCP server.

    3. Select the standard input/output (>_ stdio) tab that allows you to specify a command and command arguments to run your MCP server. In this example, you use the npx command utility to run the @modelcontextprotocol/server-everything server. If your server is exposed on a public URL, you can enter that URL in the SSE tab instead.

    4. Click Add Target to save your configuration.

  1. Create a JSON file that contains your listener configuration. The following example sets up these components:

    • Listener: An SSE listener that listens for incoming traffic on port 3000.
    • Target: The Agent Gateway targets a sample, open source MCP test server, server-everything. The server runs the entire MCP stack in a single process and can be used to test, develop, or demo MCP environments. To run the server, you use the standard input/output (stdio) capability of the Agent Gateway that allows you specify a command and command arguments that you want to run. In this example, you use the npx command utility to run the @modelcontextprotocol/server-everything server.
    cat <<EOF > config.json
    {
      "type": "static",
      "listeners": [
        {
          "name": "sse",
          "protocol": "MCP",
          "sse": {
            "address": "[::]",
            "port": 3000
          }
        }
      ],
      "targets": {
        "mcp": [
          {
            "name": "everything",
            "stdio": {
              "cmd": "npx",
              "args": [
                "@modelcontextprotocol/server-everything"
              ]
            }
          }
        ]
      }
    }
    EOF
  2. Run the Agent Gateway.

    agentgateway -f config.json
  3. Open the Agent Gateway target UI and verify that your target is added successfully.

  1. Start your Agent Gateway. The Agent Gateway automatically exposes its admin API on port 19000.

    agentgateway
  2. Create an SSE listener by using the /listeners endpoint. In the following example, the listener is exposed on port 3000. A listener must be created before you can add a target.

    curl -X POST -H content-type:application/json http://localhost:19000/listeners -d '{"name": "sse", "sse": {"address": "[::]", "port": 3000}}'
  3. Verify that the listener is created.

    curl http://localhost:19000/listeners
  4. Create an MCP target by using the /targets/mcp endpoint. In this example, you create the everything target that connects to a sample MCP test server, server-everything. To run the server, you use the npx command, which allows you to run a Node.js package without installing it.

    curl -X POST -H content-type:application/json http://localhost:19000/targets/mcp -d '{"name": "everything", "stdio": {"cmd": "npx", "args": ["@modelcontextprotocol/server-everything"]}}'
  5. Verify that the MCP target is created.

    curl http://localhost:19000/targets/mcp

Delete targets

Remove Agent Gateway targets with the UI.

  1. Run the Agent Gateway from which you want to remove a listener.

    agentgateway -f config.json
  2. Open the Agent Gateway targets UI and find the target that you want to remove.

  3. Click the trash icon to remove the target and confirm the deletion.

Update the configuration file to remove the target.

  1. Remove the target from your configuration file.

  2. Apply the updated configuration file to your Agent Gateway.

    agentgateway -f config.json

Use the Agent Gateway admin API to delete targets from your Agent Gateway.

  1. Run the Agent Gateway from which you want to remove a target.

    agentgateway -f config.json
  2. List all the MCP targets that are configured on your Agent Gateway and note the name of the target that you want to remove. In the following example, the name of the MCP target is everything.

    curl http://localhost:19000/targets/mcp

    Example output:

    [{"name":"everything","spec":{"Stdio":{"cmd":"npx","args":["@modelcontextprotocol/server-everything"]}}}]
    
  3. Remove the MCP target from your Agent Gateway.

    curl -X DELETE http://localhost:19000/targets/mcp/everything
  4. Verify that the MCP target is removed.

    curl http://localhost:19000/targets/mcp

    Example output:

    []
    
  5. List all the A2A targets that are configured on your Agent Gateway and note the name of the target that you want to remove. In the following example, the name of the A2A target is google_adk.

    curl http://localhost:19000/targets/a2a

    Example output:

    [{"name":"google-adk","host":"127.0.0.1","port":10002}]%
    
  6. Remove the A2A target from your Agent Gateway.

    curl -X DELETE curl http://localhost:19000/targets/a2a/google_adk
  7. Verify that the A2A target is removed.

    curl http://localhost:19000/targets/a2a

    Example output:

    []