For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
MCP tool modes
Choose how an MCP backend exposes upstream tools to clients, including progressive disclosure for large tool catalogs.
An MCP backend can expose the upstream server’s tools to the client in four different shapes. You choose the shape with the entMcp.toolMode field on an EnterpriseAgentgatewayBackend resource. The right choice depends on how many tools the upstream server has, how much of the client’s context budget you want to spend listing them, and whether you want the model to compose multiple tool calls in a single round trip.
Tool modes are how agentgateway implements progressive disclosure for MCP: the model receives a tool’s definition only when it needs that tool, instead of receiving the entire catalog up front. Search mode and code and search mode disclose one tool definition at a time, and Code mode replaces the catalog with a single scripting interface.
Tool modes
toolMode | What the client sees on tools/list | Use case |
|---|---|---|
Standard (default) | Every upstream tool, filtered by RBAC. | Backends with a small, stable tool set. |
Search | Two meta tools: get_tool and invoke_tool. The client searches for a tool by name, then invokes it. Progressive disclosure in its simplest form. | Backends with many tools, where listing them all would crowd the model’s context window. |
Code | A single run_code tool. The client submits JavaScript that calls the upstream tools, and the gateway executes the script in an embedded sandbox. | Multi-step workflows where the model would otherwise call several tools in sequence and pass intermediate results back through its context. |
CodeSearch | Two meta tools: get_tool and run_code. The client discovers a tool’s typed API with get_tool, then submits JavaScript that calls it. | Multi-step workflows on backends with so many tools that embedding every tool’s API in the run_code description would itself crowd the context window. |
Standard mode forwards tools/list and tools/call to the upstream server, applying any tool-access filters along the way. The other three modes intercept the upstream tool list at the gateway and present a different surface to the client. The upstream MCP server is unchanged in all four modes.
Standard mode
Standard mode is the default. The gateway forwards tools/list and tools/call requests through to the upstream server, with no transformation other than enforcing tool-access policies. The client sees the upstream server’s full tool catalog, minus any tools the caller is not authorized to use.
Standard mode is the right choice when:
- The upstream server exposes a small, stable set of tools that fits comfortably in the model’s context.
- You want the simplest pass-through behavior, with no gateway-side scripting or meta tools.
Search mode
Search mode is the plainest form of progressive disclosure. The client only sees get_tool and invoke_tool. The model issues a get_tool call with a name or description fragment, receives a small result that describes one matching tool, and then issues invoke_tool to call it. The full tool catalog never enters the model’s context.
Search mode is useful when:
- The upstream server exposes dozens or hundreds of tools.
- You connect multiple MCP servers to the same backend and the combined tool list would not fit in a reasonable context window.
- You want the model to discover tools at runtime instead of being primed with the full catalog.
For the step-by-step guide, see Search mode.
Code mode
The client sees a single run_code tool. Its description contains a typed JavaScript API generated from the descriptions, input schemas, and output schemas of the tools the caller is authorized to use. The model submits a script. The gateway compiles the script, executes it against the upstream MCP servers, and returns one result.
Code mode reduces context in two ways:
- Each upstream tool call’s response stays inside the sandbox. Only the final value the script returns is sent back to the model.
- Looping, filtering, joining, and error handling all happen in the script, so the model doesn’t burn turns describing those steps as separate tool calls.
For the step-by-step guide, see Code mode.
Code mode limits
The embedded runtime enforces the following limits per run_code execution. A script that exceeds any limit returns an error result rather than failing the session, so the model can recover by submitting a different script.
| Limit | Value | How to change |
|---|---|---|
| Memory | 4 MiB | Not configurable. |
| Tool calls | 20 | Not configurable. |
| Wall-clock time | 60 seconds (default) | Set entMcp.codeMode.timeout on the backend. |
| CPU time | 1 second (default) | Set entMcp.codeMode.cpuTimeout on the backend. |
| Stack size | 256 KiB | Not configurable. |
Note
Code mode currently runs in an in-process JavaScript runtime. It is not yet a fully sandboxed runtime that gives each session its own credentials, filesystem, and network.
How run_code is described to the model
The gateway builds the run_code tool description at session time. For each upstream tool the caller is authorized to use, it injects a TypeScript function signature from the tool’s input and output schemas. Field descriptions from the input and output schemas become comments on the generated types. For example, the description includes the following signature for the fetch tool:
// Fetches a website and returns its content
type Input = {
// URL to fetch
url: string,
};
async function fetch(input: Input): Promise<unknown>;When an upstream tool declares an output schema, the description also includes a type Output block and the function returns Promise<Output>. Tools that do not declare an output schema return Promise<unknown>.
If the caller is not authorized to use a tool, the gateway omits that function from the description. A script that tries to call a forbidden tool is rejected at runtime by the same authorization check that gates direct tools/call requests in Standard mode.
Code and search mode
The client sees two meta tools, get_tool and run_code. This code search mode combines progressive disclosure with sandboxed execution: the model calls get_tool to fetch the typed JavaScript API for a specific tool, then submits a script to run_code that calls it. The gateway executes the script against the upstream MCP servers and returns one result.
Code and search mode is the right choice when both of the following are true:
- The workflow benefits from Code mode, where the model composes several tool calls in one script and only the final return value reaches the model.
- The backend fronts so many tools that embedding every tool’s typed API in the
run_codedescription, as Code mode does, would itself crowd the model’s context.
Unlike Code mode, the run_code description does not list a function for every authorized tool. The model discovers each tool’s signature on demand with get_tool, the same way it would in Search mode, and get_tool returns the tool’s typed JavaScript API instead of the raw input schema. The returned signature includes input field descriptions and any declared output schema. Code and search mode honors the same execution limits and codeMode settings as Code mode.
For the step-by-step guide, see Code and search mode.
Configuration
All four modes live on the same field of the EnterpriseAgentgatewayBackend resource. The following example is for code mode.
The codeMode field is rejected at admission time unless toolMode is Code or CodeSearch. When toolMode is not set, the backend defaults to Standard.
apiVersion: enterpriseagentgateway.solo.io/v1alpha1
kind: EnterpriseAgentgatewayBackend
metadata:
name: mcp-backend
spec:
entMcp:
toolMode: Code # Standard | Search | Code | CodeSearch
codeMode: # Only valid when toolMode is Code or CodeSearch
timeout: 7s
cpuTimeout: 2s
targets:
- name: fetcher
static:
host: mcp-website-fetcher.default.svc.cluster.local
port: 80
protocol: SSERBAC
All four modes honor MCP tool-access policies. Tools that the caller is not authorized to use are filtered out of tools/list in Standard mode, hidden from get_tool results in Search mode and code and search mode, and omitted from the typed API embedded in the run_code description in Code mode. Invocations are also rejected at the gateway if a script attempts to call a tool the caller is not authorized to use.
For more information, see Control access to tools.
More resources
Code mode for OpenAPI to MCP - Blog
open_in_new
Code mode for OpenAPI to MCP - Demo 1
open_in_new
Code mode for OpenAPI to MCP - Demo 2Search mode
Apply progressive disclosure by replacing the full MCP tool list with two meta tools, get_tool and …
Code mode
Expose a single run_code tool so that the LLM composes multiple MCP calls in one script.
Code and search mode
Combine progressive disclosure and sandboxed execution with get_tool and run_code.