feat(tool/openapitoolset): generate tools from an OpenAPI 3.x spec
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 8.8k
- Forks
- 1k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 88
Description
What
Add a toolset that reads an OpenAPI 3.x document and exposes each operation as an ADK tool, so an agent can call a REST API described by its spec without anyone hand-writing a functiontool per endpoint.
Target import path: google.golang.org/adk/tool/openapitoolset.
Why
adk-python has had this since early on, as google/adk/tools/openapi_tool (openapi_toolset.py, operation_parser.py, rest_api_tool.py). adk-go has no equivalent, so anyone pointing an agent at an existing REST API has to write the wrappers by hand.
#451 attempted it and we closed it: it was stacked on two auth PRs that did not land, and its hand-rolled parser skipped $ref rather than resolving it. The goal here is a much smaller change that reuses what main already provides.
Design constraints
These come from decisions already made in the repo, so a PR that ignores them will not land.
- Credentials go through
auth.CredentialProvider. Main'sauthpackage resolves one credential per invocation andauth.Transportis anhttp.RoundTripperthat applies it per outgoing request. The toolset supplies a provider and anhttp.Client; it must not build auth headers itself, and it must not reimplement token exchange or refresh.golang.org/x/oauth2does that. - It should be a separate Go module. CONTRIBUTING says integrations with heavy or optional dependencies are separate modules, and an OpenAPI library is one.
plugin/agentanalyticsis the precedent. This keeps the parser dependency out of the rootgo.mod, which is what makes the library choice below a low-stakes decision rather than a repo-wide one. - The library must resolve
$ref. This is the requirement #451 failed. A parameter or request body that referencescomponents/schemashas to arrive at the tool declaration fully resolved, otherwise the model receives an untyped argument and the tool call is wrong in a way nothing detects. - Operation-level parameters override path-level ones by name and location, per the OpenAPI specification. Appending both lists is a correctness bug.
Decision needed: which library
All three are maintained and permissively licensed. Figures checked on 1 September 2026.
| Library | Licence | Last push | Notes |
|---|---|---|---|
github.com/getkin/kin-openapi |
MIT | 2026-08-28 | Covers OpenAPI 3.0, 3.1, 3.2 and Swagger 2. openapi3.Loader resolves internal and external $ref. Most widely used of the three. |
github.com/pb33f/libopenapi |
MIT | 2026-07-29 | Covers 3.0, 3.1, 3.2 and overlays. Offers both a high-level and a low-level model, and preserves document ordering. |
github.com/google/gnostic |
Apache-2.0 | 2026-08-10 | Compiles a spec into protobuf models. In-house, but built as a compiler and code generator rather than a resolver-first library, so its $ref behaviour needs checking against requirement 3 before it is chosen. |
Recommendation: kin-openapi, on the grounds that its loader already meets requirement 3 and it has the widest usage. Whoever picks this up should confirm the resolution behaviour with a spec that uses components/schemas before committing to it.
Scope
In scope:
- Parse an OpenAPI 3.x document from bytes, a file path, or a URL, in JSON or YAML.
- Emit one tool per operation, with a resolved
genai.Schemafor parameters and request body. - Path, query, header and cookie parameters, and a JSON request body.
- Execute the call over an injected
*http.Client, soauth.Transportsupplies credentials. - Implement
tool.Toolset, includingClose. - A filter so callers can select a subset of operations, matching the existing
tool.Predicatepattern.
Out of scope for the first PR:
- OAuth2 consent flows.
authhandles those. - Non-JSON request bodies,
multipart/form-data, and file upload. - Response schema validation.
Acceptance
- Table-driven tests over a spec fixture that uses
components/schemas,$refparameters, and both path-level and operation-level parameters. - A test proving an operation-level parameter overrides a path-level one of the same name and location.
- No live network calls in tests.
- An example under
examples/pointing at a spec served byhttptest.
Credit
The idea and a first attempt came from @cpunion in #451. The constraints above are what that PR ran into, not a criticism of it. @cpunion, you are welcome to take this if you would like it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with auth.CredentialProvider and auth.Transport, then inspect plugin/agentanalytics for the separate-module pattern. Confirm kin-openapi resolves internal and external $ref before choosing it, and define the openapitoolset entry points around the injected http.Client and tool.Predicate filter. Done means table-driven fixture tests cover schemas, parameter precedence, no live network calls, and an httptest example is included.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100