Generate tools from an API spec
An API spec is an OpenAPI document or a GraphQL schema: a file that lists every operation an API has and what each one takes. You need:
- Terraform set up with the Spotlight provider, using a token that has the
configurescope, and thesecretsscope if you keep a key. See Manage Spotlight with Terraform. - An OpenAPI 3.0 or 3.1 spec, in JSON or YAML, or a GraphQL endpoint. Spotlight does not read Swagger 2; convert it to OpenAPI 3 first.
- On a self-hosted Spotlight with an outbound allow-list, the list includes the host the spec is read from and the API's own host. Spotlight reads the spec and calls the API from its own servers.
- If the API needs credentials: a key stored as a secret, as in Add a tool from an HTTP API, or an OAuth connection, as in Connect an integration that signs in with OAuth.
The examples use the public Swagger Petstore, an OpenAPI sample, and Linear's GraphQL API.
Name the spec
For an OpenAPI spec, add an openapi block to the integration's
definition, with the spec's url:
resource "spotlight_integration" "petstore" {
team_id = data.spotlight_team.core.id
definition = {
integration = "petstore"
name = "Petstore"
openapi = {
url = "https://petstore3.swagger.io/api/v3/openapi.json"
baseUrl = "https://petstore3.swagger.io/api/v3"
auth = { secrets = ["secret.${spotlight_secret.petstore_key.name}"] }
}
}
}If the spec itself can be read only with the key, give baseUrl. See
Reading the spec
for when Spotlight sends auth.
If the spec is not published anywhere, write it out as document
in place of url, and give baseUrl.
For a GraphQL API, add a graphql block instead, with the endpoint as url.
Spotlight requests the schema from the endpoint, sending the block's auth:
resource "spotlight_integration" "linear" {
team_id = data.spotlight_team.core.id
definition = {
integration = "linear"
name = "Linear"
connection = {
oauth2 = {
authorize = "https://linear.app/oauth/authorize"
token = "https://api.linear.app/oauth/token"
scopes = ["read", "write"]
}
}
graphql = {
url = "https://api.linear.app/graphql"
auth = { oauth2 = {} }
}
}
}If the endpoint does not answer schema questions, write the schema out as
document in GraphQL's schema language, and keep url for the calls.
An integration has one openapi, graphql or mcp
block. Run terraform apply.
Check what was generated
Spotlight reads the spec during the apply. Once it finishes:
terraform state show spotlight_integration.petstoretools lists every tool the integration offers, such as
"find-pets-by-status" = "petstore.find-pets-by-status". spec.tools
counts the generated ones.
The apply's warnings name each operation Spotlight skipped, and why, such as one that takes a body other than JSON.
If spec.problem is set, Spotlight could not read the spec, and
the apply shows the same reason as a warning on the block's url, or on its
document. Fix the cause. If the fix is outside the definition, also
raise revision. Then run terraform apply.
If the integration signs in with OAuth and the API answers only with
credentials, the first read fails. Connect the team,
and Spotlight reads the spec again. This also applies to an integration whose
actsAs is requester too: the spec is read with the team's
connection, and a person connecting their own account does not read it again.
Choose which tools it offers
To offer only some operations, add tools.include and tools.exclude
to the block. Each entry matches a tool name, with * for any run of
characters:
openapi = {
url = "https://petstore3.swagger.io/api/v3/openapi.json"
baseUrl = "https://petstore3.swagger.io/api/v3"
auth = { secrets = ["secret.${spotlight_secret.petstore_key.name}"] }
tools = {
include = ["*pet*"]
exclude = ["delete-*"]
}
}If the apply fails because the spec gives more than 1,000 tools,
name fewer in tools.include.
To change how one tool calls the API, write a tool of the same name under the
definition's tools. The tool you wrote is offered in place of the generated
one.
Decide which calls wait for approval
Generated tools that change data wait for a person to approve each call. To change which ones wait, or the reason a person reads, see Require approval before a tool runs.
Enable a tool at a station
Name the tool through the integration's tools map, as for any tool:
station {
key = "implementation"
name = "Implementation"
harness = "claude-code"
tools = [spotlight_integration.petstore.tools["find-pets-by-status"]]
passes_to = ["code-review"]
}If the tool does not exist, the apply fails, not the plan. See Top level.
The agent calls the tool with the API's own input names. An input that takes a list or an object is given as JSON:
spotlight tools call petstore.find-pets-by-status --status sold
spotlight tools call linear.issue-create --input '{"teamId": "<team id>", "title": "Flaky upload test"}'Read the spec again
When the API changes behind the same address, set or raise revision, then
run terraform apply:
openapi = {
url = "https://petstore3.swagger.io/api/v3/openapi.json"
baseUrl = "https://petstore3.swagger.io/api/v3"
revision = "2"
}Reading the spec lists every change that makes Spotlight read it again.
Related
spotlight_integration: every field of theopenapiandgraphqlblocks, and how tools are named.- Agent commands: how an agent gives a tool its inputs.
- Limits and timeouts