For the complete documentation index, see llms.txt.
Skip to main content

Context Control: Mechanisms and Trade-offs

Context Control is the deliberate design of the MCP contract and Tool results presented to a model. The goal is not simply to minimize bytes. It is to expose the smallest useful action surface while preserving the information required for a correct task.

The mechanisms act at different stages​

MechanismChangesBest used whenTrade-off
Included or excluded operationsGenerated Tools visible from the ServiceThe backend has operations irrelevant to the consumerCouples the Plan to backend operation names
includedArtifactsAdditional Prompts, Resources, Custom Tools, and output filtersConsumers need different capability bundles from one ServiceAn empty selection means all attached Artifacts, so deletion requires care
Declarative Custom ToolTool name, description, input schema, and mapping to one generated ToolA backend operation needs a stable, agent-oriented contractMapping must be maintained when the target operation changes
Scripted Custom ToolA composed action that can invoke allowed ToolsOne action requires orchestration or conditional logicAdds code, runtime limits, and a larger maintenance surface
jsonRetainBranches present in a JSON Tool resultThe backend returns useful data mixed with large irrelevant branchesRequired fields can be removed accidentally
jsonPatchesShape or values of a JSON Tool resultThe client needs a stable response shape or small transformationPatch paths depend on the backend response structure
TOONEncoding of the treated resultRepetitive structured data benefits from a more compact representationThe client or model must interpret TOON; semantics are unchanged

Reduce the advertised operation surface​

Start with operation selection when the problem is too many generated Tools. An allowlist is usually easier to review than a denylist because every exposed operation is explicit. In reShapr, includedOperations takes precedence when both lists are present; with neither list, all Service operations are available.

This choice affects Tool discovery, not backend permissions. The backend should still enforce its own authorization policy.

Replace protocol detail with a business action​

Use a declarative Custom Tool when the useful action maps to one generated Tool but needs a clearer contract. Use a scripted Custom Tool only when the action must combine calls or perform logic that declarative argument mapping cannot express.

Custom Tools do not automatically make an operation safer or its result smaller. Pair them with operation selection and output filtering according to the actual task.

Select capability bundles per consumer​

Attach reusable Artifacts to the Service, then use includedArtifacts to select them per Plan. This supports, for example, one Plan with only a weather Tool and another with the same Tool plus Prompts and Resources.

Selection uses Artifact names, while derived capabilities show what each custom Artifact declares:

  • Prompt names for a Prompts Artifact;
  • Tool names for a Custom Tools Artifact;
  • Resource and Resource Template URIs for a Resources Artifact;
  • target Tool names for an output-filter Artifact.

These capability names are composition metadata. They help a user choose Artifacts but do not themselves add another runtime authorization layer.

Treat the response after the call​

Use jsonRetain to keep only required branches, then jsonPatches for explicit RFC 6902 transformations. Enable TOON only after the JSON result has the intended information and shape. In the 0.2.3 runtime, the order is fixed: retain, patch, then encode.

Filters fail open in 0.2.3: if a selected filter cannot parse or transform the response, the Gateway returns the original response. This avoids replacing a successful backend call with a filtering failure, but it means filtering must not be treated as a security boundary for removing sensitive fields.

Three common decisions​

Too many Tools are visible​

  1. Start with an operation allowlist.
  2. Exclude attached Custom Tool Artifacts that this consumer does not need.
  3. Verify the result with tools/list.

Low-level operations do not express the user task​

  1. Prefer one declarative Custom Tool over exposing several implementation-oriented operations.
  2. Use a scripted Tool only if orchestration is required.
  3. Keep only the generated target operations required by the Custom Tool.

Tool results are too large or unstable​

  1. Retain only fields required by the task.
  2. Patch the shape only when a stable transformation is needed.
  3. Consider TOON after content reduction, not as a substitute for it.
  4. Compare payloads using the same request and a published byte-counting method.

Measure without overclaiming​

Measure the exact Tool list or response produced by two named configurations. Record the request, protocol version, filter, encoding, date, and byte-counting command. A reduction observed for one API response does not establish a universal token reduction or improved model accuracy.

Continue with From API Contract to Agent Action for the complete request flow. The Custom Tools and Tools Output Filtering pages remain the syntax references.

Agent View