Table of Contents

Class McpTransportFactory

Namespace
GenerativeAI.Tools.Mcp
Assembly
GenerativeAI.Tools.dll

Factory class for creating MCP client transports with common configurations. Supports stdio, HTTP/SSE, and other transport protocols.

public static class McpTransportFactory
Inheritance
McpTransportFactory
Inherited Members

Methods

CreateHttpTransport(string, HttpClient?, IDictionary<string, string>?)

Creates an HTTP/SSE transport for connecting to a remote MCP server via HTTP.

public static IClientTransport CreateHttpTransport(string baseUrl, HttpClient? httpClient = null, IDictionary<string, string>? additionalHeaders = null)

Parameters

baseUrl string

The base URL of the MCP server (e.g., "http://localhost:8080").

httpClient HttpClient

Optional custom HttpClient instance.

additionalHeaders IDictionary<string, string>

Optional additional HTTP headers.

Returns

IClientTransport

A configured HttpClientTransport.

CreateHttpTransport(Uri, HttpClient?, IDictionary<string, string>?)

Creates an HTTP/SSE transport for connecting to a remote MCP server via HTTP.

public static IClientTransport CreateHttpTransport(Uri baseUrl, HttpClient? httpClient = null, IDictionary<string, string>? additionalHeaders = null)

Parameters

baseUrl Uri

The base URL of the MCP server (e.g., "http://localhost:8080").

httpClient HttpClient

Optional custom HttpClient instance.

additionalHeaders IDictionary<string, string>

Optional additional HTTP headers.

Returns

IClientTransport

A configured HttpClientTransport.

CreateHttpTransportWithAuth(string, string, HttpClient?)

Creates an HTTP/SSE transport with authentication headers.

public static IClientTransport CreateHttpTransportWithAuth(string baseUrl, string authToken, HttpClient? httpClient = null)

Parameters

baseUrl string

The base URL of the MCP server.

authToken string

Authentication token (will be sent as "Authorization: Bearer {token}").

httpClient HttpClient

Optional custom HttpClient instance.

Returns

IClientTransport

A configured HttpClientTransport with authentication.

CreateHttpTransportWithAuth(Uri, string, HttpClient?)

Creates an HTTP/SSE transport with authentication headers.

public static IClientTransport CreateHttpTransportWithAuth(Uri baseUrl, string authToken, HttpClient? httpClient = null)

Parameters

baseUrl Uri

The base URL of the MCP server.

authToken string

Authentication token (will be sent as "Authorization: Bearer {token}").

httpClient HttpClient

Optional custom HttpClient instance.

Returns

IClientTransport

A configured HttpClientTransport with authentication.

CreateHttpTransportWithHeaders(string, IDictionary<string, string>, HttpClient?)

Creates an HTTP/SSE transport with custom headers.

public static IClientTransport CreateHttpTransportWithHeaders(string baseUrl, IDictionary<string, string> headers, HttpClient? httpClient = null)

Parameters

baseUrl string

The base URL of the MCP server.

headers IDictionary<string, string>

Custom HTTP headers.

httpClient HttpClient

Optional custom HttpClient instance.

Returns

IClientTransport

A configured HttpClientTransport with custom headers.

CreateHttpTransportWithHeaders(Uri, IDictionary<string, string>, HttpClient?)

Creates an HTTP/SSE transport with custom headers.

public static IClientTransport CreateHttpTransportWithHeaders(Uri baseUrl, IDictionary<string, string> headers, HttpClient? httpClient = null)

Parameters

baseUrl Uri

The base URL of the MCP server.

headers IDictionary<string, string>

Custom HTTP headers.

httpClient HttpClient

Optional custom HttpClient instance.

Returns

IClientTransport

A configured HttpClientTransport with custom headers.

CreateStdioTransport(string, string, IEnumerable<string>, IDictionary<string, string>?, string?)

Creates a stdio transport for launching an MCP server as a subprocess.

public static IClientTransport CreateStdioTransport(string name, string command, IEnumerable<string> arguments, IDictionary<string, string>? environmentVariables = null, string? workingDirectory = null)

Parameters

name string

The name of the MCP server.

command string

The command to execute (e.g., "npx", "python", "node").

arguments IEnumerable<string>

Command-line arguments.

environmentVariables IDictionary<string, string>

Optional environment variables.

workingDirectory string

Optional working directory.

Returns

IClientTransport

A configured StdioClientTransport.