Skip to content

Add MCP tools to search, read and list API Explorer operations - #4886

Merged
akira28 merged 7 commits into
mainfrom
feature/issue-add-new-mcp
Nov 17, 2026
Merged

akira28 merged 7 commits into
mainfrom
feature/issue-add-new-mcp

Conversation

@akira28

@akira28 akira28 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The docs MCP server gains three tools for the REST API reference: search_api_operations, get_api_operation and list_api_operations. An agent can now ask for an operation by route, such as GET /_cluster/health, or by operation id, and get its parameters and request and response fields as structured data.

Affects: MCP, Search

Prompt summary: Add MCP tools dedicated to API Explorer content, as filed in elastic/docs-eng-team#1203. Ship searching, reading and listing operations together in one PR.

Why

API operations reach an agent only through search_docs with sectionFilter: api and through get_document_by_url. Both return page-shaped results. An agent cannot look up an endpoint by route or operation id, narrow to one API and version, or read the fields of a request body. The docs search index already holds all of this in api.* on every API Explorer page, so the gap is only in the MCP server.

What

Searching operations

search_api_operations runs the same query as the API Explorer search box (ApiLookupQueryBuilder), so the MCP server and the site rank operations the same way. It understands typed routes, operation words and field paths, and a trailing dot such as retriever. lists child fields. Each hit carries the fields the query matched. Results can be narrowed to one API key and version, and deprecated operations stay out unless the caller asks for them.

Reading one operation

get_api_operation takes either an operation id or an endpoint. A concrete endpoint such as GET /my-index/_search resolves to the route it fills: the index returns every candidate template, and ApiRouteMatch picks the route with the most literal segments that also serves the typed method. A route made only of parameters, such as PUT /{index}, has no endpoint key, so the lookup also matches it by path. Index names cannot start with _, so a typed system route such as GET /_bulk never falls through to it. The reply lists the operation's routes, version trees and every documented field with its location (path, query, header, request, response). The page body comes back only on request. Operations that match equally well, such as the same operation id in another API, are listed as otherMatches.

Browsing APIs

list_api_operations without arguments lists each API's key, landing page and versions. The versions come from every rendering of the landing page, because a hidden rendering lists the trees whose content differs from the default. With a key, it returns the API's operations by group. An API with more than 150 operations returns only its group names and counts, and the caller then passes group, so a large API like Elasticsearch does not flood the context.

Versions and server instructions

Without a version, every tool reads the API's default tree, the documents that are not hidden. With a version, URLs are rebased into that tree. The public profile gains an Api module, and its introduction now points at these tools instead of sectionFilter: api. The search_docs parameter description stops suggesting the api value, which still works. The tools need no feature flag: without API Explorer documents in the index they return nothing.

One runner for every MCP tool

Each tool used to repeat the same span, logs and error handling, and only the search tools turned a transient backend failure into a retryable McpException. Every tool now hands its work to McpToolRunner, which returns either a JSON reply or a rejection such as "not found". As a result, the coherence tools and the new API tools also report timeouts and overloads as retryable. SearchUnavailableException.IsTransient holds the check, which FullSearchService and the API gateway share. The gateway also catches an overload that the client returns as an invalid response instead of throwing.

Verify

dotnet test --project tests/Mcp.Remote.Tests
# ApiRouteMatchTests, ApiGatewayTests, ApiToolsTests, plus the updated handshake and instruction snapshots
dotnet test --project tests/Elastic.Documentation.Journeys.Tests --treenode-filter "/*/*/McpHttp/*"
# the journeys copy of the MCP handshake
mise run integrate
# ApiToolsIntegrationTests: skips only when the index holds no API Explorer documents

Out of scope: the indexed body of an operation page is still a short summary. elastic/docs-eng-team#1176 replaces it with the full operation CommonMark, which improves includeBody=true without changes here.

🤖 Generated with Claude Code

Agents could reach API operations only through page-shaped search, so they
could not ask for an endpoint by route or operation id, or get its fields.
The new tools read the api.* fields the docs search index already holds and
reuse the query behind the API Explorer search box.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 requested a review from a team as a code owner November 17, 2026 09:41
@akira28
akira28 requested a review from Mpdreamz November 17, 2026 09:41
@github-actions

Copy link
Copy Markdown
Contributor

akira28 and others added 2 commits November 17, 2026 10:52
Route parsing repeated ApiEndpointPath.NormalizeQuery, and both gateways
formatted endpoints the same way by hand. The test stub now owns its client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The journeys suite keeps its own copy of the handshake response, which still
listed only the original tools.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every tool repeated the same span, logging and error handling, and only some
turned transient backend failures into a retryable McpException. The API
gateway also missed routes made only of parameters, listed only the versions
of the visible landing page, and reported overloads as permanent errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
akira28 and others added 2 commits November 17, 2026 12:10
The server instructions now send API lookups to the API tools, so the
parameter description pointed agents two ways. The filter value still works.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A typed route like GET /_bulk with the wrong method, or a typo such as
/_clusterr, matched GET /{index} and came back as the index operation.
Index names cannot start with an underscore, so such a segment never fills
a route made only of parameters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
_all is an index expression, so it fills a route made only of parameters
such as /{index} even though it starts with an underscore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 merged commit e223e5e into main Nov 17, 2026
44 checks passed
@akira28
akira28 deleted the feature/issue-add-new-mcp branch November 17, 2026 11:59
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