Class McpServiceExtensions
Extension methods that integrate MCP servers with AIService.
public static class McpServiceExtensions
- Inheritance
-
McpServiceExtensions
- Inherited Members
Methods
WithMcpServerAsync(AIService, IMcpTransport, Func<string, bool>?, string?, CancellationToken)
Connects to an MCP server using a pre-built transport, discovers its tools, and registers them on this service.
public static Task<McpConnection> WithMcpServerAsync(this AIService service, IMcpTransport transport, Func<string, bool>? toolFilter = null, string? namePrefix = null, CancellationToken cancellationToken = default)
Parameters
serviceAIServiceThe AI service to register tools on.
transportIMcpTransportA ready-to-use MCP transport.
toolFilterFunc<string, bool>Optional filter โ return true for tool names to include.
namePrefixstringOptional prefix to prepend to each tool name.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<McpConnection>
The initialized McpConnection. Caller must dispose it when done.
WithMcpServerAsync(AIService, string, string?, Func<string, bool>?, string?, string?, Dictionary<string, string>?, CancellationToken)
Connects to an MCP server via stdio transport, discovers its tools, and registers them as FunctionDefinitions on this service. Dispose the returned McpConnection to shut down the server process.
public static Task<McpConnection> WithMcpServerAsync(this AIService service, string command, string? args = null, Func<string, bool>? toolFilter = null, string? namePrefix = null, string? workingDirectory = null, Dictionary<string, string>? environmentVariables = null, CancellationToken cancellationToken = default)
Parameters
serviceAIServiceThe AI service to register tools on.
commandstringThe executable to launch (e.g., "npx", "python", "node").
argsstringArguments to pass to the executable.
toolFilterFunc<string, bool>Optional filter โ return true for tool names to include.
namePrefixstringOptional prefix to prepend to each tool name.
workingDirectorystringOptional working directory for the server process.
environmentVariablesDictionary<string, string>Optional environment variables for the server process.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<McpConnection>
The initialized McpConnection. Caller must dispose it when done.