Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Microsoft.Extensions.Logging;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;

namespace Azure.Mcp.Core.Areas.Server.Commands.ToolLoading;
Expand Down Expand Up @@ -45,7 +46,7 @@ public abstract class BaseToolLoader(ILogger logger) : IToolLoader
/// </summary>
/// <param name="request">The request context containing the tool call parameters.</param>
/// <returns>
/// The "parameters" JsonElement if it exists and is a valid JSON object;
/// The "parameters" JsonElement if it exists and is a valid JSON object;
/// otherwise, returns an empty JSON object.
/// </returns>
protected static JsonElement GetParametersJsonElement(RequestContext<CallToolRequestParams> request)
Expand Down Expand Up @@ -109,4 +110,46 @@ protected virtual ValueTask DisposeAsyncCore()
// Default implementation does nothing
return ValueTask.CompletedTask;
}

protected McpClientOptions CreateClientOptions(IMcpServer server)
{
SamplingCapability? samplingCapability = null;
ElicitationCapability? elicitationCapability = null;

if (server.ClientCapabilities?.Sampling != null)
{
samplingCapability = new SamplingCapability
{
SamplingHandler = (request, progress, token) =>
{
ArgumentNullException.ThrowIfNull(request);
return server.SampleAsync(request, token);
}
};
}

if (server.ClientCapabilities?.Elicitation != null)
{
elicitationCapability = new ElicitationCapability
{
ElicitationHandler = (request, token) =>
{
ArgumentNullException.ThrowIfNull(request);
return server.ElicitAsync(request, token);
}
};
}

var clientOptions = new McpClientOptions
{
ClientInfo = server.ClientInfo,
Capabilities = new ClientCapabilities
{
Sampling = samplingCapability,
Elicitation = elicitationCapability,
}
};

return clientOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,6 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
return (null, new Dictionary<string, object?>());
}

private McpClientOptions CreateClientOptions(IMcpServer server)
{
var clientOptions = new McpClientOptions
{
ClientInfo = server.ClientInfo,
Capabilities = new ClientCapabilities(),
};

return clientOptions;
}

/// <summary>
/// Disposes resources owned by this tool loader.
/// Clears the cached tool lists dictionary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,6 @@ await request.Server.NotifyProgressAsync(progressToken.Value,
return (null, new Dictionary<string, object?>());
}

private McpClientOptions CreateClientOptions(IMcpServer server)
{
var clientOptions = new McpClientOptions
{
ClientInfo = server.ClientInfo,
Capabilities = new ClientCapabilities(),
};

return clientOptions;
}

/// <summary>
/// Disposes resources owned by this tool loader.
/// Clears the cached tool lists and root tools dictionaries.
Expand Down
Loading