Skip to content

Commit 6ac8732

Browse files
authored
Merge pull request #5 from Ai4c-AI/mcp
merge mcp into master
2 parents 994da49 + 1a1f56f commit 6ac8732

File tree

28 files changed

+644
-292
lines changed

28 files changed

+644
-292
lines changed

BotSharp.sln

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Rules", "src\
127127
EndProject
128128
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}"
129129
EndProject
130-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj", "{8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}"
130+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj", "{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}"
131131
EndProject
132-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{AD91B4ED-0623-4710-913E-6D7C893E76EF}"
132+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}"
133+
EndProject
134+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{8D2AD45F-836A-516F-DE6A-71443CEBB18A}"
133135
EndProject
134136
Global
135137
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -523,6 +525,30 @@ Global
523525
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU
524526
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU
525527
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = Release|Any CPU
528+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
529+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
530+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|x64.ActiveCfg = Debug|Any CPU
531+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|x64.Build.0 = Debug|Any CPU
532+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
533+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|Any CPU.Build.0 = Release|Any CPU
534+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|x64.ActiveCfg = Release|Any CPU
535+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|x64.Build.0 = Release|Any CPU
536+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
537+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
538+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|x64.ActiveCfg = Debug|Any CPU
539+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|x64.Build.0 = Debug|Any CPU
540+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
541+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.Build.0 = Release|Any CPU
542+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.ActiveCfg = Release|Any CPU
543+
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.Build.0 = Release|Any CPU
544+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
545+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
546+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.ActiveCfg = Debug|Any CPU
547+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.Build.0 = Debug|Any CPU
548+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.ActiveCfg = Release|Any CPU
549+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.Build.0 = Release|Any CPU
550+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.ActiveCfg = Release|Any CPU
551+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.Build.0 = Release|Any CPU
526552
EndGlobalSection
527553
GlobalSection(SolutionProperties) = preSolution
528554
HideSolutionNode = FALSE
@@ -584,6 +610,9 @@ Global
584610
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
585611
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
586612
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
613+
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
614+
{781F1465-365C-0F22-1775-25025DAFA4C7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
615+
{8D2AD45F-836A-516F-DE6A-71443CEBB18A} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
587616
EndGlobalSection
588617
GlobalSection(ExtensibilityGlobals) = postSolution
589618
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

Directory.Packages.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageVersion Include="EntityFramework" Version="6.4.4" />
9+
<PackageVersion Include="mcpdotnet" Version="1.1.0.1" />
910
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="$(AspNetCoreVersion)" />
1011
<PackageVersion Include="Microsoft.AspNetCore.StaticFiles" Version="$(AspNetCoreVersion)" />
1112
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
1213
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
1314
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
1415
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.1" />
1516
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
17+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
1618
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
1719
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
1820
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
1921
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.0" />
22+
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.0-preview.1.25080.5" />
2023
<PackageVersion Include="System.Memory.Data" Version="8.0.0" />
2124
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
2225
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
26+
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
2327
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
2428
<PackageVersion Include="Rougamo.Fody" Version="4.0.4" />
2529
<PackageVersion Include="Aspects.Cache" Version="2.0.4" />
@@ -106,6 +110,8 @@
106110
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
107111
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
108112
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
113+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
114+
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.1.25171.12" />
109115
</ItemGroup>
110116
<ItemGroup>
111117
<PackageVersion Include="BotSharp.Core" Version="$(BotSharpVersion)" />

src/BotSharp.AppHost/BotSharp.AppHost.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<ProjectReference Include="..\..\tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj" />
1819
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
1920
<ProjectReference Include="..\WebStarter\WebStarter.csproj" />
2021
</ItemGroup>

src/BotSharp.AppHost/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var apiService = builder.AddProject<Projects.WebStarter>("apiservice")
44
.WithExternalHttpEndpoints();
5+
var mcpService = builder.AddProject<Projects.BotSharp_PizzaBot_MCPServer>("mcpservice")
6+
.WithExternalHttpEndpoints();
57

68
builder.AddNpmApp("BotSharpUI", "../../../BotSharp-UI")
79
.WithReference(apiService)

src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum AgentField
1919
Sample,
2020
LlmConfig,
2121
Utility,
22-
Acp,
22+
McpTool,
2323
KnowledgeBase,
2424
Rule,
2525
MaxMessageCount

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public async Task<string> PatchAgentTemplate(Agent agent)
197197
var samples = GetSamplesFromFile(dir);
198198
return agent.SetInstruction(defaultInstruction)
199199
.SetChannelInstructions(channelInstructions)
200-
.SetTemplates(templates)
200+
.SetTemplates(templates)
201201
.SetFunctions(functions)
202202
.SetResponses(responses)
203203
.SetSamples(samples);

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void UpdateAgent(Agent agent, AgentField field)
6060
case AgentField.Utility:
6161
UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities);
6262
break;
63-
case AgentField.Acp:
63+
case AgentField.McpTool:
6464
UpdateAgentMcpTools(agent.Id, agent.McpTools);
6565
break;
6666
case AgentField.KnowledgeBase:

src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using BotSharp.Abstraction.Functions.Models;
2-
using McpDotNet.Protocol.Types;
2+
using ModelContextProtocol.Protocol.Types;
33
using System;
44
using System.Collections.Generic;
55
using System.Text.Json;
6-
using System.Text.Json.Serialization;
76

87
namespace BotSharp.Core.MCP;
98

@@ -16,19 +15,19 @@ public static FunctionDef MapToFunctionDef(Tool tool)
1615
throw new ArgumentNullException(nameof(tool));
1716
}
1817

19-
var properties = tool.InputSchema?.Properties;
20-
var required = tool.InputSchema?.Required ?? new List<string>();
18+
var properties = tool.InputSchema.GetProperty("properties");
19+
var required = tool.InputSchema.GetProperty("required");
2120

2221
FunctionDef funDef = new FunctionDef
2322
{
2423
Name = tool.Name,
25-
Description = tool.Description?? string.Empty,
24+
Description = tool.Description ?? string.Empty,
2625
Type = "function",
2726
Parameters = new FunctionParametersDef
2827
{
2928
Type = "object",
30-
Properties = properties != null ? JsonSerializer.SerializeToDocument(properties) : JsonDocument.Parse("{}"),
31-
Required = required
29+
Properties = JsonDocument.Parse(properties.GetRawText()),
30+
Required = JsonSerializer.Deserialize<List<string>>(required.GetRawText())
3231
}
3332
};
3433

src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="mcpdotnet" Version="1.1.0.1" />
12+
<PackageReference Include="ModelContextProtocol" />
13+
<PackageReference Include="System.Linq.AsyncEnumerable" />
1314
</ItemGroup>
1415

1516
<ItemGroup>

src/Infrastructure/BotSharp.MCP/Functions/McpToolFunction.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using BotSharp.Abstraction.Agents;
2-
using BotSharp.Abstraction.Agents.Models;
32
using BotSharp.Abstraction.Conversations.Models;
43
using BotSharp.Abstraction.Functions;
5-
using McpDotNet.Client;
6-
using McpDotNet.Protocol.Types;
4+
using BotSharp.Abstraction.Utilities;
75
using Microsoft.Extensions.DependencyInjection;
8-
using Microsoft.Extensions.Logging;
6+
using ModelContextProtocol.Client;
7+
using ModelContextProtocol.Protocol.Types;
98
using System;
109
using System.Collections.Generic;
1110
using System.Linq;
@@ -38,7 +37,7 @@ public async Task<bool> Execute(RoleDialogModel message)
3837
var agent = await agentService.LoadAgent(currentAgentId);
3938
var serverId = agent.McpTools.Where(t => t.Functions.Any(f => f.Name == Name)).FirstOrDefault().ServerId;
4039

41-
var client = await _clientManager.Factory.GetClientAsync(serverId);
40+
var client = await _clientManager.GetMcpClientAsync(serverId);
4241
// Call the tool through mcpdotnet
4342
var result = await client.CallToolAsync(
4443
_tool.Name,
@@ -50,7 +49,7 @@ public async Task<bool> Execute(RoleDialogModel message)
5049
.Where(c => c.Type == "text")
5150
.Select(c => c.Text));
5251
message.Content = json;
53-
message.Data = JsonSerializer.Deserialize(json,typeof(object));
52+
message.Data = json.JsonContent();
5453
return true;
5554
}
5655

0 commit comments

Comments
 (0)