MCP TypeScript SDK (V2) / @modelcontextprotocol/client / client/stdio
client/stdio
Classes
StdioClientTransport
Defined in: packages/client/src/client/stdio.ts:101
Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout.
This transport is only available in Node.js environments.
Implements
Constructors
Constructor
new StdioClientTransport(
server):StdioClientTransport
Defined in: packages/client/src/client/stdio.ts:111
Parameters
server
Returns
Properties
onclose?
optionalonclose?: () =>void
Defined in: packages/client/src/client/stdio.ts:107
Callback for when the connection is closed for any reason.
This should be invoked when close() is called as well.
Returns
void
Implementation of
onerror?
optionalonerror?: (error) =>void
Defined in: packages/client/src/client/stdio.ts:108
Callback for when an error occurs.
Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
Parameters
error
Error
Returns
void
Implementation of
onmessage?
optionalonmessage?: (message) =>void
Defined in: packages/client/src/client/stdio.ts:109
Callback for when a message (request or response) is received over the connection.
Includes the request and authInfo if the transport is authenticated.
The request can be used to get the original request information (headers, etc.)
Parameters
message
Returns
void
Implementation of
Accessors
pid
Get Signature
get pid():
number|null
Defined in: packages/client/src/client/stdio.ts:200
The child process pid spawned by this transport.
This is only available after the transport has been started.
Returns
number | null
stderr
Get Signature
get stderr():
Stream|null
Defined in: packages/client/src/client/stdio.ts:187
The stderr stream of the child process, if StdioServerParameters.stderr was set to "pipe" or "overlapped".
If stderr piping was requested, a PassThrough stream is returned immediately, allowing callers to attach listeners before the start method is invoked. This prevents loss of any early error output emitted by the child process.
Returns
Stream | null
Methods
close()
close():
Promise<void>
Defined in: packages/client/src/client/stdio.ts:219
Closes the connection.
Returns
Promise<void>
Implementation of
send()
send(
message):Promise<void>
Defined in: packages/client/src/client/stdio.ts:260
Sends a JSON-RPC message (request or response).
If present, relatedRequestId is used to indicate to the transport which incoming request to associate this outgoing message with.
Parameters
message
Returns
Promise<void>
Implementation of
start()
start():
Promise<void>
Defined in: packages/client/src/client/stdio.ts:122
Starts the server process and prepares to communicate with it.
Returns
Promise<void>
Implementation of
Type Aliases
StdioServerParameters
StdioServerParameters =
object
Defined in: packages/client/src/client/stdio.ts:10
Properties
args?
optionalargs?:string[]
Defined in: packages/client/src/client/stdio.ts:19
Command line arguments to pass to the executable.
command
command:
string
Defined in: packages/client/src/client/stdio.ts:14
The executable to run to start the server.
cwd?
optionalcwd?:string
Defined in: packages/client/src/client/stdio.ts:40
The working directory to use when spawning the process.
If not specified, the current working directory will be inherited.
env?
optionalenv?:Record<string,string>
Defined in: packages/client/src/client/stdio.ts:26
The environment to use when spawning the process.
If not specified, the result of getDefaultEnvironment will be used.
maxBufferSize?
optionalmaxBufferSize?:number
Defined in: packages/client/src/client/stdio.ts:48
Maximum size of the read buffer in bytes. If a single message exceeds this size the transport will emit an error and close.
Defaults to 10 MB.
stderr?
optionalstderr?:IOType|Stream|number
Defined in: packages/client/src/client/stdio.ts:33
How to handle stderr of the child process. This matches the semantics of Node's child_process.spawn.
The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr.
Variables
DEFAULT_INHERITED_ENV_VARS
constDEFAULT_INHERITED_ENV_VARS:string[]
Defined in: packages/client/src/client/stdio.ts:54
Environment variables to inherit by default, if an environment is not explicitly given.
Functions
getDefaultEnvironment()
getDefaultEnvironment():
Record<string,string>
Defined in: packages/client/src/client/stdio.ts:76
Returns a default environment object including only environment variables deemed safe to inherit.
Returns
Record<string, string>