Skip to content

Serve API Explorer APIs and operations from the docs API - #4887

Merged
akira28 merged 8 commits into
mainfrom
feature/api-operations-rest-endpoints
Nov 18, 2026
Merged

akira28 merged 8 commits into
mainfrom
feature/api-operations-rest-endpoints

Conversation

@akira28

@akira28 akira28 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The docs API gains an /docs/_api/v1/apis resource, with each API's operations under it, that answers the same lookups as the API MCP tools in #4886. HTTP clients such as the Elastic CLI can now search, read and list API Explorer operations without speaking MCP.

Affects: API, MCP

Follows: #4886, now merged. This PR is rebased onto main.

Stack: bottom of #4895. #4894, #4896, #4897 and #4898 build on it.

Prompt summary: The Elastic CLI should expose the API Explorer MCP tools as elastic docs api * commands (elastic/docs-eng-team#1204) and call the docs API rather than the MCP server. Add the matching API requests here, reusing the MCP code where possible.

Why

The CLI reaches the docs site only through /docs/_api/v1 (search, ask-ai). The new API lookups exist only as MCP tools. A CLI that called them would need to speak JSON-RPC over Streamable HTTP, which is the wrong layer for a plain HTTP client.

What

One service for both surfaces

ApiGateway, IApiGateway and ApiRouteMatch move unchanged from Mcp.Remote/Gateways into Elastic.Documentation.Search/ApiReference, which both apps already reference.

A new ApiReferenceService holds what ApiTools did before:

  • the version needs api check
  • scope normalization and page size clamping
  • the operationId-or-endpoint check
  • grouping, and the group-names-only reply for large APIs

It answers with an ApiReferenceReply union: one of its response records, or an ApiReferenceRejection. The response records move from McpResponses to sit next to the service.

ApiTools keeps its tool names, parameters and descriptions, and now maps that union onto ToolReply. The bodyNote stays MCP-only, because it tells the caller to pass includeBody=true. ResponseBody.Note now takes a body length, so the MCP layer can still compute the note. AddApiReferenceServices() registers the gateway and the service for both apps.

The gateway gains FindOperationsAsync. Its id and endpoint lookups already load every ranked match with DetailSource, so it returns all of them with their versions, fields and body from that one query. GetOperationAsync is built on it.

Endpoints

Every operation lives under its API. Most operation ids and many routes exist in several APIs: elasticsearch and elasticsearch-serverless share 325 ids, kibana and kibana-serverless 724, and cloud and cloud-enterprise 115. A lookup across APIs could only return them in an undefined order and pick one, so the REST API has none.

Request Same as
GET /apis list_api_operations without arguments
GET /apis/{api} none (one API's key, title and versions)
GET /apis/{api}/groups?version=&include_deprecated= the group summary of list_api_operations
GET /apis/{api}/operations?q=&version=&include_deprecated=&page=&size= search_api_operations with an API
GET /apis/{api}/operations?endpoint=&view=full&include_body= get_api_operation by endpoint, with every match in the API, best route first
GET /apis/{api}/operations?group=&page=&size= list_api_operations with a group, paged
GET /apis/{api}/operations/{operationId}?version=&include_body= get_api_operation by id
  • One API per request: {api} is part of every operation path, so an operation id or a route matches in that API only. Results are complete and deterministic, and no client has to pick one.
  • The operations collection: it takes at most one of q or endpoint. Without either, it lists the API by path, hides deprecated operations unless include_deprecated=true, and pages. That makes the group-names-only reply for large APIs unnecessary; it moves to /apis/{api}/groups.
  • Endpoint lookups: a route made only of parameters, such as /{index}, can serve several operations even within one API, so an endpoint lookup returns a page. view=full adds each match's versions and fields, and include_body=true its body. That's one request and one index query, because FindOperationsAsync returns the details.
  • Group counts: /apis/{api}/groups drops deprecated operations unless include_deprecated=true, like the listing, so a group's count equals its listing's totalHits. A blank API key is a 400.
  • Rules in one place: every check lives in ApiReferenceService, including view, with unit tests in ApiReferenceServiceTests.
  • Errors: a lookup that matches nothing returns an empty page. A rejection returns { "errorType", "message" }, with 404 for *_not_found and 400 otherwise. Publish an OpenAPI document for the docs API and answer errors as RFC 9457 problems #4896 replaces this body with RFC 9457 problems.
  • Parameters: query parameters are snake_case, like navigation-search.
  • MCP tools: they keep their names, parameters and replies. Their api stays optional, so agents can still search across APIs, and a lookup without it may match in several.

One wording change: the group_not_found message no longer names the MCP tool.

Verify

dotnet test --project tests/Elastic.Documentation.Api.Tests --treenode-filter "/*/*/ApiOperationsEndpointTests/*"
# routing, argument mapping, status codes, body on request
dotnet test --project tests/Mcp.Remote.Tests
# ApiTools, ApiGateway and ApiRouteMatch tests, unchanged in behavior
mise run integrate
# ApiToolsIntegrationTests still run through the shared service

I ran the two unit projects locally on top of main (267 and 76 tests pass) and built the integration project. I did not run the endpoints against a real index.

🤖 Generated with Claude Code

@akira28
akira28 requested a review from a team as a code owner November 17, 2026 11:19
@akira28
akira28 requested a review from Mpdreamz November 17, 2026 11:19
Base automatically changed from feature/issue-add-new-mcp to main November 17, 2026 11:59
akira28 and others added 2 commits November 17, 2026 13:19
The CLI and other HTTP clients can now search, read and list API Explorer
operations without speaking MCP. The gateway moves to the search project,
and a shared ApiReferenceService holds the argument checks and grouping, so
the MCP tools and the new /api-reference endpoints answer the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The operation lookup told HTTP callers to pass operationId, which the
endpoint does not take. The REST API page now lists the three lookups with
their parameters, defaults, responses and status codes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 force-pushed the feature/api-operations-rest-endpoints branch from 168d742 to cbe5c12 Compare November 17, 2026 12:20
@github-actions

Copy link
Copy Markdown
Contributor

The lookups move from /api-reference/{,search,operation} to
/api-operations: the collection filters by q or by endpoint, one
operation reads by id, and groups and apis are their own routes, so each
route returns one shape. An endpoint lookup now lists every operation that
serves the request, best first, instead of reading the top match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28 akira28 changed the title Serve API Explorer operation lookups from the docs API Serve API Explorer operations from the docs API Nov 17, 2026
Operations are one collection at /api-operations, filtered by q, endpoint,
operation_id, api, version and group, and read at /api-operations/{id},
where id is {api}:{operationId}. APIs and their groups move to /apis, so no
literal route shadows an id. view=full adds fields to each result, so an
endpoint or id lookup without an API key takes one request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28 akira28 changed the title Serve API Explorer operations from the docs API Serve API Explorer APIs and operations from the docs API Nov 17, 2026
akira28 and others added 2 commits November 17, 2026 14:30
The gateway's lookups already load each match's trees, properties and body,
so FindOperationsAsync returns them all and the full view no longer reads
each other match again. Group counts drop deprecated operations unless
include_deprecated is set, like the group listing, and a blank API key is a
400 instead of a NullReferenceException.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every other rule of the operations collection lives in ApiReferenceService.QueryAsync; the view check was the only one in the HTTP handler, so it now sits with them and has a unit test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Most operation ids and many routes exist in several APIs: elasticsearch and
elasticsearch-serverless share 325 ids, kibana and kibana-serverless 724. A
lookup across APIs had to pick one, in no defined order. Operations now live
under /apis/{api}/operations, searched, looked up by endpoint or listed there,
and read at /apis/{api}/operations/{operationId}. /api-operations, the
{api}:{operationId} ids and the operation_id filter are gone. The MCP tools
keep their optional api.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
akira28 added a commit that referenced this pull request Nov 17, 2026
The copy follows #4887, where /api-operations moved to /apis/{api}/operations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 merged commit 2af9fae into main Nov 18, 2026
44 checks passed
@akira28
akira28 deleted the feature/api-operations-rest-endpoints branch November 18, 2026 09:19
akira28 added a commit that referenced this pull request Nov 18, 2026
The copy follows #4887, where /api-operations moved to /apis/{api}/operations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants