Skip to content

Commit 213d393

Browse files
committed
2 parents 404a3ed + 812423c commit 213d393

File tree

36 files changed

+908
-142
lines changed

36 files changed

+908
-142
lines changed

BotSharp.sln

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ 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", "{8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}"
131+
EndProject
132+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{AD91B4ED-0623-4710-913E-6D7C893E76EF}"
131133
EndProject
132134
Global
133135
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -521,14 +523,6 @@ Global
521523
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU
522524
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU
523525
{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
532526
EndGlobalSection
533527
GlobalSection(SolutionProperties) = preSolution
534528
HideSolutionNode = FALSE
@@ -590,7 +584,6 @@ Global
590584
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
591585
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
592586
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
593-
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
594587
EndGlobalSection
595588
GlobalSection(ExtensibilityGlobals) = postSolution
596589
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

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+
Acp,
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
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public async Task<Agent> LoadAgent(string id, bool loadUtility = true)
7171
{
7272
hook.OnAgentUtilityLoaded(agent);
7373
}
74+
75+
if(agent.McpTools != null && agent.McpTools.Count >0)
76+
{
77+
hook.OnAgentMCPToolLoaded(agent);
78+
}
7479

7580
hook.OnAgentLoaded(agent);
7681
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public async Task UpdateAgent(Agent agent, AgentField updateField)
4040
record.Responses = agent.Responses ?? [];
4141
record.Samples = agent.Samples ?? [];
4242
record.Utilities = agent.Utilities ?? [];
43+
record.McpTools = agent.McpTools ?? [];
4344
record.KnowledgeBases = agent.KnowledgeBases ?? [];
4445
record.Rules = agent.Rules ?? [];
4546
if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit)
@@ -106,6 +107,7 @@ public async Task<string> UpdateAgentFromFile(string id)
106107
.SetResponses(foundAgent.Responses)
107108
.SetSamples(foundAgent.Samples)
108109
.SetUtilities(foundAgent.Utilities)
110+
.SetMcps(foundAgent.McpTools)
109111
.SetKnowledgeBases(foundAgent.KnowledgeBases)
110112
.SetRules(foundAgent.Rules)
111113
.SetLlmConfig(foundAgent.LlmConfig);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ 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:
64+
UpdateAgentMcpTools(agent.Id, agent.McpTools);
65+
break;
6366
case AgentField.KnowledgeBase:
6467
UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases);
6568
break;
@@ -191,6 +194,20 @@ private void UpdateAgentUtilities(string agentId, bool mergeUtility, List<AgentU
191194
File.WriteAllText(agentFile, json);
192195
}
193196

197+
private void UpdateAgentMcpTools(string agentId, List<MCPTool> mcptools)
198+
{
199+
if (mcptools == null) return;
200+
201+
var (agent, agentFile) = GetAgentFromFile(agentId);
202+
if (agent == null) return;
203+
204+
205+
agent.McpTools = mcptools;
206+
agent.UpdatedDateTime = DateTime.UtcNow;
207+
var json = JsonSerializer.Serialize(agent, _options);
208+
File.WriteAllText(agentFile, json);
209+
}
210+
194211
private void UpdateAgentKnowledgeBases(string agentId, List<AgentKnowledgeBase> knowledgeBases)
195212
{
196213
if (knowledgeBases == null) return;
@@ -360,6 +377,7 @@ private void UpdateAgentAllFields(Agent inputAgent)
360377
agent.Profiles = inputAgent.Profiles;
361378
agent.Labels = inputAgent.Labels;
362379
agent.Utilities = inputAgent.Utilities;
380+
agent.McpTools = inputAgent.McpTools;
363381
agent.KnowledgeBases = inputAgent.KnowledgeBases;
364382
agent.RoutingRules = inputAgent.RoutingRules;
365383
agent.Rules = inputAgent.Rules;

0 commit comments

Comments
 (0)