C# Семантическое ядро MCP Server ConnectionC#

Место общения программистов C#
Ответить
Anonymous
 C# Семантическое ядро MCP Server Connection

Сообщение Anonymous »

Я пытаюсь подключить удаленный сервер 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
Спасибо за вашу помощь.

Подробнее здесь: https://stackoverflow.com/questions/797 ... connection
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»