Skip to content

Commit 65ef696

Browse files
committed
Add Xai backend support to McpService
1 parent 9d52e65 commit 65ef696

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/MaIN.Services/Services/McpService.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ private PromptExecutionSettings InitializeChatCompletions(IKernelBuilder kernelB
107107
ExtensionData = new Dictionary<string, object>{ ["max_tokens"] = 4096 }
108108
};
109109

110+
case BackendType.Xai:
111+
kernelBuilder.Services.AddOpenAIChatCompletion(
112+
modelId: model,
113+
apiKey: GetXaiKey() ?? throw new ArgumentNullException(nameof(GetXaiKey)),
114+
endpoint: new Uri("https://api.x.ai/v1"));
115+
return new OpenAIPromptExecutionSettings()
116+
{
117+
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(options: new() { RetainArgumentTypes = true })
118+
};
119+
110120
case BackendType.Self:
111121
throw new NotSupportedException("Self backend (local models) does not support MCP integration.");
112122

@@ -123,4 +133,6 @@ private PromptExecutionSettings InitializeChatCompletions(IKernelBuilder kernelB
123133
=> settings.GroqCloudKey ?? Environment.GetEnvironmentVariable("GROQ_API_KEY");
124134
string? GetAnthropicKey()
125135
=> settings.AnthropicKey ?? Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
136+
string? GetXaiKey()
137+
=> settings.XaiKey ?? Environment.GetEnvironmentVariable("XAI_API_KEY");
126138
}

0 commit comments

Comments
 (0)