Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 21 additions & 21 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<PackageVersion Include="Azure.Communication.Sms" Version="1.0.2" />
<PackageVersion Include="Azure.Communication.Email" Version="1.0.2" />
<PackageVersion Include="Azure.AI.Projects" Version="1.0.0-beta.9" />
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.4" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.3.0-beta.2" />
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.7" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.7.0-beta.1" />
<PackageVersion Include="Azure.Bicep.Types" Version="0.6.1" />
<PackageVersion Include="Azure.Core" Version="1.49.0" />
<PackageVersion Include="Azure.Data.AppConfiguration" Version="1.6.1" />
Expand Down Expand Up @@ -59,38 +59,38 @@
<PackageVersion Include="Azure.ResourceManager.ResourceGraph" Version="1.1.0" />
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="13.0.2" />
<PackageVersion Include="Microsoft.Identity.Client.Broker" Version="4.72.1" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.10.0" />
<PackageVersion Include="Microsoft.Extensions.AI.Evaluation" Version="9.10.0" />
<PackageVersion Include="Microsoft.Extensions.AI.Evaluation.Quality" Version="9.10.0" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.0-preview.1.25513.3" />
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.4.0-preview.3" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.9" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.9" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="10.0.1" />
<PackageVersion Include="Microsoft.Extensions.AI.Evaluation" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.AI.Evaluation.Quality" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="10.0.1-preview.1.25571.5" />
<PackageVersion Include="ModelContextProtocol" Version="0.5.0-preview.1" />
<PackageVersion Include="ModelContextProtocol.AspNetCore" Version="0.5.0-preview.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0" />
<PackageVersion Include="Microsoft.Identity.Abstractions" Version="9.5.0" />
<PackageVersion Include="Microsoft.Identity.Web" Version="4.0.1" />
<PackageVersion Include="Microsoft.Identity.Web.Azure" Version="4.0.1" />
<PackageVersion Include="Microsoft.HybridRow" Version="1.1.0-preview3" />
<PackageVersion Include="Microsoft.Azure.Cosmos.Aot" Version="0.1.4-preview.2" />
<PackageVersion Include="Microsoft.Azure.Mcp.AzTypes.Internal.Compact" Version="0.2.802" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.9" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageVersion Include="MySqlConnector" Version="2.4.0" />
<PackageVersion Include="Npgsql" Version="9.0.3" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-rc.1.25451.107" />
<PackageVersion Include="System.Formats.Asn1" Version="9.0.9" />
<PackageVersion Include="System.CommandLine" Version="2.0.0" />
<PackageVersion Include="System.Formats.Asn1" Version="10.0.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.0-rc.1.25451.107" />
<PackageVersion Include="System.Net.ServerSentEvents" Version="10.0.0-rc.1.25451.107" />
<PackageVersion Include="System.Numerics.Tensors" Version="9.0.0" />
<PackageVersion Include="System.Text.Json" Version="9.0.9" />
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.0" />
<PackageVersion Include="System.Net.ServerSentEvents" Version="10.0.0" />
<PackageVersion Include="System.Numerics.Tensors" Version="10.0.0" />
<PackageVersion Include="System.Text.Json" Version="10.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.3.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.11.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.0" />
<PackageVersion Include="Azure.Search.Documents" Version="11.7.0-beta.7" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static BaseToolLoader()
/// </returns>
protected static JsonElement GetParametersJsonElement(RequestContext<CallToolRequestParams> request)
{
IReadOnlyDictionary<string, JsonElement>? args = request.Params?.Arguments;
IDictionary<string, JsonElement>? args = request.Params?.Arguments;
if (args != null && args.TryGetValue("parameters", out var parametersElem) && parametersElem.ValueKind == JsonValueKind.Object)
{
return parametersElem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private async Task<CallToolResult> InvokeChildToolAsync(
string? intent,
string namespaceName,
string command,
IReadOnlyDictionary<string, JsonElement> parameters,
IDictionary<string, JsonElement> parameters,
CancellationToken cancellationToken)
{
if (request.Params == null)
Expand Down Expand Up @@ -458,7 +458,7 @@ private async Task<CallToolResult> InvokeToolLearn(RequestContext<CallToolReques
if (SupportsSampling(request.Server) && !string.IsNullOrWhiteSpace(intent))
{
var availableTools = GetChildToolList(request, namespaceName);
(string? commandName, IReadOnlyDictionary<string, JsonElement> parameters) = await GetCommandAndParametersFromIntentAsync(request, intent, namespaceName, availableTools, cancellationToken);
(string? commandName, IDictionary<string, JsonElement> parameters) = await GetCommandAndParametersFromIntentAsync(request, intent, namespaceName, availableTools, cancellationToken);
if (commandName != null)
{
response = await InvokeChildToolAsync(request, intent, namespaceName, commandName, parameters, cancellationToken);
Expand Down Expand Up @@ -586,7 +586,7 @@ private static bool IsRawMcpToolInputOption(Option option)
string.Equals(NameNormalization.NormalizeOptionName(alias), RawMcpToolInputOptionName, StringComparison.OrdinalIgnoreCase));
}

private static IReadOnlyDictionary<string, JsonElement> GetParametersFromArgs(IReadOnlyDictionary<string, JsonElement>? args)
private static Dictionary<string, JsonElement> GetParametersFromArgs(IDictionary<string, JsonElement>? args)
{
if (args == null || !args.TryGetValue("parameters", out var paramsElem))
{
Expand Down Expand Up @@ -620,10 +620,10 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
{
Progress = 0f,
Message = message,
}, cancellationToken);
}, cancellationToken: cancellationToken);
}

private async Task<(string? commandName, IReadOnlyDictionary<string, JsonElement> parameters)> GetCommandAndParametersFromIntentAsync(
private async Task<(string? commandName, Dictionary<string, JsonElement> parameters)> GetCommandAndParametersFromIntentAsync(
RequestContext<CallToolRequestParams> request,
string intent,
string namespaceName,
Expand All @@ -638,11 +638,12 @@ await request.Server.NotifyProgressAsync(progressToken.Value,

var samplingRequest = new CreateMessageRequestParams
{
MaxTokens = 1000,
Messages = [
new SamplingMessage
{
Role = Role.Assistant,
Content = new TextContentBlock{
Content = [new TextContentBlock{
Text = $"""
This is a list of available commands for the {namespaceName} server.

Expand All @@ -666,17 +667,17 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
Available Commands:
{availableToolsJson}
"""
}
}]
}
],
};
try
{
var samplingResponse = await request.Server.SampleAsync(samplingRequest, cancellationToken);
var samplingContent = samplingResponse.Content as TextContentBlock;
var samplingContent = samplingResponse.Content is { Count: > 0 } ? samplingResponse.Content[0] as TextContentBlock : null;
var toolCallJson = samplingContent?.Text?.Trim();
string? commandName = null;
IReadOnlyDictionary<string, JsonElement> parameters = new Dictionary<string, JsonElement>();
var parameters = new Dictionary<string, JsonElement>();

if (!string.IsNullOrEmpty(toolCallJson))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override async ValueTask<CallToolResult> CallToolHandler(RequestContext<C
/// </summary>
/// <param name="args">The arguments to transform to parameters.</param>
/// <returns>A dictionary of parameter names and values compatible with McpClientExtensions.CallToolAsync.</returns>
private static Dictionary<string, object?> TransformArgumentsToDictionary(IReadOnlyDictionary<string, JsonElement>? args)
private static Dictionary<string, object?> TransformArgumentsToDictionary(IDictionary<string, JsonElement>? args)
{
if (args == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
{
Progress = 0f,
Message = message,
}, cancellationToken);
}, cancellationToken: cancellationToken);
}
private async Task<(string? commandName, Dictionary<string, object?> parameters)> GetCommandAndParametersFromIntentAsync(
RequestContext<CallToolRequestParams> request,
Expand All @@ -456,11 +456,12 @@ await request.Server.NotifyProgressAsync(progressToken.Value,

var samplingRequest = new CreateMessageRequestParams
{
MaxTokens = 1000,
Messages = [
new SamplingMessage
{
Role = Role.Assistant,
Content = new TextContentBlock{
Content = [new TextContentBlock{
Text = $"""
This is a list of available commands for the {tool} server.

Expand All @@ -484,14 +485,14 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
Available Commands:
{availableToolsJson}
"""
}
}]
}
],
};
try
{
var samplingResponse = await request.Server.SampleAsync(samplingRequest, cancellationToken);
var samplingContent = samplingResponse.Content as TextContentBlock;
var samplingContent = samplingResponse.Content is { Count: > 0 } ? samplingResponse.Content[0] as TextContentBlock : null;
var toolCallJson = samplingContent?.Text?.Trim();
string? commandName = null;
Dictionary<string, object?> parameters = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
{
Progress = 0f,
Message = message,
}, cancellationToken);
}, cancellationToken: cancellationToken);
}

private async Task<string?> GetToolNameFromIntentAsync(RequestContext<CallToolRequestParams> request, string intent, string toolsJson, CancellationToken cancellationToken)
Expand All @@ -366,11 +366,12 @@ await request.Server.NotifyProgressAsync(progressToken.Value,

var samplingRequest = new CreateMessageRequestParams
{
MaxTokens = 1000,
Messages = [
new SamplingMessage
{
Role = Role.Assistant,
Content = new TextContentBlock{
Content = [new TextContentBlock{
Text = $"""
The following is a list of available tools for the Azure server.

Expand All @@ -385,14 +386,14 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
Available Tools:
{toolsJson}
"""
}
}]
}
],
};
try
{
var samplingResponse = await request.Server.SampleAsync(samplingRequest, cancellationToken);
var samplingContent = samplingResponse.Content as TextContentBlock;
var samplingContent = samplingResponse.Content is { Count: > 0 } ? samplingResponse.Content[0] as TextContentBlock : null;
var toolName = samplingContent?.Text?.Trim();
if (!string.IsNullOrEmpty(toolName) && toolName != "Unknown")
{
Expand Down Expand Up @@ -421,11 +422,12 @@ await request.Server.NotifyProgressAsync(progressToken.Value,

var samplingRequest = new CreateMessageRequestParams
{
MaxTokens = 1000,
Messages = [
new SamplingMessage
{
Role = Role.Assistant,
Content = new TextContentBlock{
Content = [new TextContentBlock{
Text = $"""
This is a list of available commands for the {tool} server.

Expand All @@ -449,14 +451,14 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
Available Commands:
{toolsJson}
"""
}
}]
}
],
};
try
{
var samplingResponse = await request.Server.SampleAsync(samplingRequest, cancellationToken);
var samplingContent = samplingResponse.Content as TextContentBlock;
var samplingContent = samplingResponse.Content is { Count: > 0 } ? samplingResponse.Content[0] as TextContentBlock : null;
var toolCallJson = samplingContent?.Text?.Trim();
string? commandName = null;
Dictionary<string, object?> parameters = [];
Expand Down
4 changes: 2 additions & 2 deletions core/Azure.Mcp.Core/src/Commands/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class CommandExtensions
/// <param name="command">The command to parse options for</param>
/// <param name="arguments">Dictionary of argument name/value pairs</param>
/// <returns>ParseResult containing the parsed arguments</returns>
public static ParseResult ParseFromDictionary(this Command command, IReadOnlyDictionary<string, JsonElement>? arguments)
public static ParseResult ParseFromDictionary(this Command command, IDictionary<string, JsonElement>? arguments)
{
if (arguments == null || arguments.Count == 0)
{
Expand Down Expand Up @@ -75,7 +75,7 @@ public static ParseResult ParseFromDictionary(this Command command, IReadOnlyDic
return command.Parse([.. args]);
}

public static ParseResult ParseFromRawMcpToolInput(this Command command, IReadOnlyDictionary<string, JsonElement>? arguments)
public static ParseResult ParseFromRawMcpToolInput(this Command command, IDictionary<string, JsonElement>? arguments)
{
var args = new List<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task Should_Error_When_Resources_Unsubscribe_Not_Supported()
[Fact]
public async Task Should_Not_Hang_On_Logging_SetLevel_Not_Supported()
{
await Client.SetLoggingLevel(LoggingLevel.Info, cancellationToken: TestContext.Current.CancellationToken);
await Client.SetLoggingLevelAsync(LoggingLevel.Info, cancellationToken: TestContext.Current.CancellationToken);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static RequestContext<ListToolsRequestParams> CreateListToolsRequest()
};
}

private static RequestContext<CallToolRequestParams> CreateCallToolRequest(string toolName = "test-tool", IReadOnlyDictionary<string, JsonElement>? arguments = null)
private static RequestContext<CallToolRequestParams> CreateCallToolRequest(string toolName = "test-tool", IDictionary<string, JsonElement>? arguments = null)
{
return new RequestContext<CallToolRequestParams>(CreateMockServer(), new() { Method = RequestMethods.ToolsCall })
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ public async Task CreateClientOptions_SamplingHandler_DelegatesToServerSendReque

var samplingRequest = new CreateMessageRequestParams
{
MaxTokens = 1000,
Messages =
[
new SamplingMessage
{
Role = Role.User,
Content = new TextContentBlock { Text = "Test message" }
Content = [new TextContentBlock { Text = "Test message" }]
}
]
};
Expand All @@ -208,7 +209,7 @@ public async Task CreateClientOptions_SamplingHandler_DelegatesToServerSendReque
Result = JsonSerializer.SerializeToNode(new CreateMessageResult
{
Role = Role.Assistant,
Content = new TextContentBlock { Text = "Mock response" },
Content = [new TextContentBlock { Text = "Mock response" }],
Model = "test-model"
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static RequestContext<ListToolsRequestParams> CreateListToolsRequest()
};
}

private static RequestContext<CallToolRequestParams> CreateCallToolRequest(string toolName, IReadOnlyDictionary<string, JsonElement>? arguments = null)
private static RequestContext<CallToolRequestParams> CreateCallToolRequest(string toolName, IDictionary<string, JsonElement>? arguments = null)
{
var mockServer = Substitute.For<McpServer>();
return new RequestContext<CallToolRequestParams>(mockServer, new() { Method = RequestMethods.ToolsCall })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static ModelContextProtocol.Server.RequestContext<ListToolsRequestParams
};
}

private static ModelContextProtocol.Server.RequestContext<CallToolRequestParams> CreateCallToolRequest(string toolName, IReadOnlyDictionary<string, JsonElement>? arguments = null)
private static ModelContextProtocol.Server.RequestContext<CallToolRequestParams> CreateCallToolRequest(string toolName, IDictionary<string, JsonElement>? arguments = null)
{
var mockServer = Substitute.For<ModelContextProtocol.Server.McpServer>();
return new ModelContextProtocol.Server.RequestContext<CallToolRequestParams>(mockServer, new() { Method = RequestMethods.ToolsCall })
Expand Down
Loading
Loading