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
baseUrlstringThe base URL of the MCP server (e.g., "http://localhost:8080").
httpClientHttpClientOptional custom HttpClient instance.
additionalHeadersIDictionary<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
baseUrlUriThe base URL of the MCP server (e.g., "http://localhost:8080").
httpClientHttpClientOptional custom HttpClient instance.
additionalHeadersIDictionary<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
baseUrlstringThe base URL of the MCP server.
authTokenstringAuthentication token (will be sent as "Authorization: Bearer {token}").
httpClientHttpClientOptional 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
baseUrlUriThe base URL of the MCP server.
authTokenstringAuthentication token (will be sent as "Authorization: Bearer {token}").
httpClientHttpClientOptional 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
baseUrlstringThe base URL of the MCP server.
headersIDictionary<string, string>Custom HTTP headers.
httpClientHttpClientOptional 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
baseUrlUriThe base URL of the MCP server.
headersIDictionary<string, string>Custom HTTP headers.
httpClientHttpClientOptional 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
namestringThe name of the MCP server.
commandstringThe command to execute (e.g., "npx", "python", "node").
argumentsIEnumerable<string>Command-line arguments.
environmentVariablesIDictionary<string, string>Optional environment variables.
workingDirectorystringOptional working directory.
Returns
- IClientTransport
A configured StdioClientTransport.