Class BowireMcpChatClient

Namespace
Kuestenlogik.Bowire.Ai.Mcp
Assembly
Kuestenlogik.Bowire.Ai.Mcp.dll

Microsoft.Extensions.AI.IChatClient backed by the user's MCP host (#25 Phase 4 — MCP-client reversal). Bowire becomes the MCP client; the upstream MCP host carries the model affinity, auth, and rate-limiting the user has already configured for their other tools (Claude Desktop, Cursor, a corporate gateway).

public sealed class BowireMcpChatClient : IChatClient, IDisposable
Inheritance
BowireMcpChatClient
Implements
IChatClient
Inherited Members

Remarks

How chat lands as an MCP call. Standard MCP exposes tools rather than a chat-completion verb, so this adapter scans the upstream's tool list for the first one whose name reads as a chat / completion / sampling gateway — chat, completion / complete, llm, generate, sampling are all matched case-insensitively. Each GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken) call serialises the conversation into the tool's argument dictionary (messages + optional model) and parses the tool's text content as the assistant reply.

Endpoint shape. The Endpoint string is either an absolute HTTP(S) URL — taken as a Streamable-HTTP / SSE MCP endpoint — or a stdio: prefix followed by a command line spawned via stdio (stdio:claude mcp serve). Empty / malformed endpoints surface as an InvalidOperationException from the first chat call.

Connection lifecycle. The MCP client is established lazily on the first call and held for the lifetime of this instance. The BowireAiRuntime disposes the chat client on hot-swap and shutdown; that flows into DisposeAsync() here which closes the MCP client + transport. No connection pooling — Settings- UI saves rebuild the client.

Constructors

BowireMcpChatClient(string, string)

public BowireMcpChatClient(string endpoint, string modelId)

Parameters

endpoint string
modelId string

Methods

Dispose()

public void Dispose()

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)

public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<ChatMessage>
options ChatOptions
cancellationToken CancellationToken

Returns

Task<ChatResponse>

GetService(Type, object?)

public object? GetService(Type serviceType, object? serviceKey = null)

Parameters

serviceType Type
serviceKey object

Returns

object

GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)

public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<ChatMessage>
options ChatOptions
cancellationToken CancellationToken

Returns

IAsyncEnumerable<ChatResponseUpdate>