Visibility and approval for tool calls
The Model Context Protocol (MCP) defines how servers expose tools to language models. Models can use these tools to query databases, call APIs, or perform calculations. MCP tools are designed so that models can discover and call them automatically based on their context and the user's prompts.
For security, MCP recommends keeping a human in the loop who can reject tool calls. It also recommends that applications clearly show which tools are available to the model, provide visual indicators during calls, and prompt users to approve actions. The protocol leaves the choice of user interface to the application.
A client sends a tools/list request to discover available tools. It uses tools/call to invoke a tool. In the tool definition, name is the unique identifier, description explains what the tool does, and inputSchema defines the expected parameters. Optional annotations can describe aspects of the tool's behavior.
Under MCP, clients should treat tool annotations as untrusted unless they come from trusted servers. A server uses listChanged to indicate whether it will send notifications when the list of available tools changes. A server that advertises this capability should send a notification when the list changes.
MCP also recommends that clients ask users to approve sensitive operations and show them the tool inputs before sending the call to the server. Showing the inputs helps guard against malicious or accidental data exfiltration. Clients should also validate tool results before passing them to the LLM.
Limiting functionality and permissions
The OWASP Gen AI Security Project describes Excessive Agency as the risk that unexpected, ambiguous, or manipulated LLM outputs can lead to harmful actions. OWASP links this risk to excessive functionality, excessive permissions, or excessive autonomy. The impact depends on which systems the application can interact with.
In OWASP's example of excessive functionality, an agent only needs to read content from a repository. The extension it uses also has functions for modifying and deleting that content. OWASP recommends limiting the extensions an agent can call and the functions those extensions expose to the minimum needed.
OWASP also addresses open-ended functionality. It recommends avoiding extensions that can execute arbitrary shell commands where possible and using more narrowly scoped functions. In its example, an extension dedicated to writing files can handle output that needs to be saved to a file.
Permissions need their own checks. In OWASP's example, a read-only operation uses an extension that connects to a database under an identity with SELECT as well as UPDATE, INSERT, and DELETE permissions. OWASP recommends limiting the extension's permissions in other systems to the minimum required and granting the appropriate database permissions to the identity used for the connection.
OWASP also recommends carrying out actions on a user's behalf in that user's context with the minimum privileges required. In its example of an extension that reads a code repository, the user authenticates through OAuth and the extension uses the minimum scope required. OWASP also recommends requiring human approval before carrying out high-impact actions.
Authorization decisions require checks beyond the LLM. OWASP recommends enforcing authorization in downstream systems and validating every request made through an extension against security policies. MCP also requires servers to validate all tool inputs and enforce appropriate access controls.
Tool output and error handling
MCP requires servers to sanitize tool outputs and rate-limit tool calls. It recommends that clients validate tool results before passing them to the LLM, enforce timeouts on calls, and log tool usage for auditing.
A tool result can contain structured or unstructured content. Unstructured content is returned in the result's content field. Structured content is returned as a JSON object in the structuredContent field. If a tool defines an outputSchema, the server must return a structured result that conforms to it. The client should also validate the result against that schema.
MCP defines two ways to report errors. Unknown tools, invalid arguments, and server failures can be reported as protocol errors. Errors encountered while running a tool, such as API failures, invalid input data, and business logic errors, are reported in the tool result with isError: true.