Skip to content

Commit fe19666

Browse files
authored
Update libraries and fix bugs (#41)
1 parent 28df906 commit fe19666

File tree

10 files changed

+29
-17
lines changed

10 files changed

+29
-17
lines changed

MCPSharp.Example.OllamaChatCLI/MCPSharp.Example.OllamaChatCLI.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.3.0-preview.1.25114.11" />
11+
<PackageReference Include="OllamaSharp" Version="5.2.2" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
15+
<ProjectReference Include="..\MCPSharp.Example\MCPSharp.Example.csproj" />
1516
<ProjectReference Include="..\MCPSharp\MCPSharp.csproj" />
1617
</ItemGroup>
1718

MCPSharp.Example.OllamaChatCLI/Program.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@
2626
Tools = clients.GetAllAIFunctions(),
2727
ToolMode = ChatToolMode.Auto //let the assistant choose not to use a tool if it doesn't need to
2828
};
29-
var chatHistory = new List<ChatMessage>() { new(ChatRole.System, conf.Models["ollama"].SystemPrompt) };
30-
var chatClient = new OllamaChatClient(conf.Models["ollama"].Endpoint, conf.Models["ollama"].ModelId).AsBuilder().UseFunctionInvocation().Build();
29+
var chatHistory = new List<ChatMessage>() { new(ChatRole.System, conf.Models["ollama"].SystemPrompt) };
30+
var chatClient = new OllamaSharp.OllamaApiClient(conf.Models["ollama"].Endpoint, conf.Models["ollama"].ModelId); //.AsBuilder().UseFunctionInvocation().Build();
31+
3132

3233
while (true)
3334
{
3435
Console.Write("\n\n[User] >> ");
3536
var input = Console.ReadLine();
3637
if (input == "bye") break;
37-
chatHistory.Add(new ChatMessage(ChatRole.User, input));
38-
var response = await chatClient.GetResponseAsync(chatHistory, chatOptions);
38+
if (string.IsNullOrWhiteSpace(input)) continue;
39+
var response = await chatClient.GetResponseAsync(input, chatOptions);
3940
Console.WriteLine($"\n\n[Assistant] {DateTime.Now.ToShortTimeString()}: {response}");
40-
chatHistory.Add(response.Message);
41+
chatHistory.Add(response.Messages.First());
4142
}
4243

4344
class McpServerConfiguration

MCPSharp.Example/MCPSharp.Example.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<DebugType>embedded</DebugType>
3030
</PropertyGroup>
3131

32+
<ItemGroup>
33+
<PackageReference Include="System.Formats.Asn1" Version="9.0.6" />
34+
</ItemGroup>
35+
3236
<ItemGroup>
3337
<ProjectReference Include="..\MCPSharp.ExternalExample\MCPSharp.Example.Import.csproj" />
3438
<ProjectReference Include="..\MCPSharp\MCPSharp.csproj" />

MCPSharp.ExternalExample/ExternalTool.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
namespace MCPSharp.ExternalExample
55
{
66

7-
[McpTool("external_tools", "for testing accessing tool classes loaded from a library")]
87
public class ExternalTool
98
{
109

11-
[McpFunction("dll-tool", "attempts to use a tool that is loaded from an external assembly dll. should return 'success'")]
10+
[McpTool("dll-tool", "attempts to use a tool that is loaded from an external assembly dll. should return 'success'")]
1211
public static async Task<string> UseAsync()
1312
{
1413
return await Task.Run(()=>"success");

MCPSharp.ExternalExample/MCPSharp.Example.Import.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<TargetFramework>net9.0</TargetFramework>
77
</PropertyGroup>
88

99
<ItemGroup>

MCPSharp.Test/AIFunctionAbstractionTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public async Task TestInvokingAnAIFunctionWithParameters()
3737
var function = functions.First(f => f.Name == "Echo");
3838
var Schema = function.JsonSchema;
3939
Console.WriteLine(Schema);
40-
CallToolResult result = (CallToolResult)(await function.InvokeAsync(new Dictionary<string, object?> { { "input", "hello there" } }))!;
40+
41+
AIFunctionArguments keyValuePairs = new()
42+
{
43+
{ "input", "hello there" }
44+
};
45+
46+
CallToolResult result = (CallToolResult)(await function.InvokeAsync(keyValuePairs))!;
4147

4248
Assert.IsFalse(result.IsError);
4349

MCPSharp.Test/MCPSharp.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="MSTest" Version="3.8.2" />
11+
<PackageReference Include="MSTest" Version="3.9.3" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

MCPSharp/Core/MCPFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class MCPFunction(Tool tool, MCPClient client) : AIFunction()
4848
public override JsonElement JsonSchema => JsonSerializer.SerializeToElement(new MCPFunctionInputSchema(_tool.Name, _tool.Description, _tool.InputSchema));
4949

5050

51-
protected override async Task<object> InvokeCoreAsync(IEnumerable<KeyValuePair<string, object>> arguments, CancellationToken cancellationToken)
51+
protected override async ValueTask<object> InvokeCoreAsync(AIFunctionArguments arguments, CancellationToken cancellationToken)
5252
{
5353
return await _client.CallToolAsync(_tool.Name, arguments.ToDictionary(p => p.Key, p => p.Value));
5454
}

MCPSharp/MCPSharp.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ await client.CallToolAsync("echo", new Dictionary&lt;string, object&gt;{{"input"
7979

8080
<ItemGroup>
8181
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.3.0" />
82-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
83-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
84-
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.38.0" />
82+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.6.0" />
83+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.6.0" />
84+
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.57.0" />
8585
<PackageReference Include="PolySharp" Version="1.15.0">
8686
<PrivateAssets>all</PrivateAssets>
8787
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8888
</PackageReference>
89-
<PackageReference Include="StreamJsonRpc" Version="2.21.10" />
89+
<PackageReference Include="StreamJsonRpc" Version="2.22.11" />
90+
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
9091
</ItemGroup>
9192

9293
<ItemGroup>

MCPSharp/Model/MetaData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class MetaData
1111
/// Gets or sets the progress token.
1212
/// </summary>
1313
[JsonPropertyName("progressToken")]
14-
public int ProgressToken { get; set; } = 0;
14+
public string ProgressToken { get; set; } = "";
1515
}
1616
}

0 commit comments

Comments
 (0)