Skip to content

Commit 0df79b0

Browse files
Merge branch 'master' into dev_fix_pizza
2 parents e0e717a + b80cba3 commit 0df79b0

File tree

10 files changed

+136
-114
lines changed

10 files changed

+136
-114
lines changed

src/Infrastructure/BotSharp.OpenAPI/BotSharp.OpenAPI.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
</ItemGroup>
4848

4949
<ItemGroup>
50-
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
50+
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
51+
<ProjectReference Include="..\BotSharp.MCP\BotSharp.MCP.csproj" />
5152
</ItemGroup>
5253

5354
<ItemGroup>

src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using BotSharp.Abstraction.Agents.Models;
2+
using BotSharp.Core.Mcp;
3+
using ModelContextProtocol.Client;
4+
using ModelContextProtocol.Protocol.Types;
25

36
namespace BotSharp.OpenAPI.Controllers;
47

@@ -9,15 +12,19 @@ public class AgentController : ControllerBase
912
private readonly IAgentService _agentService;
1013
private readonly IUserIdentity _user;
1114
private readonly IServiceProvider _services;
15+
private readonly MCPClientManager _clientManager;
1216

1317
public AgentController(
1418
IAgentService agentService,
1519
IUserIdentity user,
16-
IServiceProvider services)
20+
IServiceProvider services,
21+
MCPClientManager mCPClientManager
22+
)
1723
{
1824
_agentService = agentService;
1925
_user = user;
2026
_services = services;
27+
_clientManager = mCPClientManager;
2128
}
2229

2330
[HttpGet("/agent/settings")]
@@ -167,6 +174,16 @@ public IEnumerable<AgentUtility> GetAgentUtilityOptions()
167174
return utilities.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderBy(x => x.Name).ToList();
168175
}
169176

177+
[HttpGet("/agent/mcp/tools")]
178+
public async Task<IEnumerable<Tool>> GetMCPTools(string serverId)
179+
{
180+
var client = await _clientManager.GetMcpClientAsync(serverId);
181+
var tools = await client.ListToolsAsync().ToListAsync();
182+
183+
return tools.Where(x => !string.IsNullOrWhiteSpace(x.Name))
184+
.OrderBy(x => x.Name).ToList();
185+
}
186+
170187
[HttpGet("/agent/labels")]
171188
public async Task<IEnumerable<string>> GetAgentLabels()
172189
{

src/WebStarter/WebStarter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
<ItemGroup>
8080
<ProjectReference Include="..\..\tests\BotSharp.Plugin.PizzaBot\BotSharp.Plugin.PizzaBot.csproj" />
8181
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
82-
<ProjectReference Include="..\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj" />
8382
</ItemGroup>
8483

8584
<ItemGroup Condition="$(SolutionName)==BotSharp">
@@ -122,6 +121,7 @@
122121
<ProjectReference Include="..\Plugins\BotSharp.Plugin.MetaGLM\BotSharp.Plugin.MetaGLM.csproj" />
123122
<ProjectReference Include="..\Plugins\BotSharp.Plugin.Planner\BotSharp.Plugin.Planner.csproj" />
124123
<ProjectReference Include="..\Plugins\BotSharp.Plugin.TencentCos\BotSharp.Plugin.TencentCos.csproj" />
124+
<ProjectReference Include="..\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj" />
125125
</ItemGroup>
126126

127127
<ItemGroup>
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
//using BotSharp.Abstraction.Conversations.Models;
2-
//using System.Text.Json;
1+
using BotSharp.Abstraction.Conversations.Models;
2+
using System.Text.Json;
33

4-
//namespace BotSharp.Plugin.PizzaBot.Functions;
4+
namespace BotSharp.Plugin.PizzaBot.Functions;
55

6-
//public class GetPizzaPricesFn : IFunctionCallback
7-
//{
8-
// public string Name => "get_pizza_price";
6+
public class GetPizzaPricesFn : IFunctionCallback
7+
{
8+
public string Name => "get_pizza_price";
99

10-
// public async Task<bool> Execute(RoleDialogModel message)
11-
// {
12-
// message.Data = new
13-
// {
14-
// pepperoni_unit_price = 3.2,
15-
// cheese_unit_price = 3.5,
16-
// margherita_unit_price = 3.8,
17-
// };
18-
// message.Content = JsonSerializer.Serialize(message.Data);
19-
// return true;
20-
// }
21-
//}
10+
public async Task<bool> Execute(RoleDialogModel message)
11+
{
12+
message.Data = new
13+
{
14+
pepperoni_unit_price = 3.2,
15+
cheese_unit_price = 3.5,
16+
margherita_unit_price = 3.8,
17+
};
18+
message.Content = JsonSerializer.Serialize(message.Data);
19+
return true;
20+
}
21+
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//using BotSharp.Abstraction.Conversations.Models;
1+
using BotSharp.Abstraction.Conversations.Models;
22

3-
//namespace BotSharp.Plugin.PizzaBot.Functions;
3+
namespace BotSharp.Plugin.PizzaBot.Functions;
44

5-
//public class MakePaymentFn : IFunctionCallback
6-
//{
7-
// public string Name => "make_payment";
5+
public class MakePaymentFn : IFunctionCallback
6+
{
7+
public string Name => "make_payment";
88

9-
// public async Task<bool> Execute(RoleDialogModel message)
10-
// {
11-
// message.Content = "Payment proceed successfully. Thank you for your business. Have a great day!";
12-
// message.Data = new
13-
// {
14-
// Transaction = Guid.NewGuid().ToString(),
15-
// Status = "Success"
16-
// };
17-
// return true;
18-
// }
19-
//}
9+
public async Task<bool> Execute(RoleDialogModel message)
10+
{
11+
message.Content = "Payment proceed successfully. Thank you for your business. Have a great day!";
12+
message.Data = new
13+
{
14+
Transaction = Guid.NewGuid().ToString(),
15+
Status = "Success"
16+
};
17+
return true;
18+
}
19+
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
//using BotSharp.Abstraction.Conversations;
2-
//using BotSharp.Abstraction.Conversations.Models;
1+
using BotSharp.Abstraction.Conversations;
2+
using BotSharp.Abstraction.Conversations.Models;
33

4-
//namespace BotSharp.Plugin.PizzaBot.Functions;
4+
namespace BotSharp.Plugin.PizzaBot.Functions;
55

6-
//public class PlaceOrderFn : IFunctionCallback
7-
//{
8-
// public string Name => "place_an_order";
6+
public class PlaceOrderFn : IFunctionCallback
7+
{
8+
public string Name => "place_an_order";
99

10-
// private readonly IServiceProvider _service;
11-
// public PlaceOrderFn(IServiceProvider service)
12-
// {
13-
// _service = service;
14-
// }
10+
private readonly IServiceProvider _service;
11+
public PlaceOrderFn(IServiceProvider service)
12+
{
13+
_service = service;
14+
}
1515

16-
// public async Task<bool> Execute(RoleDialogModel message)
17-
// {
18-
// message.Content = "The order number is P123-01";
19-
// var state = _service.GetRequiredService<IConversationStateService>();
20-
// state.SetState("order_number", "P123-01");
16+
public async Task<bool> Execute(RoleDialogModel message)
17+
{
18+
message.Content = "The order number is P123-01";
19+
var state = _service.GetRequiredService<IConversationStateService>();
20+
state.SetState("order_number", "P123-01");
2121

22-
// return true;
23-
// }
24-
//}
22+
return true;
23+
}
24+
}

tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotConversationHook.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ public override Task OnTaskCompleted(RoleDialogModel message)
3232
return base.OnTaskCompleted(message);
3333
}
3434

35+
#if USE_BOTSHARP
3536
public override async Task OnResponseGenerated(RoleDialogModel message)
3637
{
3738
var agentService = _services.GetRequiredService<IAgentService>();
3839
var state = _services.GetRequiredService<IConversationStateService>();
3940
var agent = await agentService.LoadAgent(message.CurrentAgentId);
41+
4042
if (agent.McpTools.Any(item => item.Functions.Any(x => x.Name == message.FunctionName)))
4143
{
4244
var data = JsonDocument.Parse(JsonSerializer.Serialize(message.Data));
4345
state.SaveStateByArgs(data);
4446
}
47+
4548
await base.OnResponseGenerated(message);
4649
}
50+
#endif
4751
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//{
2-
// "name": "get_pizza_price",
3-
// "description": "call this function to get the pizza price",
4-
// "parameters": {
5-
// "type": "object",
6-
// "properties": {
7-
// "pizza_type": {
8-
// "type": "string",
9-
// "description": "The pizza type."
10-
// },
11-
// "quantity": {
12-
// "type": "string",
13-
// "description": "quantity of pizza."
14-
// }
15-
// },
16-
// "required": [ "pizza_type", "quantity" ]
17-
// }
18-
//}
1+
{
2+
"name": "get_pizza_price",
3+
"description": "call this function to get the pizza price",
4+
"parameters": {
5+
"type": "object",
6+
"properties": {
7+
"pizza_type": {
8+
"type": "string",
9+
"description": "The pizza type."
10+
},
11+
"quantity": {
12+
"type": "string",
13+
"description": "quantity of pizza."
14+
}
15+
},
16+
"required": [ "pizza_type", "quantity" ]
17+
}
18+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
//{
2-
// "name": "place_an_order",
3-
// "description": "Place an order when user has confirmed the pizza type and quantity.",
4-
// "parameters": {
5-
// "type": "object",
6-
// "properties": {
7-
// "pizza_type": {
8-
// "type": "string",
9-
// "description": "The pizza type."
10-
// },
11-
// "quantity": {
12-
// "type": "number",
13-
// "description": "quantity of pizza."
14-
// },
15-
// "unit_price": {
16-
// "type": "number",
17-
// "description": "unit price"
18-
// }
19-
// },
20-
// "required": [ "pizza_type", "quantity", "unit_price" ]
21-
// }
22-
//}
1+
{
2+
"name": "place_an_order",
3+
"description": "Place an order when user has confirmed the pizza type and quantity.",
4+
"parameters": {
5+
"type": "object",
6+
"properties": {
7+
"pizza_type": {
8+
"type": "string",
9+
"description": "The pizza type."
10+
},
11+
"quantity": {
12+
"type": "number",
13+
"description": "quantity of pizza."
14+
},
15+
"unit_price": {
16+
"type": "number",
17+
"description": "unit price"
18+
}
19+
},
20+
"required": [ "pizza_type", "quantity", "unit_price" ]
21+
}
22+
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//{
2-
// "name": "make_payment",
3-
// "description": "call this function to make payment",
4-
// "parameters": {
5-
// "type": "object",
6-
// "properties": {
7-
// "order_number": {
8-
// "type": "string",
9-
// "description": "order number."
10-
// },
11-
// "total_amount": {
12-
// "type": "string",
13-
// "description": "total amount."
14-
// }
15-
// },
16-
// "required": [ "order_number", "total_amount" ]
17-
// }
18-
//}
1+
{
2+
"name": "make_payment",
3+
"description": "call this function to make payment",
4+
"parameters": {
5+
"type": "object",
6+
"properties": {
7+
"order_number": {
8+
"type": "string",
9+
"description": "order number."
10+
},
11+
"total_amount": {
12+
"type": "string",
13+
"description": "total amount."
14+
}
15+
},
16+
"required": [ "order_number", "total_amount" ]
17+
}
18+
}

0 commit comments

Comments
 (0)