Skip to content

Commit adfb8f4

Browse files
author
Jicheng Lu
committed
fix startup and use camel case
1 parent acf1ed9 commit adfb8f4

File tree

23 files changed

+112
-95
lines changed

23 files changed

+112
-95
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public virtual void OnAgentUtilityLoaded(Agent agent)
6060

6161
}
6262

63-
public virtual void OnAgentMCPToolLoaded(Agent agent)
63+
public virtual void OnAgentMcpToolLoaded(Agent agent)
6464
{
6565

6666
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface IAgentHook
2727

2828
void OnAgentUtilityLoaded(Agent agent);
2929

30-
void OnAgentMCPToolLoaded(Agent agent);
30+
void OnAgentMcpToolLoaded(Agent agent);
3131

3232
/// <summary>
3333
/// Triggered when agent is loaded completely.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class Agent
107107
/// <summary>
108108
/// Agent MCP Tools
109109
/// </summary>
110-
public List<MCPTool> McpTools { get; set; } = new();
110+
public List<McpTool> McpTools { get; set; } = new();
111111

112112
/// <summary>
113113
/// Agent rules
@@ -305,7 +305,7 @@ public Agent SetLlmConfig(AgentLlmConfig? llmConfig)
305305
return this;
306306
}
307307

308-
public Agent SetMcps(List<MCPTool> mcps)
308+
public Agent SetMcpTools(List<McpTool>? mcps)
309309
{
310310
McpTools = mcps ?? [];
311311
return this;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
namespace BotSharp.Abstraction.Agents.Models;
22

3-
public class MCPTool
3+
public class McpTool
44
{
55
public string Name { get; set; }
66
public string ServerId { get; set; }
77
public bool Disabled { get; set; }
8-
public IEnumerable<MCPFunction> Functions { get; set; } = [];
8+
public IEnumerable<McpFunction> Functions { get; set; } = [];
99

10-
public MCPTool()
10+
public McpTool()
1111
{
1212

1313
}
1414

15-
public MCPTool(
15+
public McpTool(
1616
string name,
1717
string serverId,
1818
bool disabled = false,
19-
IEnumerable<MCPFunction>? functions = null)
19+
IEnumerable<McpFunction>? functions = null)
2020
{
2121
Name = name;
2222
ServerId = serverId;
@@ -31,11 +31,11 @@ public override string ToString()
3131
}
3232

3333

34-
public class MCPFunction
34+
public class McpFunction
3535
{
3636
public string Name { get; set; }
3737

38-
public MCPFunction(string name)
38+
public McpFunction(string name)
3939
{
4040
Name = name;
4141
}

src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ namespace BotSharp.Abstraction.Plugins;
33
public class PluginSettings
44
{
55
public string[] Assemblies { get; set; } = new string[0];
6+
7+
public string[] ExcludedFunctions { get; set; } = new string[0];
68
}

src/Infrastructure/BotSharp.Core.MCP/BotSharpMCPExtensions.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
using Microsoft.Extensions.Configuration;
55
using ModelContextProtocol.Configuration;
66
using ModelContextProtocol.Client;
7+
using BotSharp.Core.MCP.Managers;
78

89
namespace BotSharp.Core.MCP;
910

10-
public static class BotSharpMCPExtensions
11+
public static class BotSharpMcpExtensions
1112
{
1213
/// <summary>
1314
/// Add mcp
@@ -17,11 +18,11 @@ public static class BotSharpMCPExtensions
1718
/// <returns></returns>
1819
public static IServiceCollection AddBotSharpMCP(this IServiceCollection services, IConfiguration config)
1920
{
20-
var settings = config.GetSection("MCPSettings").Get<MCPSettings>();
21-
services.AddScoped<MCPSettings>(provider => { return settings; });
22-
if (settings != null)
21+
var settings = config.GetSection("MCPSettings").Get<McpSettings>();
22+
services.AddScoped<McpSettings>(provider => { return settings; });
23+
if (settings != null && !settings.McpServerConfigs.IsNullOrEmpty())
2324
{
24-
var clientManager = new MCPClientManager(settings);
25+
var clientManager = new McpClientManager(settings);
2526
services.AddSingleton(clientManager);
2627

2728
foreach (var server in settings.McpServerConfigs)
@@ -31,13 +32,14 @@ public static IServiceCollection AddBotSharpMCP(this IServiceCollection services
3132
.GetAwaiter()
3233
.GetResult();
3334
}
35+
3436
// Register hooks
35-
services.AddScoped<IAgentHook, MCPToolAgentHook>();
37+
services.AddScoped<IAgentHook, McpToolAgentHook>();
3638
}
3739
return services;
3840
}
3941

40-
private static async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server, MCPClientManager clientManager)
42+
private static async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server, McpClientManager clientManager)
4143
{
4244
var client = await clientManager.GetMcpClientAsync(server.Id);
4345
var tools = await client.ListToolsAsync();

src/Infrastructure/BotSharp.Core.MCP/Functions/McpToolAdapter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System.Text.Json;
2+
using BotSharp.Core.MCP.Managers;
23
using ModelContextProtocol.Client;
34

45
namespace BotSharp.Core.MCP.Functions;
56

67
public class McpToolAdapter : IFunctionCallback
78
{
89
private readonly McpClientTool _tool;
9-
private readonly MCPClientManager _clientManager;
10+
private readonly McpClientManager _clientManager;
1011
private readonly IServiceProvider _services;
1112

12-
public McpToolAdapter(IServiceProvider services, McpClientTool tool, MCPClientManager client)
13+
public McpToolAdapter(IServiceProvider services, McpClientTool tool, McpClientManager client)
1314
{
1415
_services = services ?? throw new ArgumentNullException(nameof(services));
1516
_tool = tool ?? throw new ArgumentNullException(nameof(tool));

src/Infrastructure/BotSharp.Core.MCP/AIFunctionUtilities.cs renamed to src/Infrastructure/BotSharp.Core.MCP/Helpers/AiFunctionHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System.Text.Json;
2-
32
using ModelContextProtocol.Client;
43

5-
namespace BotSharp.Core.MCP;
4+
namespace BotSharp.Core.MCP.Helpers;
65

7-
internal static class AIFunctionUtilities
6+
internal static class AiFunctionHelper
87
{
98
public static FunctionDef MapToFunctionDef(McpClientTool tool)
109
{

src/Infrastructure/BotSharp.Core.MCP/Hooks/MCPToolAgentHook.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
using BotSharp.Core.MCP.Helpers;
2+
using BotSharp.Core.MCP.Managers;
13
using ModelContextProtocol.Client;
24

35
namespace BotSharp.Core.MCP.Hooks;
46

5-
public class MCPToolAgentHook : AgentHookBase
7+
public class McpToolAgentHook : AgentHookBase
68
{
79
public override string SelfId => string.Empty;
810

9-
public MCPToolAgentHook(IServiceProvider services, AgentSettings settings)
11+
public McpToolAgentHook(IServiceProvider services, AgentSettings settings)
1012
: base(services, settings)
1113
{
1214
}
1315

14-
public override void OnAgentMCPToolLoaded(Agent agent)
16+
public override void OnAgentMcpToolLoaded(Agent agent)
1517
{
1618
if (agent.Type == AgentType.Routing)
1719
{
@@ -24,7 +26,7 @@ public override void OnAgentMCPToolLoaded(Agent agent)
2426

2527
agent.SecondaryFunctions ??= [];
2628

27-
var functions = GetMCPContent(agent).Result;
29+
var functions = GetMcpContent(agent).Result;
2830
foreach (var fn in functions)
2931
{
3032
if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase)))
@@ -34,11 +36,11 @@ public override void OnAgentMCPToolLoaded(Agent agent)
3436
}
3537
}
3638

37-
private async Task<IEnumerable<FunctionDef>> GetMCPContent(Agent agent)
39+
private async Task<IEnumerable<FunctionDef>> GetMcpContent(Agent agent)
3840
{
3941
var functionDefs = new List<FunctionDef>();
40-
var mcpClientManager = _services.GetRequiredService<MCPClientManager>();
41-
var mcps = agent.McpTools;
42+
var mcpClientManager = _services.GetRequiredService<McpClientManager>();
43+
var mcps = agent.McpTools.Where(x => !x.Disabled);
4244
foreach (var item in mcps)
4345
{
4446
var mcpClient = await mcpClientManager.GetMcpClientAsync(item.ServerId);
@@ -48,7 +50,7 @@ private async Task<IEnumerable<FunctionDef>> GetMCPContent(Agent agent)
4850
var toolnames = item.Functions.Select(x => x.Name).ToList();
4951
foreach (var tool in tools.Where(x => toolnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
5052
{
51-
var funDef = AIFunctionUtilities.MapToFunctionDef(tool);
53+
var funDef = AiFunctionHelper.MapToFunctionDef(tool);
5254
functionDefs.Add(funDef);
5355
}
5456
}

src/Infrastructure/BotSharp.Core.MCP/MCPClientManager.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)