Method ForStdio
ForStdio(string, string)
Creates an MCP client for a stdio-based MCP server.
public static McpClient ForStdio(string command, string arguments = null)
Parameters
commandstringThe command to execute (e.g., "npx", "python", "uvx").
argumentsstringCommand-line arguments.
Returns
Examples
// Filesystem MCP server
using var client = McpClient.ForStdio("npx", "@modelcontextprotocol/server-filesystem /tmp");
// Python MCP server
using var client = McpClient.ForStdio("python", "-m my_mcp_server");
// UV-based Python server
using var client = McpClient.ForStdio("uvx", "mcp-server-git");
Exceptions
- ArgumentException
Thrown when
commandis null or whitespace.
ForStdio(StdioTransportOptions)
Creates an MCP client for a stdio-based MCP server with detailed options.
public static McpClient ForStdio(StdioTransportOptions options)
Parameters
optionsStdioTransportOptionsThe stdio transport configuration options.
Returns
Examples
var options = new StdioTransportOptions
{
Command = "python",
Arguments = "-m my_mcp_server",
WorkingDirectory = "/path/to/server",
Environment = new Dictionary<string, string>
{
["API_KEY"] = "your-key",
["DEBUG"] = "true"
},
StderrHandler = line => Console.WriteLine($"[Server] {line}")
};
using var client = McpClient.ForStdio(options);
Exceptions
- ArgumentNullException
Thrown when
optionsis null.