feat:switch official sdk ModelContextProtocol

mcpdotnet now is mcp offical sdk
This commit is contained in:
geffzhang 2025-03-21 13:14:19 +08:00
parent 58e3e7fba7
commit 7a9d7ffc75
20 changed files with 47 additions and 58 deletions

View file

@ -131,10 +131,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrast
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}"
EndProject 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{8D2AD45F-836A-516F-DE6A-71443CEBB18A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol", "..\Ai4c\mcpcsharp-sdk\src\ModelContextProtocol\ModelContextProtocol.csproj", "{13E4F06A-D4F2-49FA-E979-DE3937137579}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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|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.ActiveCfg = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.Build.0 = 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.ActiveCfg = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.Build.0 = 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 {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|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.ActiveCfg = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -622,8 +622,8 @@ Global
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA} {AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749} {684781D5-3DD4-6A0B-B53F-0A362CD6BB0C} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{781F1465-365C-0F22-1775-25025DAFA4C7} = {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} {8D2AD45F-836A-516F-DE6A-71443CEBB18A} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
{13E4F06A-D4F2-49FA-E979-DE3937137579} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -19,7 +19,7 @@ public enum AgentField
Sample, Sample,
LlmConfig, LlmConfig,
Utility, Utility,
Acp, McpTool,
KnowledgeBase, KnowledgeBase,
Rule, Rule,
MaxMessageCount MaxMessageCount

View file

@ -60,7 +60,7 @@ namespace BotSharp.Core.Repository
case AgentField.Utility: case AgentField.Utility:
UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities); UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities);
break; break;
case AgentField.Acp: case AgentField.McpTool:
UpdateAgentMcpTools(agent.Id, agent.McpTools); UpdateAgentMcpTools(agent.Id, agent.McpTools);
break; break;
case AgentField.KnowledgeBase: case AgentField.KnowledgeBase:

View file

@ -1,9 +1,8 @@
using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Functions.Models;
using McpDotNet.Protocol.Types; using ModelContextProtocol.Protocol.Types;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
namespace BotSharp.Core.MCP; namespace BotSharp.Core.MCP;
@ -16,19 +15,19 @@ internal static class AIFunctionUtilities
throw new ArgumentNullException(nameof(tool)); throw new ArgumentNullException(nameof(tool));
} }
var properties = tool.InputSchema?.Properties; var properties = tool.InputSchema.GetProperty("properties");
var required = tool.InputSchema?.Required ?? new List<string>(); var required = tool.InputSchema.GetProperty("required");
FunctionDef funDef = new FunctionDef FunctionDef funDef = new FunctionDef
{ {
Name = tool.Name, Name = tool.Name,
Description = tool.Description?? string.Empty, Description = tool.Description ?? string.Empty,
Type = "function", Type = "function",
Parameters = new FunctionParametersDef Parameters = new FunctionParametersDef
{ {
Type = "object", Type = "object",
Properties = properties != null ? JsonSerializer.SerializeToDocument(properties) : JsonDocument.Parse("{}"), Properties = JsonDocument.Parse(properties.GetRawText()),
Required = required Required = JsonSerializer.Deserialize<List<string>>(required.GetRawText())
} }
}; };

View file

@ -13,7 +13,7 @@
</ItemGroup> </ItemGroup>
<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" /> <ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -1,12 +1,10 @@
using BotSharp.Abstraction.Agents; using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Conversations.Models; using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Functions; using BotSharp.Abstraction.Functions;
using BotSharp.Abstraction.Utilities; using BotSharp.Abstraction.Utilities;
using McpDotNet.Client;
using McpDotNet.Protocol.Types;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol.Types;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View file

@ -1,17 +1,11 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Agents.Settings;
using BotSharp.Abstraction.Agents; using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Conversations.Models; using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Infrastructures.Enums;
using BotSharp.Abstraction.Translation;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks;
namespace BotSharp.MCP.Hooks; namespace BotSharp.MCP.Hooks;
@ -19,7 +13,6 @@ public class MCPResponseHook : ConversationHookBase
{ {
private readonly IServiceProvider _services; private readonly IServiceProvider _services;
private readonly IConversationStateService _states; private readonly IConversationStateService _states;
private const string AIAssistant = BuiltInAgentId.AIAssistant;
public MCPResponseHook(IServiceProvider services, public MCPResponseHook(IServiceProvider services,
IConversationStateService states) IConversationStateService states)

View file

@ -6,8 +6,8 @@ using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Functions.Models;
using BotSharp.Core.Mcp; using BotSharp.Core.Mcp;
using BotSharp.Core.MCP; using BotSharp.Core.MCP;
using McpDotNet.Client;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ModelContextProtocol.Client;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View file

@ -1,6 +1,6 @@
using BotSharp.Core.Mcp.Settings; using BotSharp.Core.Mcp.Settings;
using McpDotNet.Client;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ModelContextProtocol.Client;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;

View file

@ -5,12 +5,11 @@ using BotSharp.Abstraction.Plugins;
using BotSharp.Core.Mcp.Functions; using BotSharp.Core.Mcp.Functions;
using BotSharp.Core.Mcp.Settings; using BotSharp.Core.Mcp.Settings;
using BotSharp.MCP.Hooks; using BotSharp.MCP.Hooks;
using McpDotNet.Client;
using McpDotNet.Protocol.Types;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using ModelContextProtocol.Client;
using ModelContextProtocol.Configuration;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -44,7 +43,7 @@ public class McpPlugin : IBotSharpPlugin
services.AddScoped<IConversationHook, MCPResponseHook>(); 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 client = await clientManager.GetMcpClientAsync(server.Id);
var tools = await client.ListToolsAsync().ToListAsync(); var tools = await client.ListToolsAsync().ToListAsync();

View file

@ -1,5 +1,5 @@
using McpDotNet.Client; using ModelContextProtocol.Client;
using McpDotNet.Configuration; using ModelContextProtocol.Configuration;
using System.Collections.Generic; using System.Collections.Generic;
namespace BotSharp.Core.Mcp.Settings; namespace BotSharp.Core.Mcp.Settings;

View file

@ -61,7 +61,7 @@ public partial class MongoRepository
case AgentField.Utility: case AgentField.Utility:
UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities); UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities);
break; break;
case AgentField.Acp: case AgentField.McpTool:
UpdateAgentMcps(agent.Id, agent.McpTools); UpdateAgentMcps(agent.Id, agent.McpTools);
break; break;
case AgentField.KnowledgeBase: case AgentField.KnowledgeBase:

View file

@ -14,6 +14,6 @@
<PackageReference Include="System.Net.ServerSentEvents" /> <PackageReference Include="System.Net.ServerSentEvents" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\mcpdotnet\src\mcpdotnet\mcpdotnet.csproj" /> <ProjectReference Include="..\..\..\Ai4c\mcpcsharp-sdk\src\ModelContextProtocol\ModelContextProtocol.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -1,7 +1,7 @@
using McpDotNet.Protocol.Messages;
using McpDotNet.Server;
using McpDotNet.Utils.Json;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using ModelContextProtocol.Protocol.Messages;
using ModelContextProtocol.Server;
using ModelContextProtocol.Utils.Json;
namespace BotSharp.PizzaBot.MCPServer; namespace BotSharp.PizzaBot.MCPServer;
@ -45,7 +45,7 @@ public static class McpEndpointRouteBuilderExtensions
return; 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) if (message is null)
{ {
await Results.BadRequest("No message in request body.").ExecuteAsync(context); await Results.BadRequest("No message in request body.").ExecuteAsync(context);

View file

@ -1,5 +1,5 @@
using BotSharp.PizzaBot.MCPServer; using BotSharp.PizzaBot.MCPServer;
using McpDotNet; using ModelContextProtocol;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMcpServer().WithTools(); builder.Services.AddMcpServer().WithTools();

View file

@ -1,6 +1,6 @@
using McpDotNet.Protocol.Messages; using ModelContextProtocol.Protocol.Messages;
using McpDotNet.Protocol.Transport; using ModelContextProtocol.Protocol.Transport;
using McpDotNet.Utils.Json; using ModelContextProtocol.Utils.Json;
using System.Buffers; using System.Buffers;
using System.Net.ServerSentEvents; using System.Net.ServerSentEvents;
using System.Text.Json; using System.Text.Json;
@ -28,7 +28,7 @@ public class SseServerStreamTransport(Stream sseResponseStream) : ITransport
return; 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, // The very first SSE event isn't really an IJsonRpcMessage, but there's no API to write a single item of a different type,

View file

@ -1,4 +1,4 @@
using McpDotNet.Server; using ModelContextProtocol.Server;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;

View file

@ -1,6 +1,6 @@
using McpDotNet.Server; using ModelContextProtocol.Server;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Dynamic; using System.Dynamic;
using System.Text.Json; using System.Text.Json;

View file

@ -1,4 +1,4 @@
using McpDotNet.Server; using ModelContextProtocol.Server;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;