Skip to content

Commit e31ef62

Browse files
author
aden.chen
committed
merge from branch master
2 parents ea5d44a + 39a7421 commit e31ef62

31 files changed

Lines changed: 168 additions & 114 deletions

File tree

BotSharp.sln

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI"
127127
EndProject
128128
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}"
129129
EndProject
130-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{8D2AD45F-836A-516F-DE6A-71443CEBB18A}"
131-
EndProject
132130
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Test.ComputerUse", "tests\BotSharp.Test.ComputerUse\BotSharp.Test.ComputerUse.csproj", "{C19D9AC1-97DD-8E65-E8DB-D295A095AA2D}"
133131
EndProject
134132
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.OsDriver", "src\Plugins\BotSharp.Plugin.OsDriver\BotSharp.Plugin.OsDriver.csproj", "{B268E2F0-060F-8466-7D81-ABA4D735CA59}"
@@ -549,14 +547,6 @@ Global
549547
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.Build.0 = Release|Any CPU
550548
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.ActiveCfg = Release|Any CPU
551549
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.Build.0 = Release|Any CPU
552-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
553-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
554-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.ActiveCfg = Debug|Any CPU
555-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.Build.0 = Debug|Any CPU
556-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.ActiveCfg = Release|Any CPU
557-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.Build.0 = Release|Any CPU
558-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.ActiveCfg = Release|Any CPU
559-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.Build.0 = Release|Any CPU
560550
{C19D9AC1-97DD-8E65-E8DB-D295A095AA2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
561551
{C19D9AC1-97DD-8E65-E8DB-D295A095AA2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
562552
{C19D9AC1-97DD-8E65-E8DB-D295A095AA2D}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -730,7 +720,6 @@ Global
730720
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
731721
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
732722
{781F1465-365C-0F22-1775-25025DAFA4C7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
733-
{8D2AD45F-836A-516F-DE6A-71443CEBB18A} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
734723
{C19D9AC1-97DD-8E65-E8DB-D295A095AA2D} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
735724
{B268E2F0-060F-8466-7D81-ABA4D735CA59} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
736725
{970BE341-9AC8-99A5-6572-E703C1E02FCB} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
<PackageVersion Include="MSTest.TestAdapter" Version="4.0.2" />
9999
<PackageVersion Include="MSTest.TestFramework" Version="4.0.2" />
100100
<PackageVersion Include="Shouldly" Version="4.3.0" />
101-
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
102-
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.4.0-preview.3" />
101+
<PackageVersion Include="ModelContextProtocol" Version="1.2.0" />
102+
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="1.2.0" />
103103
</ItemGroup>
104104
<ItemGroup>
105105
<PackageVersion Include="BotSharp.Core" Version="$(BotSharpVersion)" />

src/BotSharp.AppHost/BotSharp.AppHost.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<Sdk Name="Aspire.AppHost.Sdk" Version="9.5.2" />
44
<PropertyGroup>
@@ -17,7 +17,6 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<ProjectReference Include="..\..\tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj" />
2120
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
2221
<ProjectReference Include="..\WebStarter\WebStarter.csproj" />
2322
</ItemGroup>

src/BotSharp.AppHost/Program.cs

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

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

86
builder.AddNpmApp("BotSharpUI", "../../../BotSharp-UI")
97
.WithReference(apiService)

src/Infrastructure/BotSharp.Abstraction/MCP/Models/McpServerConfigModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ public class McpServerConfigModel
1212
/// </summary>
1313
public string Name { get; set; } = null!;
1414

15+
/// <summary>
16+
/// Indicates whether this server is enabled.
17+
/// </summary>
18+
public bool Enabled { get; set; } = true;
19+
20+
/// <summary>
21+
/// URL of the icon to display for this server.
22+
/// </summary>
23+
public string? IconUrl { get; set; }
24+
25+
/// <summary>
26+
/// Short description of this server.
27+
/// </summary>
28+
public string? Description { get; set; }
29+
1530
public McpSseServerConfig? SseConfig { get; set; }
1631
public McpStdioServerConfig? StdioConfig { get; set; }
1732
}

src/Infrastructure/BotSharp.Abstraction/MCP/Models/McpServerOptionModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace BotSharp.Abstraction.MCP.Models;
22

33
public class McpServerOptionModel : IdName
44
{
5+
public string? IconUrl { get; set; }
6+
public string? Description { get; set; }
57
public IEnumerable<string> Tools { get; set; } = [];
68

79
public McpServerOptionModel() : base()

src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BotSharp.Abstraction.Options;
2+
using System.Security.Cryptography;
23
using System.Text.Json;
34
using System.Text.RegularExpressions;
45

@@ -186,4 +187,25 @@ public static string ConvertToString<T>(this T? value, JsonSerializerOptions? js
186187
var str = JsonSerializer.Serialize(value, jsonOptions);
187188
return str;
188189
}
190+
191+
/// <summary>
192+
/// Get MD5 hash of a string
193+
/// </summary>
194+
/// <param name="text"></param>
195+
/// <returns></returns>
196+
public static string GetMd5Hash(this string text)
197+
{
198+
using MD5 md5 = MD5.Create();
199+
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
200+
byte[] hashBytes = md5.ComputeHash(inputBytes);
201+
202+
// Convert byte array to a 32-character hex string
203+
StringBuilder sb = new StringBuilder();
204+
for (int i = 0; i < hashBytes.Length; i++)
205+
{
206+
sb.Append(hashBytes[i].ToString("x2")); // "x2" for lowercase hex
207+
}
208+
209+
return sb.ToString();
210+
}
189211
}

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public async Task ScheduledTimeArrived(CrontabItem item)
117117
{
118118
_logger.LogDebug($"ScheduledTimeArrived {item}");
119119

120+
if (!await HasEnabledTriggerRule(item)) return;
121+
120122
await HookEmitter.Emit<ICrontabHook>(_services, async hook =>
121123
{
122124
if (hook.Triggers == null || hook.Triggers.Contains(item.Title))
@@ -129,6 +131,27 @@ await HookEmitter.Emit<ICrontabHook>(_services, async hook =>
129131
}, item.AgentId);
130132
}
131133

134+
/// <summary>
135+
/// Returns whether the trigger is treated as enabled for this schedule: <c>true</c> unless a rule with the
136+
/// same trigger name exists and is explicitly disabled (opt-out). Missing rules do not block.
137+
/// </summary>
138+
private async Task<bool> HasEnabledTriggerRule(CrontabItem item)
139+
{
140+
var agentService = _services.GetRequiredService<IAgentService>();
141+
// No agent context: do not gate (legacy / callers without AgentId).
142+
if (string.IsNullOrEmpty(item.AgentId)) return true;
143+
144+
var agent = await agentService.GetAgent(item.AgentId);
145+
if (agent == null)
146+
{
147+
_logger.LogWarning("Agent {AgentId} is not found", item.AgentId);
148+
return false;
149+
}
150+
151+
// Opt-out only: block when a matching trigger rule exists and Disabled is true.
152+
return !agent.Rules.Any(r => r.TriggerName == item.Title && r.Disabled);
153+
}
154+
132155
public async Task ExecuteTimeArrivedItemWithReentryProtection(CrontabItem item)
133156
{
134157
if (!item.ReentryProtection)

src/Infrastructure/BotSharp.Core/MCP/Managers/McpClientManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public McpClientManager(
2222
{
2323
var settings = _services.GetRequiredService<McpSettings>();
2424
var config = settings.McpServerConfigs.Where(x => x.Id == serverId).FirstOrDefault();
25-
if (config == null)
25+
if (config == null || !config.Enabled)
2626
{
2727
return null;
2828
}

src/Infrastructure/BotSharp.Core/MCP/Services/McpService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public async Task<IEnumerable<McpServerOptionModel>> GetServerConfigsAsync()
3636
{
3737
Id = config.Id,
3838
Name = config.Name,
39+
IconUrl = config.IconUrl,
40+
Description = config.Description,
3941
Tools = tools.Select(x => x.Name)
4042
});
4143
}

0 commit comments

Comments
 (0)