Skip to content

Commit 3d26ee8

Browse files
authored
Merge pull request #966 from Ai4c-AI/master
merge to botsharp
2 parents 385b65e + 6ac8732 commit 3d26ee8

File tree

46 files changed

+1262
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1262
-144
lines changed

BotSharp.sln

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +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.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}"
130+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj", "{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}"
131+
EndProject
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}"
131135
EndProject
132136
Global
133137
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -521,14 +525,30 @@ Global
521525
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU
522526
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU
523527
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = Release|Any CPU
524-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
525-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
526-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|x64.ActiveCfg = Debug|Any CPU
527-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|x64.Build.0 = Debug|Any CPU
528-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
529-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|Any CPU.Build.0 = Release|Any CPU
530-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|x64.ActiveCfg = Release|Any CPU
531-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.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
532552
EndGlobalSection
533553
GlobalSection(SolutionProperties) = preSolution
534554
HideSolutionNode = FALSE
@@ -590,7 +610,9 @@ Global
590610
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
591611
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
592612
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
593-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
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}
594616
EndGlobalSection
595617
GlobalSection(ExtensibilityGlobals) = postSolution
596618
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/AgentHookBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ public virtual void OnAgentLoaded(Agent agent)
5757

5858
public virtual void OnAgentUtilityLoaded(Agent agent)
5959
{
60+
61+
}
62+
63+
public virtual void OnAgentMCPToolLoaded(Agent agent)
64+
{
65+
6066
}
6167
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum AgentField
1919
Sample,
2020
LlmConfig,
2121
Utility,
22+
McpTool,
2223
KnowledgeBase,
2324
Rule,
2425
MaxMessageCount

src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface IAgentHook
2727

2828
void OnAgentUtilityLoaded(Agent agent);
2929

30+
void OnAgentMCPToolLoaded(Agent agent);
31+
3032
/// <summary>
3133
/// Triggered when agent is loaded completely.
3234
/// </summary>

src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,20 @@ public class Agent
9595
public List<string> Labels { get; set; } = new();
9696

9797
/// <summary>
98-
/// Merge utilities from entry agent
98+
/// Merge Utility from entry agent
9999
/// </summary>
100100
public bool MergeUtility { get; set; }
101101

102102
/// <summary>
103-
/// Agent utilities
103+
/// Agent Utility
104104
/// </summary>
105105
public List<AgentUtility> Utilities { get; set; } = new();
106106

107+
/// <summary>
108+
/// Agent MCP Tools
109+
/// </summary>
110+
public List<MCPTool> McpTools { get; set; } = new();
111+
107112
/// <summary>
108113
/// Agent rules
109114
/// </summary>
@@ -157,6 +162,7 @@ public static Agent Clone(Agent agent)
157162
Responses = agent.Responses,
158163
Samples = agent.Samples,
159164
Utilities = agent.Utilities,
165+
McpTools = agent.McpTools,
160166
Knowledges = agent.Knowledges,
161167
IsPublic = agent.IsPublic,
162168
Disabled = agent.Disabled,
@@ -298,4 +304,10 @@ public Agent SetLlmConfig(AgentLlmConfig? llmConfig)
298304
LlmConfig = llmConfig;
299305
return this;
300306
}
307+
308+
public Agent SetMcps(List<MCPTool> mcps)
309+
{
310+
McpTools = mcps ?? [];
311+
return this;
312+
}
301313
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace BotSharp.Abstraction.Agents.Models;
2+
3+
public class MCPTool
4+
{
5+
public string ServerId { get; set; }
6+
7+
public bool Disabled { get; set; }
8+
9+
public IEnumerable<MCPFunction> Functions { get; set; } = [];
10+
11+
public MCPTool()
12+
{
13+
14+
}
15+
16+
public MCPTool(
17+
IEnumerable<MCPFunction>? functions = null)
18+
{
19+
Functions = functions ?? [];
20+
}
21+
22+
public override string ToString()
23+
{
24+
return ServerId;
25+
}
26+
}
27+
28+
29+
public class MCPFunction
30+
{
31+
public string Name { get; set; }
32+
33+
public MCPFunction(string name)
34+
{
35+
this.Name = name;
36+
}
37+
}

src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public override void OnAgentUtilityLoaded(Agent agent)
3838
agent.SecondaryInstructions.Add(prompt);
3939
}
4040
}
41+
4142

4243
private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(Agent agent)
4344
{
@@ -81,5 +82,5 @@ public override void OnAgentUtilityLoaded(Agent agent)
8182
.Distinct().ToList();
8283

8384
return (functionNames, templateNames);
84-
}
85+
}
8586
}

0 commit comments

Comments
 (0)