Restructure IMcpEndpoint, IMcpClient, and IMcpServer (#723)
* Remove `McpEndpoint` & `IMcpClient` * Revise naming, add abstract classes * Fix missing renames * Move extension methods to instance methods * Add back old API, but obsoleted * Add back obsoleted factory classes * Move deprecation attributes * `SseClientTransport` -> `HttpClientTransport` * Update src/ModelContextProtocol.Core/Server/AugmentedServiceProvider.cs Co-authored-by: Stephen Halter <halter73@gmail.com> * PR feedback * PR feedback * Add back dispose lock * Fix docs projects * PR feedback * Undo `docs/*.md` changes --------- Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
parent
fe2ce2bc60
commit
38b4a26998
5 changed files with 5169 additions and 3786 deletions
|
|
@ -4,7 +4,7 @@ using ModelContextProtocol.Protocol;
|
|||
|
||||
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
|
||||
|
||||
var clientTransport = new SseClientTransport(new()
|
||||
var clientTransport = new HttpClientTransport(new()
|
||||
{
|
||||
Endpoint = new Uri(endpoint),
|
||||
TransportMode = HttpTransportMode.StreamableHttp,
|
||||
|
|
@ -27,7 +27,7 @@ McpClientOptions options = new()
|
|||
}
|
||||
};
|
||||
|
||||
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport, options);
|
||||
await using var mcpClient = await McpClient.CreateAsync(clientTransport, options);
|
||||
// </snippet_McpInitialize>
|
||||
|
||||
var tools = await mcpClient.ListToolsAsync();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public sealed class InteractiveTools
|
|||
// <snippet_GuessTheNumber>
|
||||
[McpServerTool, Description("A simple game where the user has to guess a number between 1 and 10.")]
|
||||
public async Task<string> GuessTheNumber(
|
||||
IMcpServer server, // Get the McpServer from DI container
|
||||
McpServer server, // Get the McpServer from DI container
|
||||
CancellationToken token
|
||||
)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ using System.Text.Json;
|
|||
|
||||
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
|
||||
|
||||
var clientTransport = new SseClientTransport(new()
|
||||
var clientTransport = new HttpClientTransport(new()
|
||||
{
|
||||
Endpoint = new Uri(endpoint),
|
||||
TransportMode = HttpTransportMode.StreamableHttp,
|
||||
});
|
||||
|
||||
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport);
|
||||
await using var mcpClient = await McpClient.CreateAsync(clientTransport);
|
||||
|
||||
// <snippet_LoggingCapabilities>
|
||||
// Verify that the server supports logging
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using ModelContextProtocol.Protocol;
|
|||
|
||||
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
|
||||
|
||||
var clientTransport = new SseClientTransport(new()
|
||||
var clientTransport = new HttpClientTransport(new()
|
||||
{
|
||||
Endpoint = new Uri(endpoint),
|
||||
TransportMode = HttpTransportMode.StreamableHttp,
|
||||
|
|
@ -20,7 +20,7 @@ McpClientOptions options = new()
|
|||
}
|
||||
};
|
||||
|
||||
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport, options);
|
||||
await using var mcpClient = await McpClient.CreateAsync(clientTransport, options);
|
||||
|
||||
var tools = await mcpClient.ListToolsAsync();
|
||||
foreach (var tool in tools)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class LongRunningTools
|
|||
{
|
||||
[McpServerTool, Description("Demonstrates a long running tool with progress updates")]
|
||||
public static async Task<string> LongRunningTool(
|
||||
IMcpServer server,
|
||||
McpServer server,
|
||||
RequestContext<CallToolRequestParams> context,
|
||||
int duration = 10,
|
||||
int steps = 5)
|
||||
|
|
|
|||
Loading…
Reference in a new issue