MCPEx.Transport.Stdio (MCPEx v0.1.0)

Implementation of the MCP transport over standard I/O.

This transport spawns an external process and communicates with it over standard input/output pipes. It handles encoding/decoding of messages and manages the lifecycle of the external process.

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the transport connection.

Sends a message to the process.

Starts a new stdio transport as a linked process.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

@spec close(pid()) :: :ok

Closes the transport connection.

Returns

  • :ok - The connection was closed successfully

send_message(pid, message)

@spec send_message(pid(), String.t()) :: :ok | {:error, term()}

Sends a message to the process.

Parameters

  • message - The message to send

Returns

  • :ok - The message was sent successfully
  • {:error, reason} - Failed to send the message

start_link(options)

@spec start_link(keyword()) :: {:ok, pid()} | {:error, term()}

Starts a new stdio transport as a linked process.

Options

  • :command - The command to execute (required)
  • :args - List of command arguments (default: [])
  • :cd - Working directory for the command (default: current directory)
  • :env - Environment variables for the command (default: current environment)

Returns

  • {:ok, pid} - The transport was started successfully
  • {:error, reason} - Failed to start the transport