Overview
The Stdio (Standard Input/Output) transport is designed for connectingMCPServerAdapter 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.
Key Concepts
- Local Execution: Stdio transport manages a locally running process for the MCP server.
StdioServerParameters: This class from themcplibrary is used to configure the command, arguments, and environment variables for launching the Stdio server.
Connecting via Stdio
You can connect to an Stdio-based MCP server using two main approaches for managing the connection lifecycle:1. Fully Managed Connection (Recommended)
Using a Python context manager (with statement) is the recommended approach. It automatically handles starting the MCP server process and stopping it when the context is exited.
2. Manual Connection Lifecycle
If you need finer-grained control over when the Stdio MCP server process is started and stopped, you can manage theMCPServerAdapter lifecycle manually.
You MUST call
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).