---
title: "Stdio"
description: "StdIO connector for MCP implementations API Documentation"
icon: "code"
github: "https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/client/connectors/stdio.py"
---

import {RandomGradientBackground} from "/snippets/gradient.jsx"

<Callout type="info" title="Source Code">
View the source code for this module on GitHub: <a href='https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/client/connectors/stdio.py' target='_blank' rel='noopener noreferrer'>https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/client/connectors/stdio.py</a>
</Callout>

StdIO connector for MCP implementations.

This module provides a connector for communicating with MCP implementations
through the standard input/output streams.

## StdioConnector

<div>
<RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
<div className="text-black">
<div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> StdioConnector</div>

Connector for MCP implementations using stdio transport.

    This connector uses the stdio transport to communicate with MCP implementations
    that are executed as child processes. It uses a connection manager to handle
    the proper lifecycle management of the stdio client.

</div>
</RandomGradientBackground>
```python
from mcp_use.client.connectors.stdio import StdioConnector
```

<Card type="info">
### `method` __init__

Initialize a new stdio connector.


**Parameters**
><ParamField body="command" type="str" default='npx' >   String value </ParamField>
><ParamField body="args" type="list[str] | None" default="None" >   List of items </ParamField>
><ParamField body="env" type="dict[str, str] | None" default="None" >   Optional environment variables. </ParamField>
><ParamField body="errlog" default="<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>" >   Stream to write error output to. </ParamField>
><ParamField body="sampling_callback" type="mcp.client.session.SamplingFnT | None" default="None" >   Optional callback to sample the client. </ParamField>
><ParamField body="elicitation_callback" type="mcp.client.session.ElicitationFnT | None" default="None" >   Optional callback to elicit the client. </ParamField>
><ParamField body="message_handler" type="mcp.client.session.MessageHandlerFnT | None" default="None" >   Optional callback to handle messages. </ParamField>
><ParamField body="logging_callback" type="mcp.client.session.LoggingFnT | None" default="None" >   Optional callback to handle log messages. </ParamField>
><ParamField body="middleware" type="list[mcp_use.client.middleware.middleware.Middleware] | None" default="None" >   Optional list of middleware. </ParamField>
><ParamField body="roots" type="list[mcp.types.Root] | None" default="None" >   Optional initial list of roots to advertise to the server. </ParamField>
><ParamField body="list_roots_callback" type="mcp.client.session.ListRootsFnT | None" default="None" >   Optional custom callback to handle roots/list requests. </ParamField>

**Signature**
```python wrap
def __init__(command: str = "npx", args: list[str] | None = None, env: dict[str, str] | None = None, errlog = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, sampling_callback: mcp.client.session.SamplingFnT | None = None, elicitation_callback: mcp.client.session.ElicitationFnT | None = None, message_handler: mcp.client.session.MessageHandlerFnT | None = None, logging_callback: mcp.client.session.LoggingFnT | None = None, middleware: list[mcp_use.client.middleware.middleware.Middleware] | None = None, roots: list[mcp.types.Root] | None = None, list_roots_callback: mcp.client.session.ListRootsFnT | None = None):
```

</Card>
</div>
