Skip to content

Modelcontextprotocol #968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7a4a5db
Merge pull request #1 from Ai4c-AI/dev_conversation
geffzhang Aug 22, 2024
0bed132
Merge pull request #2 from SciSharp/master
geffzhang Aug 23, 2024
116f903
Merge branch 'SciSharp:master' into master
GreenShadeZhang Sep 25, 2024
2adab0c
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Oct 6, 2024
4d353b6
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Oct 10, 2024
e418dca
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Oct 21, 2024
bd09127
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Nov 11, 2024
866a37e
Merge branch 'SciSharp:master' into master
geffzhang Nov 25, 2024
db002a5
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Dec 17, 2024
f5e4078
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Dec 26, 2024
e2faa42
Merge branch 'SciSharp:master' into master
geffzhang Jan 6, 2025
9298c57
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Jan 7, 2025
5eec74e
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Jan 20, 2025
b9b43ba
Merge branch 'master' of https://github.com/Ai4c-AI/BotSharp
geffzhang Feb 9, 2025
ae986ed
Merge branch 'SciSharp:master' into master
geffzhang Feb 17, 2025
029c6d2
Merge branch 'SciSharp:master' into master
geffzhang Feb 18, 2025
739f2a5
feat:Integrated model context protocol(mcp)
geffzhang Feb 23, 2025
ddecb4d
Update appsettings.json
geffzhang Feb 23, 2025
4edb296
Merge branch 'SciSharp:master' into master
geffzhang Feb 23, 2025
9b66216
feat : Agent add mcp property
geffzhang Feb 23, 2025
731355d
feat: Rename Agent Context Protocols
geffzhang Feb 24, 2025
69993bd
feat:Migrate MCP to the independent BotSharp.MCP package
geffzhang Feb 25, 2025
485757c
feat: remove mcptooltemplate
geffzhang Feb 25, 2025
1d8c765
Merge branch 'SciSharp:master' into master
geffzhang Feb 25, 2025
cca509d
Merge branch 'mcp' into mergecode
geffzhang Feb 25, 2025
cfe4870
Merge pull request #3 from Ai4c-AI/mergecode
geffzhang Feb 25, 2025
8a0df48
Merge branch 'mcp' of https://github.com/Ai4c-AI/BotSharp into mcp
geffzhang Feb 25, 2025
b8926a2
feat: add pizza mcp test server
geffzhang Feb 26, 2025
1083700
Update appsettings.json
geffzhang Feb 26, 2025
ffcb1e3
feat : test pizza with mcp
geffzhang Feb 27, 2025
e9bc28f
feat: use mpdotnet nuget package
geffzhang Feb 27, 2025
0fbff1f
Update MCPToolAgentHook.cs
geffzhang Mar 2, 2025
8b46789
Merge branch 'master' into mcp
geffzhang Mar 2, 2025
812423c
feat:update mcpdotnet 1.1.0.1
geffzhang Mar 13, 2025
404a3ed
Merge branch 'SciSharp:master' into master
geffzhang Mar 16, 2025
213d393
Merge branch 'mcp' of https://github.com/Ai4c-AI/BotSharp
geffzhang Mar 16, 2025
7f6104f
Merge pull request #4 from Ai4c-AI/master
geffzhang Mar 16, 2025
bf6b30d
feat: use directory packages
geffzhang Mar 18, 2025
35358f2
feat:Data with Json
geffzhang Mar 18, 2025
c2de647
Update appsettings.json
geffzhang Mar 18, 2025
58e3e7f
feat: Using MCP's SSE transport
geffzhang Mar 19, 2025
7a9d7ff
feat:switch official sdk ModelContextProtocol
geffzhang Mar 21, 2025
129331d
feat: remove ModelContextProtocol source ref
geffzhang Mar 22, 2025
994da49
Merge branch 'SciSharp:master' into master
geffzhang Mar 22, 2025
1a1f56f
Merge branch 'master' into mcp
geffzhang Mar 22, 2025
6ac8732
Merge pull request #5 from Ai4c-AI/mcp
geffzhang Mar 22, 2025
3d26ee8
Merge pull request #966 from Ai4c-AI/master
geffzhang Mar 23, 2025
6da0598
feat: rename mcptoolfunction to mcptooladapter
geffzhang Mar 24, 2025
919fa5e
feat: rename funcnames to toolnames
geffzhang Mar 24, 2025
22b6ce5
Merge branch 'master' into modelcontextprotocol
geffzhang Mar 24, 2025
2c09c78
move out MCPConversationHook designed for PizzaBot
Oceania2018 Mar 26, 2025
21f3d6a
feat:remove unused LoggerFactory
geffzhang Mar 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions BotSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Rules", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj", "{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{8D2AD45F-836A-516F-DE6A-71443CEBB18A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -521,14 +525,30 @@ Global
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = Release|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|x64.ActiveCfg = Debug|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Debug|x64.Build.0 = Debug|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|Any CPU.Build.0 = Release|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|x64.ActiveCfg = Release|Any CPU
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4}.Release|x64.Build.0 = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|x64.ActiveCfg = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|x64.Build.0 = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|Any CPU.Build.0 = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|x64.ActiveCfg = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|x64.Build.0 = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|x64.ActiveCfg = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|x64.Build.0 = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.Build.0 = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.ActiveCfg = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.Build.0 = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.ActiveCfg = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.Build.0 = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.Build.0 = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.ActiveCfg = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -590,7 +610,9 @@ Global
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
{7ACD8C95-C66B-436A-80E7-541A57D8C3F4} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{781F1465-365C-0F22-1775-25025DAFA4C7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{8D2AD45F-836A-516F-DE6A-71443CEBB18A} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
Expand Down
5 changes: 5 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.0" />
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.0-preview.1.25080.5" />
<PackageVersion Include="System.Memory.Data" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="Rougamo.Fody" Version="4.0.4" />
<PackageVersion Include="Aspects.Cache" Version="2.0.4" />
Expand Down Expand Up @@ -106,6 +109,8 @@
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="ModelContextProtocol" Version="0.1.0-preview.1.25171.12" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="BotSharp.Core" Version="$(BotSharpVersion)" />
Expand Down
1 change: 1 addition & 0 deletions src/BotSharp.AppHost/BotSharp.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj" />
<ProjectReference Include="..\BotSharp.ServiceDefaults\BotSharp.ServiceDefaults.csproj" />
<ProjectReference Include="..\WebStarter\WebStarter.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/BotSharp.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var apiService = builder.AddProject<Projects.WebStarter>("apiservice")
.WithExternalHttpEndpoints();
var mcpService = builder.AddProject<Projects.BotSharp_PizzaBot_MCPServer>("mcpservice")
.WithExternalHttpEndpoints();

builder.AddNpmApp("BotSharpUI", "../../../BotSharp-UI")
.WithReference(apiService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ public virtual void OnAgentLoaded(Agent agent)

public virtual void OnAgentUtilityLoaded(Agent agent)
{

}

public virtual void OnAgentMCPToolLoaded(Agent agent)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum AgentField
Sample,
LlmConfig,
Utility,
McpTool,
KnowledgeBase,
Rule,
MaxMessageCount
Expand Down
2 changes: 2 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface IAgentHook

void OnAgentUtilityLoaded(Agent agent);

void OnAgentMCPToolLoaded(Agent agent);

/// <summary>
/// Triggered when agent is loaded completely.
/// </summary>
Expand Down
16 changes: 14 additions & 2 deletions src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,20 @@ public class Agent
public List<string> Labels { get; set; } = new();

/// <summary>
/// Merge utilities from entry agent
/// Merge Utility from entry agent
/// </summary>
public bool MergeUtility { get; set; }

/// <summary>
/// Agent utilities
/// Agent Utility
/// </summary>
public List<AgentUtility> Utilities { get; set; } = new();

/// <summary>
/// Agent MCP Tools
/// </summary>
public List<MCPTool> McpTools { get; set; } = new();

/// <summary>
/// Agent rules
/// </summary>
Expand Down Expand Up @@ -157,6 +162,7 @@ public static Agent Clone(Agent agent)
Responses = agent.Responses,
Samples = agent.Samples,
Utilities = agent.Utilities,
McpTools = agent.McpTools,
Knowledges = agent.Knowledges,
IsPublic = agent.IsPublic,
Disabled = agent.Disabled,
Expand Down Expand Up @@ -298,4 +304,10 @@ public Agent SetLlmConfig(AgentLlmConfig? llmConfig)
LlmConfig = llmConfig;
return this;
}

public Agent SetMcps(List<MCPTool> mcps)
{
McpTools = mcps ?? [];
return this;
}
}
37 changes: 37 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace BotSharp.Abstraction.Agents.Models;

public class MCPTool
{
public string ServerId { get; set; }

public bool Disabled { get; set; }

public IEnumerable<MCPFunction> Functions { get; set; } = [];

public MCPTool()
{

}

public MCPTool(
IEnumerable<MCPFunction>? functions = null)
{
Functions = functions ?? [];
}

public override string ToString()
{
return ServerId;
}
}


public class MCPFunction
{
public string Name { get; set; }

public MCPFunction(string name)
{
this.Name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public override void OnAgentUtilityLoaded(Agent agent)
agent.SecondaryInstructions.Add(prompt);
}
}


private (IEnumerable<FunctionDef>, IEnumerable<string>) GetUtilityContent(Agent agent)
{
Expand Down Expand Up @@ -81,5 +82,5 @@ public override void OnAgentUtilityLoaded(Agent agent)
.Distinct().ToList();

return (functionNames, templateNames);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public async Task<Agent> LoadAgent(string id, bool loadUtility = true)
{
hook.OnAgentUtilityLoaded(agent);
}

if(agent.McpTools != null && agent.McpTools.Count >0)
{
hook.OnAgentMCPToolLoaded(agent);
}

hook.OnAgentLoaded(agent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async Task UpdateAgent(Agent agent, AgentField updateField)
record.Responses = agent.Responses ?? [];
record.Samples = agent.Samples ?? [];
record.Utilities = agent.Utilities ?? [];
record.McpTools = agent.McpTools ?? [];
record.KnowledgeBases = agent.KnowledgeBases ?? [];
record.Rules = agent.Rules ?? [];
if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit)
Expand Down Expand Up @@ -106,6 +107,7 @@ public async Task<string> UpdateAgentFromFile(string id)
.SetResponses(foundAgent.Responses)
.SetSamples(foundAgent.Samples)
.SetUtilities(foundAgent.Utilities)
.SetMcps(foundAgent.McpTools)
.SetKnowledgeBases(foundAgent.KnowledgeBases)
.SetRules(foundAgent.Rules)
.SetLlmConfig(foundAgent.LlmConfig);
Expand Down Expand Up @@ -195,7 +197,7 @@ public async Task<string> PatchAgentTemplate(Agent agent)
var samples = GetSamplesFromFile(dir);
return agent.SetInstruction(defaultInstruction)
.SetChannelInstructions(channelInstructions)
.SetTemplates(templates)
.SetTemplates(templates)
.SetFunctions(functions)
.SetResponses(responses)
.SetSamples(samples);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public void UpdateAgent(Agent agent, AgentField field)
case AgentField.Utility:
UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities);
break;
case AgentField.McpTool:
UpdateAgentMcpTools(agent.Id, agent.McpTools);
break;
case AgentField.KnowledgeBase:
UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases);
break;
Expand Down Expand Up @@ -191,6 +194,20 @@ private void UpdateAgentUtilities(string agentId, bool mergeUtility, List<AgentU
File.WriteAllText(agentFile, json);
}

private void UpdateAgentMcpTools(string agentId, List<MCPTool> mcptools)
{
if (mcptools == null) return;

var (agent, agentFile) = GetAgentFromFile(agentId);
if (agent == null) return;


agent.McpTools = mcptools;
agent.UpdatedDateTime = DateTime.UtcNow;
var json = JsonSerializer.Serialize(agent, _options);
File.WriteAllText(agentFile, json);
}

private void UpdateAgentKnowledgeBases(string agentId, List<AgentKnowledgeBase> knowledgeBases)
{
if (knowledgeBases == null) return;
Expand Down Expand Up @@ -360,6 +377,7 @@ private void UpdateAgentAllFields(Agent inputAgent)
agent.Profiles = inputAgent.Profiles;
agent.Labels = inputAgent.Labels;
agent.Utilities = inputAgent.Utilities;
agent.McpTools = inputAgent.McpTools;
agent.KnowledgeBases = inputAgent.KnowledgeBases;
agent.RoutingRules = inputAgent.RoutingRules;
agent.Rules = inputAgent.Rules;
Expand Down
36 changes: 36 additions & 0 deletions src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using BotSharp.Abstraction.Functions.Models;
using ModelContextProtocol.Protocol.Types;
using System;
using System.Collections.Generic;
using System.Text.Json;

namespace BotSharp.Core.MCP;

internal static class AIFunctionUtilities
{
public static FunctionDef MapToFunctionDef(Tool tool)
{
if (tool == null)
{
throw new ArgumentNullException(nameof(tool));
}

var properties = tool.InputSchema.GetProperty("properties");
var required = tool.InputSchema.GetProperty("required");

FunctionDef funDef = new FunctionDef
{
Name = tool.Name,
Description = tool.Description ?? string.Empty,
Type = "function",
Parameters = new FunctionParametersDef
{
Type = "object",
Properties = JsonDocument.Parse(properties.GetRawText()),
Required = JsonSerializer.Deserialize<List<string>>(required.GetRawText())
}
};

return funDef;
}
}
19 changes: 19 additions & 0 deletions src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>$(LangVersion)</LangVersion>
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
<OutputPath>$(SolutionDir)packages</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ModelContextProtocol" />
<PackageReference Include="System.Linq.AsyncEnumerable" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>
</Project>
Loading
Loading