Learn how to connect CrewAI to local MCP servers using the Stdio (Standard Input/Output) transport mechanism.
MCPServerAdapter
to local MCP servers that communicate over their standard input and output streams. This is typically used when the MCP server is a script or executable running on the same machine as your CrewAI application.
StdioServerParameters
: This class from the mcp
library is used to configure the command, arguments, and environment variables for launching the Stdio server.with
statement) is the recommended approach. It automatically handles starting the MCP server process and stopping it when the context is exited.
MCPServerAdapter
lifecycle manually.
mcp_server_adapter.stop()
to ensure the server process is terminated and resources are released. Using a try...finally
block is highly recommended.env
parameter in StdioServerParameters
can
be used to set environment variables for the server process, which can be useful for configuring its behavior or providing necessary paths (like PYTHONPATH
).