# MCP tool search

**Last updated:** 2026-11-22T07:10:00-03:00 (UTC-3)

An agent with access to many MCP servers should not load every tool definition into its context. Tool search answers one question instead: which of the tools **this key may run** fit a short description of the task. It ranks only authorized tools, says where each result's text came from, and never contacts an MCP server.

| Flag | Default | What it turns on |
| --- | --- | --- |
| `mcp_tool_search` | `false` | `POST /v1/mcp/tools/search`; requires `mcp_execution` and `mcp_registry`; a public resource right under plan entitlements |

A result grants nothing. Calling a tool still goes through the [execution routes](/docs/features/mcp-execution/), which check registry scopes, grants and schemas again at call time.

## Who may search, and what is searched

The key needs the `mcp:read` and `mcp:execute` scopes and, with plan entitlements, the `mcp_execution` and `mcp_tool_search` rights. Browser requests from another origin are refused, as for execution.

The candidates are built **before** any ranking, counting or embedding, from the same rules that admit a call:

- **Boot servers** (`mcp_execution.servers`): the registry entry must be enabled, every registry scope must admit the key, and the tool grant must list the key's team or key ID.
- **Console servers** (`mcp_connect`): only `active` servers; only approved tools whose approval lists the key's team; and, as for calls, every scope of an enabled registry entry with the same ID must admit the key. A draft, rejected or disabled server, an unapproved tool, or a tool quarantined by drift (its latest snapshot no longer carries the approved schema) is never a candidate.
- **Access groups**: a group toolset (`mcp_tools`) narrows the candidates exactly as it narrows calls.

A tool the key cannot run is not in the results, not in `ranking.candidates` and never in an embeddings input. Revoking a grant, disabling a server or removing a team from an approval takes effect on the next search.

The searchable text is the text an administrator reviewed, never a live upstream listing:

- for a boot grant, the optional `description` written next to the grant in YAML (at most 300 printable characters on one line);
- for a console server, the description recorded in the **approved** snapshot for that tool and schema hash. A drift snapshot never replaces that text; a drifted tool leaves the results until it is approved again or a later test snapshot carries the approved schema (if the upstream reverts on its own, calls run again before search shows it; the error is on the side of fewer results).

## Configure

The bounds are boot settings under `mcp_execution.tool_search`. `GET /api/v1/admin/config` serves them, effective, as `mcp_execution.tool_search` (`mode`, `embedding_model`, `max_results`, `max_query_chars`, `max_embedding_inputs`, `cache_entries`); the Search tools panel shows them read-only, and changing them needs a rollout. Before T183 the API served this block as a top-level `mcp_tool_search`.

```yaml
features:
  mcp_registry: true
  mcp_execution: true
  mcp_tool_search: true
mcp_execution:
  protocol_version: "2025-11-25"
  tool_search:
    mode: embedding            # lexical (default) or embedding
    embedding_model: embed-small # an embeddings alias; required for embedding, refused for lexical
    max_results: 10            # default and ceiling of one search, 1-50
    max_query_chars: 512       # 16-4096
    max_embedding_inputs: 128  # texts one search may embed, query included, 1-1024
    cache_entries: 4096        # process-local vectors, 0-65536; 0 disables the cache
  servers:
    - id: weather
      endpoint_url: https://weather.example.com/mcp
      tools:
        - name: forecast
          description: Weather forecast for a city
          allowed_team_ids: [platform]
```

| Field | Default | Bounds |
| --- | --- | --- |
| `mode` | `lexical` | `lexical` or `embedding` |
| `embedding_model` | empty | required for `embedding`; must be empty for `lexical` |
| `max_results` | 10 | 1-50 |
| `max_query_chars` | 512 | 16-4096 |
| `max_embedding_inputs` | 128 | 1-1024 |
| `cache_entries` | 4096 | 0-65536 |

**Lexical** ranks with BM25 over the tool name (weighted twice) and its description; tokens split on punctuation and camelCase, so `rainAlerts` finds `rain_alerts`. Only tools that share a term with the query are returned. No provider is called.

**Embedding** sends the query and the candidate texts (`server name: tool\ndescription`) to `/v1/embeddings` through the gateway, **as the caller's key**: that key must be allowed to use the alias, and its rate limits, quotas, budget and usage records apply to the embedding call exactly as to any other request. Every search makes that call, because the query itself is never cached; so a key that lost the alias or its budget is refused even when every tool vector is cached, and no key can tell which queries a teammate ran. Tool vectors are cached per team and per resolved alias (changing the alias target or its provider connection starts a new cache; a vector whose dimensions no longer match is dropped), within `cache_entries` and at most 64 MiB per process. At most `max_embedding_inputs` texts are sent by one search, the query first and then the uncached tools that match the query best lexically; candidates left over rank after the embedded ones by their lexical score, and the response counts them. Nothing falls back silently: a refused or failed embedding call returns an error and ranks nothing.

## Search

```http
POST /v1/mcp/tools/search
Authorization: Bearer <key with mcp:read and mcp:execute>
Content-Type: application/json

{"query": "will it rain tomorrow in Lisbon", "limit": 5}
```

`query` is required (trimmed, 1 to `max_query_chars` characters; the body is at most 64 KiB); `limit` defaults to and is capped by `max_results`. Unknown fields are refused. Searches take one of the four shared slots that also bound tool calls, MCP health checks and a few heavy administrative reads, waiting for one up to three seconds; an embedding search can hold its slot up to 20 seconds.

```json
{
  "data": [
    {
      "server_id": "weather",
      "server_name": "Weather",
      "tool": "forecast",
      "description": "Weather forecast for a city",
      "source": "boot",
      "score": 0.912345,
      "embedded": true
    },
    {
      "server_id": "alerts",
      "server_name": "Alerts",
      "tool": "rain_alerts",
      "description": "Rain and storm alerts",
      "source": "managed",
      "approved_snapshot_id": 42,
      "schema_sha256": "9f2c…",
      "score": 0.871002,
      "embedded": true
    }
  ],
  "ranking": {
    "method": "embedding",
    "embedding_model": "embed-small",
    "candidates": 2,
    "embedded_inputs": 1,
    "cached_vectors": 2,
    "unembedded_candidates": 0
  }
}
```

`source` is `boot` (YAML grant) or `managed` (console approval, with the reviewed snapshot and schema hash). `embedded` is false for a result ranked lexically because the embedding budget ran out.

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | `invalid_request` | Empty or oversized query, limit outside 1-`max_results`, unknown field |
| 403 | `scope_forbidden`, `origin_forbidden`, `entitlement_forbidden` | Missing scope, cross-origin browser request, plan without the right |
| 403 | `tool_search_embedding_forbidden` | The key may not use the embeddings alias |
| 404 | `feature_disabled` | A required flag is off |
| 429 | `tool_search_embedding_limited` | The key's limits or budget refused the embedding call |
| 503 | `mcp_busy` | Every MCP operation slot stayed taken for three seconds |
| 503 | `tool_search_embedding_unavailable`, `storage_unavailable` | The embeddings alias is missing or failed; approvals could not be read |

## Console

**MCP registry → Search tools** sends a query with an inference key kept only in the page's memory and shows each result with its server, provenance (boot grant or approved snapshot), score and, in embedding mode, how many texts were embedded, reused from the cache or left out by the budget. Running a tool stays in the separate execution panel.

## Logs and limits

Each search writes one `mcp_tool_search` log line with the request ID, key, team, method, candidate and result counts, embedded inputs, status and duration. The query text and descriptions are never logged. The vector cache is per process: each replica embeds a team's tool texts once. Search does not read live upstream descriptions, resources or prompts, and does not run anything.
