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
Methods
Dispose()
public void Dispose()
DisposeAsync()
public ValueTask DisposeAsync()
Returns
GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)
Sends chat messages and returns the response.
public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messagesIEnumerable<ChatMessage>The sequence of chat messages to send.
optionsChatOptionsThe chat options with which to configure the request.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- Task<ChatResponse>
The response messages generated by the client.
Exceptions
- ArgumentNullException
messagesis null.
GetService(Type, object?)
Asks the Microsoft.Extensions.AI.IChatClient for an object of the specified type serviceType.
public object? GetService(Type serviceType, object? serviceKey = null)
Parameters
serviceTypeTypeThe type of object being requested.
serviceKeyobjectAn optional key that can be used to help identify the target service.
Returns
Remarks
The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the Microsoft.Extensions.AI.IChatClient, including itself or any services it might be wrapping. For example, to access the Microsoft.Extensions.AI.ChatClientMetadata for the instance, GetService(Type, object) may be used to request it.
Exceptions
- ArgumentNullException
serviceTypeis null.
GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)
Sends chat messages and streams the response.
public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messagesIEnumerable<ChatMessage>The sequence of chat messages to send.
optionsChatOptionsThe chat options with which to configure the request.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- IAsyncEnumerable<ChatResponseUpdate>
The response messages generated by the client.
Exceptions
- ArgumentNullException
messagesis null.