Skip to content
Back to log

Security checkpoints for MCP tools

Chainabit's Chao · · 7 min read

In short

Learn what to show users when MCP tools are called, how to limit permissions, and what risks to consider in proxy, token, and session flows.

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.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

MCP's security guidelines describe the confused deputy risk in MCP proxy servers that connect to third-party APIs. In the scenario, the proxy uses a fixed client ID with the third-party authorization server and allows MCP clients to register dynamically. The third party sets a consent cookie, and the proxy proceeds to the third-party authorization flow without obtaining appropriate consent for each client.

In the attack scenario, the user has already granted consent in response to a legitimate request. The attacker then redirects the user with an authorization request containing a malicious redirect_uri and a newly registered client ID. The third-party authorization server may see the existing consent cookie and skip the consent screen. The MCP authorization code can then be redirected to the attacker's server and used to obtain an access token.

To defend against this attack, MCP requires the proxy server to track approved client_id values for each user and check those records before starting the third-party authorization flow. The MCP consent screen must clearly display the requesting client's name, the requested third-party API scopes, and the registered redirect_uri value.

The same security guidelines require the redirect_uri in the authorization request to match the registered URI exactly. If the URI has changed without re-registration, the server must reject the request. Validation must use an exact string comparison and exclude pattern or wildcard matching.

In the OAuth flow, the proxy server must generate a cryptographically secure, random state value for each authorization request. The server stores it only after the user gives explicit consent. If the state received at the callback is missing or differs from the stored value, the server rejects the request. The state value must be single-use, and the server must delete it after validation.

MCP defines token passthrough as accepting tokens from a client and forwarding them to a downstream API without verifying that they were properly issued for the MCP server itself. The authorization rules prohibit token passthrough. MCP servers must reject tokens that were never explicitly issued for them.

Token passthrough can bypass security controls that rely on the token audience or other credential restrictions. According to MCP's security guidelines, the server may be unable to distinguish between clients that make calls using an upstream access token, which may be opaque to the server. Downstream server logs may also attribute the request to a different identity than the MCP server that forwarded the token.

SSRF and session security

MCP explains that, in an SSRF attack, an attacker can trick an MCP client into making HTTP requests to unintended destinations. During OAuth metadata discovery, a malicious server can populate URL fields such as resource_metadata in the WWW-Authenticate header, authorization_servers in Protected Resource Metadata, and token_endpoint in Authorization Server Metadata.

MCP's security guidelines require server-side clients to assess SSRF risks and apply appropriate safeguards when fetching OAuth-related URLs. For production environments, the guidelines recommend requiring HTTPS for these URLs, blocking requests to private and reserved IP ranges, and applying the same URL validation to redirect targets. The appropriate safeguards depend on the network environment.

In session hijacking, an unauthorized party can obtain a session ID and impersonate the original client. MCP requires servers that implement authorization to verify every incoming request. Servers must avoid using sessions for authentication and use secure, unpredictable session IDs. MCP also recommends binding the session ID to user-specific information.

Local servers and the limits of security controls

Local MCP servers run on the user's machine and can access the system directly. In the absence of appropriate sandboxing and approval controls, MCP lists possible attacks such as inserting a malicious startup command into the client configuration or distributing malicious content in the server itself.

An MCP client that supports one-click local server configuration must obtain approval before running the command. Under MCP, the approval screen must display the full command, including its arguments and parameters, without truncation. It must explain that the operation runs code on the user's system, ask for explicit approval, and let the user cancel the configuration.

OWASP explains that logging and monitoring extension and downstream system activity cannot prevent Excessive Agency. OWASP likewise describes rate limiting as a way to mitigate the impact of unwanted actions. Together, these measures can help detect unwanted actions and limit the damage they cause.

Ready to start?

Download the app and continue from your phone.

End of Entry