|
| 1 | +--- |
| 2 | +title: "OpenAPI Tool" |
| 3 | +description: "Automatically generate tools from an OpenAPI specification." |
| 4 | +permalink: /tools/openapi/ |
| 5 | +--- |
| 6 | + |
| 7 | +# OpenAPI Tool |
| 8 | + |
| 9 | +_Automatically generate tools from an OpenAPI specification._ |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +The OpenAPI tool fetches an OpenAPI 3.x specification from a URL and creates one tool per API operation. Each endpoint's parameters, request body, and description are translated into a callable tool that the agent can invoke directly. |
| 14 | + |
| 15 | +## Configuration |
| 16 | + |
| 17 | +```yaml |
| 18 | +toolsets: |
| 19 | + - type: openapi |
| 20 | + url: "https://petstore3.swagger.io/api/v3/openapi.json" |
| 21 | +``` |
| 22 | +
|
| 23 | +### With custom headers |
| 24 | +
|
| 25 | +Pass custom headers to every HTTP request made by the generated tools (for example, for authentication): |
| 26 | +
|
| 27 | +```yaml |
| 28 | +toolsets: |
| 29 | + - type: openapi |
| 30 | + url: "https://api.example.com/openapi.json" |
| 31 | + headers: |
| 32 | + Authorization: "Bearer ${env.API_TOKEN}" |
| 33 | + X-Custom-Header: "my-value" |
| 34 | +``` |
| 35 | +
|
| 36 | +## Properties |
| 37 | +
|
| 38 | +| Property | Type | Required | Description | |
| 39 | +| --------- | ----------------- | -------- | --------------------------------------------------------------------------- | |
| 40 | +| `url` | string | ✓ | URL of the OpenAPI specification (JSON format) | |
| 41 | +| `headers` | map[string]string | | Custom HTTP headers sent with every request. Values support `${env.VAR}` and `${headers.NAME}` placeholders. | |
| 42 | + |
| 43 | +## How it works |
| 44 | + |
| 45 | +1. The spec is fetched from the configured `url` at startup. |
| 46 | +2. Each operation (GET, POST, PUT, …) becomes a separate tool named after its `operationId` (or `method_path` when no `operationId` is set). |
| 47 | +3. Path and query parameters are exposed as tool parameters. Request body properties are prefixed with `body_`. |
| 48 | +4. Read-only operations (GET, HEAD, OPTIONS) are annotated accordingly. |
| 49 | +5. Responses are returned as text; errors include the HTTP status code. |
| 50 | + |
| 51 | +## Limits |
| 52 | + |
| 53 | +- The OpenAPI spec must be **10 MB or less**. |
| 54 | +- Individual API responses are truncated at **1 MB**. |
| 55 | + |
| 56 | +## Example |
| 57 | + |
| 58 | +See the full [Pet Store example](https://github.com/docker/docker-agent/blob/main/examples/openapi-petstore.yaml) for a working agent configuration. |
0 commit comments