Skip to content

Commit 013901f

Browse files
committed
feat: McpClientTool replace Tool
1 parent d439d38 commit 013901f

File tree

7 files changed

+13
-15
lines changed

7 files changed

+13
-15
lines changed

Directory.Packages.props

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
2020
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
2121
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
22-
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.0" />
23-
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.0-preview.1.25080.5" />
22+
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.0" />
2423
<PackageVersion Include="System.Memory.Data" Version="8.0.0" />
2524
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
2625
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
@@ -110,8 +109,7 @@
110109
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
111110
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
112111
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
113-
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.2" />
114-
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
112+
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.2" />
115113
</ItemGroup>
116114
<ItemGroup>
117115
<PackageVersion Include="BotSharp.Core" Version="$(BotSharpVersion)" />

src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BotSharp.Abstraction.Functions.Models;
2+
using ModelContextProtocol.Client;
23
using ModelContextProtocol.Protocol.Types;
34
using System;
45
using System.Collections.Generic;
@@ -8,15 +9,15 @@ namespace BotSharp.Core.MCP;
89

910
internal static class AIFunctionUtilities
1011
{
11-
public static FunctionDef MapToFunctionDef(Tool tool)
12+
public static FunctionDef MapToFunctionDef(McpClientTool tool)
1213
{
1314
if (tool == null)
1415
{
1516
throw new ArgumentNullException(nameof(tool));
1617
}
1718

18-
var properties = tool.InputSchema.GetProperty("properties");
19-
var required = tool.InputSchema.GetProperty("required");
19+
var properties = tool.JsonSchema.GetProperty("properties");
20+
var required = tool.JsonSchema.GetProperty("required");
2021

2122
FunctionDef funDef = new FunctionDef
2223
{

src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="ModelContextProtocol" />
13-
<PackageReference Include="System.Linq.AsyncEnumerable" />
1413
</ItemGroup>
1514

1615
<ItemGroup>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace BotSharp.Core.Mcp.Functions;
1515

1616
public class McpToolAdapter : IFunctionCallback
1717
{
18-
private readonly Tool _tool;
18+
private readonly McpClientTool _tool;
1919
private readonly MCPClientManager _clientManager;
2020
private readonly IServiceProvider _serviceProvider;
2121

22-
public McpToolAdapter(IServiceProvider provider, Tool tool, MCPClientManager client)
22+
public McpToolAdapter(IServiceProvider provider, McpClientTool tool, MCPClientManager client)
2323
{
2424
_serviceProvider = provider ?? throw new ArgumentNullException(nameof(provider));
2525
_tool = tool ?? throw new ArgumentNullException(nameof(tool));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ private async Task<IEnumerable<FunctionDef>> GetMCPContent(Agent agent)
5555
var mcpClient = await mcpClientManager.GetMcpClientAsync(item.ServerId);
5656
if (mcpClient != null)
5757
{
58-
var tools = await mcpClient.ListToolsAsync().ToListAsync();
58+
var tools = await mcpClient.ListToolsAsync();
5959
var toolnames = item.Functions.Select(x => x.Name).ToList();
60-
foreach (var tool in tools.Where(x => toolnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
60+
foreach (var tool in tools.ToList().Where(x => toolnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
6161
{
6262
var funDef = AIFunctionUtilities.MapToFunctionDef(tool);
6363
functionDefs.Add(funDef);

src/Infrastructure/BotSharp.MCP/McpPlugin.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
4545
private async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server)
4646
{
4747
var client = await clientManager.GetMcpClientAsync(server.Id);
48-
var tools = await client.ListToolsAsync().ToListAsync();
48+
var tools = await client.ListToolsAsync();
4949

5050
foreach (var tool in tools)
5151
{

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ public IEnumerable<AgentUtility> GetAgentUtilityOptions()
175175
}
176176

177177
[HttpGet("/agent/mcp/tools")]
178-
public async Task<IEnumerable<Tool>> GetMCPTools(string serverId)
178+
public async Task<IEnumerable<McpClientTool>> GetMCPTools(string serverId)
179179
{
180180
var client = await _clientManager.GetMcpClientAsync(serverId);
181-
var tools = await client.ListToolsAsync().ToListAsync();
181+
var tools = await client.ListToolsAsync();
182182

183183
return tools.Where(x => !string.IsNullOrWhiteSpace(x.Name))
184184
.OrderBy(x => x.Name).ToList();

0 commit comments

Comments
 (0)