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
10 changed files with 5169 additions and 3786 deletions
|
|
@ -12,7 +12,7 @@ public sealed class SampleLlmTool
|
|||
{
|
||||
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
|
||||
public static async Task<string> SampleLLM(
|
||||
IMcpServer thisServer,
|
||||
McpServer thisServer,
|
||||
[Description("The prompt to send to the LLM")] string prompt,
|
||||
[Description("Maximum number of tokens to generate")] int maxTokens,
|
||||
CancellationToken cancellationToken)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ using IChatClient samplingClient = openAIClient.AsIChatClient()
|
|||
.UseOpenTelemetry(loggerFactory: loggerFactory, configure: o => o.EnableSensitiveData = true)
|
||||
.Build();
|
||||
|
||||
var mcpClient = await McpClientFactory.CreateAsync(
|
||||
var mcpClient = await McpClient.CreateAsync(
|
||||
new StdioClientTransport(new()
|
||||
{
|
||||
Command = "npx",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using ModelContextProtocol.Server;
|
|||
|
||||
namespace EverythingServer;
|
||||
|
||||
public class LoggingUpdateMessageSender(IMcpServer server, Func<LoggingLevel> getMinLevel) : BackgroundService
|
||||
public class LoggingUpdateMessageSender(McpServer server, Func<LoggingLevel> getMinLevel) : BackgroundService
|
||||
{
|
||||
readonly Dictionary<LoggingLevel, string> _loggingLevelMap = new()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using ModelContextProtocol;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
internal class SubscriptionMessageSender(IMcpServer server, HashSet<string> subscriptions) : BackgroundService
|
||||
internal class SubscriptionMessageSender(McpServer server, HashSet<string> subscriptions) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class LongRunningTool
|
|||
{
|
||||
[McpServerTool(Name = "longRunningOperation"), Description("Demonstrates a long running operation with progress updates")]
|
||||
public static async Task<string> LongRunningOperation(
|
||||
IMcpServer server,
|
||||
McpServer server,
|
||||
RequestContext<CallToolRequestParams> context,
|
||||
int duration = 10,
|
||||
int steps = 5)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public class SampleLlmTool
|
|||
{
|
||||
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
|
||||
public static async Task<string> SampleLLM(
|
||||
IMcpServer server,
|
||||
McpServer server,
|
||||
[Description("The prompt to send to the LLM")] string prompt,
|
||||
[Description("Maximum number of tokens to generate")] int maxTokens,
|
||||
CancellationToken cancellationToken)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.IO.Pipelines;
|
|||
Pipe clientToServerPipe = new(), serverToClientPipe = new();
|
||||
|
||||
// Create a server using a stream-based transport over an in-memory pipe.
|
||||
await using IMcpServer server = McpServerFactory.Create(
|
||||
await using McpServer server = McpServer.Create(
|
||||
new StreamServerTransport(clientToServerPipe.Reader.AsStream(), serverToClientPipe.Writer.AsStream()),
|
||||
new McpServerOptions()
|
||||
{
|
||||
|
|
@ -21,7 +21,7 @@ await using IMcpServer server = McpServerFactory.Create(
|
|||
_ = server.RunAsync();
|
||||
|
||||
// Connect a client using a stream-based transport over the same in-memory pipe.
|
||||
await using IMcpClient client = await McpClientFactory.CreateAsync(
|
||||
await using McpClient client = await McpClient.CreateAsync(
|
||||
new StreamClientTransport(clientToServerPipe.Writer.AsStream(), serverToClientPipe.Reader.AsStream()));
|
||||
|
||||
// List all tools.
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ var consoleLoggerFactory = LoggerFactory.Create(builder =>
|
|||
builder.AddConsole();
|
||||
});
|
||||
|
||||
var transport = new SseClientTransport(new()
|
||||
var transport = new HttpClientTransport(new()
|
||||
{
|
||||
Endpoint = new Uri(serverUrl),
|
||||
Name = "Secure Weather Client",
|
||||
|
|
@ -40,7 +40,7 @@ var transport = new SseClientTransport(new()
|
|||
}
|
||||
}, httpClient, consoleLoggerFactory);
|
||||
|
||||
var client = await McpClientFactory.CreateAsync(transport, loggerFactory: consoleLoggerFactory);
|
||||
var client = await McpClient.CreateAsync(transport, loggerFactory: consoleLoggerFactory);
|
||||
|
||||
var tools = await client.ListToolsAsync();
|
||||
if (tools.Count == 0)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ var (command, arguments) = GetCommandAndArguments(args);
|
|||
if (command == "http")
|
||||
{
|
||||
// make sure AspNetCoreMcpServer is running
|
||||
clientTransport = new SseClientTransport(new()
|
||||
clientTransport = new HttpClientTransport(new()
|
||||
{
|
||||
Endpoint = new Uri("http://localhost:3001")
|
||||
});
|
||||
|
|
@ -33,7 +33,7 @@ else
|
|||
Arguments = arguments,
|
||||
});
|
||||
}
|
||||
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport!);
|
||||
await using var mcpClient = await McpClient.CreateAsync(clientTransport!);
|
||||
|
||||
var tools = await mcpClient.ListToolsAsync();
|
||||
foreach (var tool in tools)
|
||||
|
|
@ -62,7 +62,7 @@ var messages = new List<ChatMessage>();
|
|||
var sb = new StringBuilder();
|
||||
|
||||
PromptForInput();
|
||||
while(Console.ReadLine() is string query && !"exit".Equals(query, StringComparison.OrdinalIgnoreCase))
|
||||
while (Console.ReadLine() is string query && !"exit".Equals(query, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public sealed class SampleLlmTool
|
|||
{
|
||||
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
|
||||
public static async Task<string> SampleLLM(
|
||||
IMcpServer thisServer,
|
||||
McpServer thisServer,
|
||||
[Description("The prompt to send to the LLM")] string prompt,
|
||||
[Description("Maximum number of tokens to generate")] int maxTokens,
|
||||
CancellationToken cancellationToken)
|
||||
|
|
|
|||
Loading…
Reference in a new issue