Я пытаюсь подключить удаленный сервер MCP с помощью семантического ядра. Насколько я понимаю, Semantic Cernel Post Bad Formatted JSON для MCP Server < /p>
Правильно: < /p>
{"jsonrpc":"2.0","id":1,"method": "tools/call", "params": {"name": "GetDestinationList", "arguments": {"searchRequest": {"searchValue": "Istanbul"}}}}
< /code>
Какой пост семантического ядра: < /p>
{"jsonrpc":"2.0","id":3,"method": "tools/call", "params": {"name": "GetDestinationList", "arguments": {"searchRequest":"{\"searchValue\":\"istanbul\"}"}}}
< /code>
SearchRequest должен быть объектом, но он продолжает отправлять его как строку. Проблема, так что Sementic ядро отправьте запрос правильно. < /p>
Вот мой код: < /p>
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using ModelContextProtocol.Client;
using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Configure Semantic Kernel with OpenAI
builder.Services.AddKernel().AddOpenAIChatCompletion(
modelId: "gpt-4.1",
apiKey: "xxxxxxxx"
);
// Register MainAgentManager
builder.Services.AddScoped();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
var kernel = app.Services.GetRequiredService();
SseClientTransport sseTransport = new(new() { Endpoint = new Uri("mcp.xxxxxx.com"), Name = "sseTransport"});
IMcpClient mcpClient = await McpClientFactory.CreateAsync(sseTransport);
// Suppress the diagnostic warning SKEXP0001 by explicitly disabling it for the specific line of code.
// This is a temporary measure to proceed with the current implementation while acknowledging that the API is subject to change.
#pragma warning disable SKEXP0001
kernel.Plugins.AddFromFunctions("keytool", tools.Select(aiFunction => aiFunction.AsKernelFunction()));
var executionSettings = new OpenAIPromptExecutionSettings
{
Temperature = 0,
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};
var prompt = "What is the destination id of istanbul";
var result = await kernel.InvokePromptAsync(prompt, new(executionSettings)).ConfigureAwait(false);
app.Run();
< /code>
Debug: Tool jsonschema < /p>
+ JsonSchema ValueKind = Object : "{
"type": "object",
"condition": "Get destinations by name as DestinationId and DestinationName",
"properties": {
"searchRequest": {
"type": "object",
"properties": {
"searchValue": {
"type": "string"
}
}
}
},
"required": [
"searchRequest"
]
}" System.Text.Json.JsonElement
Я пытаюсь подключить удаленный сервер MCP с помощью семантического ядра. Насколько я понимаю, Semantic Cernel Post Bad Formatted JSON для MCP Server < /p> Правильно: < /p> [code]{"jsonrpc":"2.0","id":1,"method": "tools/call", "params": {"name": "GetDestinationList", "arguments": {"searchRequest": {"searchValue": "Istanbul"}}}} < /code> Какой пост семантического ядра: < /p> {"jsonrpc":"2.0","id":3,"method": "tools/call", "params": {"name": "GetDestinationList", "arguments": {"searchRequest":"{\"searchValue\":\"istanbul\"}"}}} < /code> SearchRequest должен быть объектом, но он продолжает отправлять его как строку. Проблема, так что Sementic ядро отправьте запрос правильно. < /p> Вот мой код: < /p> using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; using ModelContextProtocol.Client; using System.Text.Json;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen();
// Suppress the diagnostic warning SKEXP0001 by explicitly disabling it for the specific line of code. // This is a temporary measure to proceed with the current implementation while acknowledging that the API is subject to change.