feat:switch official sdk ModelContextProtocol
mcpdotnet now is mcp offical sdk
This commit is contained in:
parent
58e3e7fba7
commit
7a9d7ffc75
22
BotSharp.sln
22
BotSharp.sln
|
|
@ -131,10 +131,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrast
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mcpdotnet", "..\mcpdotnet\src\mcpdotnet\mcpdotnet.csproj", "{32D455C9-C7CF-928B-F878-8EAF0198328E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{8D2AD45F-836A-516F-DE6A-71443CEBB18A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol", "..\Ai4c\mcpcsharp-sdk\src\ModelContextProtocol\ModelContextProtocol.csproj", "{13E4F06A-D4F2-49FA-E979-DE3937137579}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -543,14 +543,6 @@ Global
|
|||
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.Build.0 = Release|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E}.Release|x64.Build.0 = Release|Any CPU
|
||||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -559,6 +551,14 @@ Global
|
|||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -622,8 +622,8 @@ Global
|
|||
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
|
||||
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
||||
{781F1465-365C-0F22-1775-25025DAFA4C7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
||||
{32D455C9-C7CF-928B-F878-8EAF0198328E} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
|
||||
{8D2AD45F-836A-516F-DE6A-71443CEBB18A} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
|
||||
{13E4F06A-D4F2-49FA-E979-DE3937137579} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public enum AgentField
|
|||
Sample,
|
||||
LlmConfig,
|
||||
Utility,
|
||||
Acp,
|
||||
McpTool,
|
||||
KnowledgeBase,
|
||||
Rule,
|
||||
MaxMessageCount
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ public partial class AgentService
|
|||
var samples = GetSamplesFromFile(dir);
|
||||
return agent.SetInstruction(defaultInstruction)
|
||||
.SetChannelInstructions(channelInstructions)
|
||||
.SetTemplates(templates)
|
||||
.SetTemplates(templates)
|
||||
.SetFunctions(functions)
|
||||
.SetResponses(responses)
|
||||
.SetSamples(samples);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace BotSharp.Core.Repository
|
|||
case AgentField.Utility:
|
||||
UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities);
|
||||
break;
|
||||
case AgentField.Acp:
|
||||
case AgentField.McpTool:
|
||||
UpdateAgentMcpTools(agent.Id, agent.McpTools);
|
||||
break;
|
||||
case AgentField.KnowledgeBase:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
using BotSharp.Abstraction.Functions.Models;
|
||||
using McpDotNet.Protocol.Types;
|
||||
using ModelContextProtocol.Protocol.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BotSharp.Core.MCP;
|
||||
|
||||
|
|
@ -16,19 +15,19 @@ internal static class AIFunctionUtilities
|
|||
throw new ArgumentNullException(nameof(tool));
|
||||
}
|
||||
|
||||
var properties = tool.InputSchema?.Properties;
|
||||
var required = tool.InputSchema?.Required ?? new List<string>();
|
||||
var properties = tool.InputSchema.GetProperty("properties");
|
||||
var required = tool.InputSchema.GetProperty("required");
|
||||
|
||||
FunctionDef funDef = new FunctionDef
|
||||
{
|
||||
Name = tool.Name,
|
||||
Description = tool.Description?? string.Empty,
|
||||
Description = tool.Description ?? string.Empty,
|
||||
Type = "function",
|
||||
Parameters = new FunctionParametersDef
|
||||
{
|
||||
Type = "object",
|
||||
Properties = properties != null ? JsonSerializer.SerializeToDocument(properties) : JsonDocument.Parse("{}"),
|
||||
Required = required
|
||||
Properties = JsonDocument.Parse(properties.GetRawText()),
|
||||
Required = JsonSerializer.Deserialize<List<string>>(required.GetRawText())
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\mcpdotnet\src\mcpdotnet\mcpdotnet.csproj" />
|
||||
<ProjectReference Include="..\..\..\..\Ai4c\mcpcsharp-sdk\src\ModelContextProtocol\ModelContextProtocol.csproj" />
|
||||
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
using BotSharp.Abstraction.Agents;
|
||||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Functions;
|
||||
using BotSharp.Abstraction.Utilities;
|
||||
using McpDotNet.Client;
|
||||
using McpDotNet.Protocol.Types;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ModelContextProtocol.Client;
|
||||
using ModelContextProtocol.Protocol.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
|
|||
|
|
@ -1,25 +1,18 @@
|
|||
using BotSharp.Abstraction.Agents.Enums;
|
||||
using BotSharp.Abstraction.Agents.Settings;
|
||||
using BotSharp.Abstraction.Agents;
|
||||
using BotSharp.Abstraction.Conversations;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Infrastructures.Enums;
|
||||
using BotSharp.Abstraction.Translation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BotSharp.MCP.Hooks;
|
||||
|
||||
public class MCPResponseHook : ConversationHookBase
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IConversationStateService _states;
|
||||
private const string AIAssistant = BuiltInAgentId.AIAssistant;
|
||||
private readonly IConversationStateService _states;
|
||||
|
||||
public MCPResponseHook(IServiceProvider services,
|
||||
IConversationStateService states)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ using BotSharp.Abstraction.Conversations;
|
|||
using BotSharp.Abstraction.Functions.Models;
|
||||
using BotSharp.Core.Mcp;
|
||||
using BotSharp.Core.MCP;
|
||||
using McpDotNet.Client;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModelContextProtocol.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using BotSharp.Core.Mcp.Settings;
|
||||
using McpDotNet.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ModelContextProtocol.Client;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@ using BotSharp.Abstraction.Plugins;
|
|||
using BotSharp.Core.Mcp.Functions;
|
||||
using BotSharp.Core.Mcp.Settings;
|
||||
using BotSharp.MCP.Hooks;
|
||||
using McpDotNet.Client;
|
||||
using McpDotNet.Protocol.Types;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ModelContextProtocol.Client;
|
||||
using ModelContextProtocol.Configuration;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ public class McpPlugin : IBotSharpPlugin
|
|||
services.AddScoped<IConversationHook, MCPResponseHook>();
|
||||
}
|
||||
|
||||
private async Task RegisterFunctionCall(IServiceCollection services, McpDotNet.Configuration.McpServerConfig server)
|
||||
private async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server)
|
||||
{
|
||||
var client = await clientManager.GetMcpClientAsync(server.Id);
|
||||
var tools = await client.ListToolsAsync().ToListAsync();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using McpDotNet.Client;
|
||||
using McpDotNet.Configuration;
|
||||
using ModelContextProtocol.Client;
|
||||
using ModelContextProtocol.Configuration;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BotSharp.Core.Mcp.Settings;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public partial class MongoRepository
|
|||
case AgentField.Utility:
|
||||
UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities);
|
||||
break;
|
||||
case AgentField.Acp:
|
||||
case AgentField.McpTool:
|
||||
UpdateAgentMcps(agent.Id, agent.McpTools);
|
||||
break;
|
||||
case AgentField.KnowledgeBase:
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@
|
|||
<PackageReference Include="System.Net.ServerSentEvents" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\mcpdotnet\src\mcpdotnet\mcpdotnet.csproj" />
|
||||
<ProjectReference Include="..\..\..\Ai4c\mcpcsharp-sdk\src\ModelContextProtocol\ModelContextProtocol.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using McpDotNet.Protocol.Messages;
|
||||
using McpDotNet.Server;
|
||||
using McpDotNet.Utils.Json;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ModelContextProtocol.Protocol.Messages;
|
||||
using ModelContextProtocol.Server;
|
||||
using ModelContextProtocol.Utils.Json;
|
||||
|
||||
namespace BotSharp.PizzaBot.MCPServer;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ public static class McpEndpointRouteBuilderExtensions
|
|||
return;
|
||||
}
|
||||
|
||||
var message = await context.Request.ReadFromJsonAsync<IJsonRpcMessage>(JsonSerializerOptionsExtensions.DefaultOptions, context.RequestAborted);
|
||||
var message = await context.Request.ReadFromJsonAsync<IJsonRpcMessage>(McpJsonUtilities.DefaultOptions, context.RequestAborted);
|
||||
if (message is null)
|
||||
{
|
||||
await Results.BadRequest("No message in request body.").ExecuteAsync(context);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using BotSharp.PizzaBot.MCPServer;
|
||||
using McpDotNet;
|
||||
using ModelContextProtocol;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddMcpServer().WithTools();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using McpDotNet.Protocol.Messages;
|
||||
using McpDotNet.Protocol.Transport;
|
||||
using McpDotNet.Utils.Json;
|
||||
using ModelContextProtocol.Protocol.Messages;
|
||||
using ModelContextProtocol.Protocol.Transport;
|
||||
using ModelContextProtocol.Utils.Json;
|
||||
using System.Buffers;
|
||||
using System.Net.ServerSentEvents;
|
||||
using System.Text.Json;
|
||||
|
|
@ -28,7 +28,7 @@ public class SseServerStreamTransport(Stream sseResponseStream) : ITransport
|
|||
return;
|
||||
}
|
||||
|
||||
JsonSerializer.Serialize(GetUtf8JsonWriter(writer), item.Data, JsonSerializerOptionsExtensions.DefaultOptions);
|
||||
JsonSerializer.Serialize(GetUtf8JsonWriter(writer), item.Data, McpJsonUtilities.DefaultOptions);
|
||||
}
|
||||
|
||||
// The very first SSE event isn't really an IJsonRpcMessage, but there's no API to write a single item of a different type,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using McpDotNet.Server;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using McpDotNet.Server;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Dynamic;
|
||||
using System.Text.Json;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using McpDotNet.Server;
|
||||
using ModelContextProtocol.Server;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue