Skip to content

Commit 32a777a

Browse files
committed
Add back obsoleted factory classes
1 parent 36dd101 commit 32a777a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.Extensions.Logging;
2+
3+
namespace ModelContextProtocol.Client;
4+
5+
/// <summary>
6+
/// Provides factory methods for creating Model Context Protocol (MCP) clients.
7+
/// </summary>
8+
/// <remarks>
9+
/// This factory class is the primary way to instantiate <see cref="IMcpClient"/> instances
10+
/// that connect to MCP servers. It handles the creation and connection
11+
/// of appropriate implementations through the supplied transport.
12+
/// </remarks>
13+
public static partial class McpClientFactory
14+
{
15+
/// <summary>Creates an <see cref="IMcpClient"/>, connecting it to the specified server.</summary>
16+
/// <param name="clientTransport">The transport instance used to communicate with the server.</param>
17+
/// <param name="clientOptions">
18+
/// A client configuration object which specifies client capabilities and protocol version.
19+
/// If <see langword="null"/>, details based on the current process will be employed.
20+
/// </param>
21+
/// <param name="loggerFactory">A logger factory for creating loggers for clients.</param>
22+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
23+
/// <returns>An <see cref="IMcpClient"/> that's connected to the specified server.</returns>
24+
/// <exception cref="ArgumentNullException"><paramref name="clientTransport"/> is <see langword="null"/>.</exception>
25+
/// <exception cref="ArgumentNullException"><paramref name="clientOptions"/> is <see langword="null"/>.</exception>
26+
[Obsolete($"Use {nameof(McpClient)}.{nameof(McpClient.CreateAsync)} instead.")]
27+
public static async Task<IMcpClient> CreateAsync(
28+
IClientTransport clientTransport,
29+
McpClientOptions? clientOptions = null,
30+
ILoggerFactory? loggerFactory = null,
31+
CancellationToken cancellationToken = default)
32+
=> await McpClient.CreateAsync(clientTransport, clientOptions, loggerFactory, cancellationToken);
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.Extensions.Logging;
2+
using ModelContextProtocol.Protocol;
3+
4+
namespace ModelContextProtocol.Server;
5+
6+
/// <summary>
7+
/// Provides a factory for creating <see cref="IMcpServer"/> instances.
8+
/// </summary>
9+
/// <remarks>
10+
/// This is the recommended way to create <see cref="IMcpServer"/> instances.
11+
/// The factory handles proper initialization of server instances with the required dependencies.
12+
/// </remarks>
13+
public static class McpServerFactory
14+
{
15+
/// <summary>
16+
/// Creates a new instance of an <see cref="IMcpServer"/>.
17+
/// </summary>
18+
/// <param name="transport">Transport to use for the server representing an already-established MCP session.</param>
19+
/// <param name="serverOptions">Configuration options for this server, including capabilities. </param>
20+
/// <param name="loggerFactory">Logger factory to use for logging. If null, logging will be disabled.</param>
21+
/// <param name="serviceProvider">Optional service provider to create new instances of tools and other dependencies.</param>
22+
/// <returns>An <see cref="IMcpServer"/> instance that should be disposed when no longer needed.</returns>
23+
/// <exception cref="ArgumentNullException"><paramref name="transport"/> is <see langword="null"/>.</exception>
24+
/// <exception cref="ArgumentNullException"><paramref name="serverOptions"/> is <see langword="null"/>.</exception>
25+
[Obsolete($"Use {nameof(McpServer)}.{nameof(McpServer.Create)} instead.")]
26+
public static IMcpServer Create(
27+
ITransport transport,
28+
McpServerOptions serverOptions,
29+
ILoggerFactory? loggerFactory = null,
30+
IServiceProvider? serviceProvider = null)
31+
=> McpServer.Create(transport, serverOptions, loggerFactory, serviceProvider);
32+
}

0 commit comments

Comments
 (0)