Model Context Protocol › Trust boundaries
Language AI HandbookAll chapters The protocol describes messages between participants. A host still limits which capabilities enter the model context, and the application or operating system restricts what a server can access. Keep returned content in its proper role. A prompt template, tool description or catalog record is data from a server. It cannot grant additional privileges or approve a subsequent action. Human approval and server authorization can work together without either taking the other's place.
Older deployments may still use roots and sampling. The modern specification deprecates roots and sampling. A roots declaration does not confine a process. Use operating-system or application-level restrictions to enforce access, and pass necessary resource identifiers or tool arguments explicitly. For modern interaction patterns that request user input, the host still decides what information to share.
When debugging an integration, start by distinguishing four questions.
- Does the client support the revision the server speaks?
- Does the server implement the operation and advertise the applicable capability?
- Does the server accept the caller and permit that operation on this data?
- Does the host policy allow the model to propose or submit the action?
A schema says what arguments fit, so check the advertised schema against the handler and exercise malformed calls separately from expected business failures. Validate the authorization behavior for a permitted and a denied caller. Restrict returned data to what the task needs. Logs for approvals and decisions can be useful without storing raw sensitive inputs unnecessarily.
Which tools enter the interface
A server can implement several legitimate operations while the task needs one. In the following inventory the server implements lookup, export and a feature unrelated to reading. For the illustrated reader identity, the server lists lookup and export. The reading host offers only lookup in this interface. The offered set is the intersection of the permitted list and the host's task list.
PythonIn [17]Expand
implemented_tools = {"lookup", "export", "index_status"}
listed_for_reader = {"lookup", "export"}
reading_interface_policy = {"lookup"}
offered_for_reading = listed_for_reader & reading_interface_policy
assert offered_for_reading == {"lookup"}
tool_stage_counts = {
"Implemented": len(implemented_tools),
"Listed to reader": len(listed_for_reader),
"Offered by host": len(offered_for_reading),
}VisualizationOut [18]Expand

The host applies the task filter before creating model-facing tool descriptions. An approval screen can then confirm an individual call. Both restrictions matter if the caller changes or the catalog is updated after discovery. In a multi-user host, a shared connection cache also needs a key compatible with the discovery response's scope, so a cached private view cannot accidentally leak to another identity.
Bounding returned content
A read-only call can still return more data than the model or interface needs. Set a separate response budget for the representation passed into the model context. In this example the application builds a serialized JSON object from one fictional record and sends a small summary when the full object exceeds a local UTF-8 byte cap. The cap is deliberately about application context assembly. Model token and transport limits need their own checks.
PythonIn [19]Expand
context_byte_cap = 120
full_context_record = {
**found["structuredContent"],
"notes": "Fictional catalog annotation for the seminar reading list. " * 4,
}
compact_context_record = {**found["structuredContent"], "notes_omitted": True}
def encode_context(record):
return json.dumps(record, ensure_ascii=False, separators=(",", ":")).encode(
"utf-8"
)
full_context_bytes = encode_context(full_context_record)
compact_context_bytes = encode_context(compact_context_record)
chosen_context_bytes = full_context_bytes
if len(chosen_context_bytes) > context_byte_cap:
chosen_context_bytes = compact_context_bytes
if len(chosen_context_bytes) > context_byte_cap:
chosen_context_bytes = b""
assert len(full_context_bytes) > context_byte_cap >= len(chosen_context_bytes)
assert json.loads(chosen_context_bytes) == compact_context_record
context_sizes = {
"Complete record": len(full_context_bytes),
"Submitted summary": len(chosen_context_bytes),
}
print("Context sizes in bytes:", context_sizes)ConsoleOut [19]Expand
Context sizes in bytes: {'Complete record': 295, 'Submitted summary': 69}VisualizationOut [20]Expand

The compact object marks that notes were omitted, which gives the caller enough information to request more detail through the application if it is needed. In this fixture the second check emits empty context when even a summary exceeds the cap. Serializing the summary before checking its size keeps the application from passing an incomplete JSON value. Authorization applies before context assembly, so a smaller representation still needs to come from a record the caller may access.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!