docs/en/mcp/security.mdx
When integrating external services like MCP (Model Context Protocol) servers into your CrewAI agents, security is paramount. MCP servers can execute code, access data, or interact with other systems based on the tools they expose. It's crucial to understand the implications and follow best practices to protect your applications and data.
Stdio transport if the server can control the command executed).Before configuring MCPServerAdapter to connect to an MCP server, ensure you know:
Avoid connecting to unknown or unverified MCP servers, especially if your agents handle sensitive tasks or data.
A significant and subtle risk is the potential for prompt injection through tool metadata. Here's how it works:
Crucially, this attack can occur simply by connecting to a malicious server and listing its tools, even if your agent never explicitly decides to use any of those tools. The mere exposure to the malicious metadata can be enough to compromise the agent's behavior.
Mitigation:
Stdio (Standard Input/Output) transport is typically used for local MCP servers running on the same machine as your CrewAI application.
StdioServerParameters is from a trusted source and has appropriate file system permissions. A malicious Stdio server script could still harm your local system.The Confused Deputy Problem is a classic security vulnerability that can manifest in MCP integrations, especially when an MCP server acts as a proxy to other third-party services (e.g., Google Calendar, GitHub) that use OAuth 2.0 for authorization.
Scenario:
MCP-Proxy) allows your agent to interact with ThirdPartyAPI.MCP-Proxy uses its own single, static client_id when talking to ThirdPartyAPI's authorization server.MCP-Proxy to access ThirdPartyAPI on your behalf. During this, ThirdPartyAPI's auth server might set a cookie in your browser indicating your consent for MCP-Proxy's client_id.MCP-Proxy, but is designed to trick ThirdPartyAPI's auth server.ThirdPartyAPI's auth server sees your existing consent cookie for MCP-Proxy's client_id, it might skip asking for your consent again.MCP-Proxy might then be tricked into forwarding an authorization code (for ThirdPartyAPI) to the attacker, or an MCP authorization code that the attacker can use to impersonate you to MCP-Proxy.Mitigation (Primarily for MCP Server Developers):
MCP-Proxy itself should show a consent screen.CrewAI User Implication:
When connecting to remote MCP servers via Server-Sent Events (SSE) or Streamable HTTP, standard web security practices are essential.
DNS rebinding allows an attacker-controlled website to bypass the same-origin policy and make requests to servers on the user's local network (e.g., localhost) or intranet. This is particularly risky if you run an MCP server locally (e.g., for development) and an agent in a browser-like environment (though less common for typical CrewAI backend setups) or if the MCP server is on an internal network.
Mitigation Strategies for MCP Server Implementers:
Origin and Host Headers: MCP servers (especially SSE ones) should validate the Origin and/or Host HTTP headers to ensure requests are coming from expected domains/clients.localhost (127.0.0.1): When running MCP servers locally for development, bind them to 127.0.0.1 instead of 0.0.0.0. This prevents them from being accessible from other machines on the network.MCPServerAdapter will respect the scheme (http or https) provided in the URL.This is primarily a concern for MCP server developers but understanding it helps in choosing secure servers.
"Token passthrough" is when an MCP server accepts an access token from your CrewAI agent (which might be a token for a different service, say ServiceA) and simply passes it through to another downstream API (ServiceB) without proper validation. Specifically, ServiceB (or the MCP server itself) should only accept tokens that were explicitly issued for them (i.e., the 'audience' claim in the token matches the server/service).
Risks:
Mitigation (For MCP Server Developers):
CrewAI User Implication:
MCPServerAdapter (if any) have only the necessary permissions to access the required tools.../ sequences).If you are developing an MCP server that CrewAI agents might connect to, consider these best practices in addition to the points above:
Stdio) has only the minimum necessary permissions. Tools themselves should also operate with the least privilege required to perform their function.For more detailed information on MCP security, refer to the official documentation:
By understanding these security considerations and implementing best practices, you can safely leverage the power of MCP servers in your CrewAI projects. These are by no means exhaustive, but they cover the most common and critical security concerns. The threats will continue to evolve, so it's important to stay informed and adapt your security measures accordingly.