Skip to content

Commit 38b4a26

Browse files
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 <[email protected]> * PR feedback * PR feedback * Add back dispose lock * Fix docs projects * PR feedback * Undo `docs/*.md` changes --------- Co-authored-by: Stephen Halter <[email protected]>
1 parent fe2ce2b commit 38b4a26

File tree

115 files changed

+5169
-3786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+5169
-3786
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ dotnet add package ModelContextProtocol --prerelease
3737

3838
## Getting Started (Client)
3939

40-
To get started writing a client, the `McpClientFactory.CreateAsync` method is used to instantiate and connect an `IMcpClient`
41-
to a server. Once you have an `IMcpClient`, you can interact with it, such as to enumerate all available tools and invoke tools.
40+
To get started writing a client, the `McpClient.CreateAsync` method is used to instantiate and connect an `McpClient`
41+
to a server. Once you have an `McpClient`, you can interact with it, such as to enumerate all available tools and invoke tools.
4242

4343
```csharp
4444
var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
@@ -48,7 +48,7 @@ var clientTransport = new StdioClientTransport(new StdioClientTransportOptions
4848
Arguments = ["-y", "@modelcontextprotocol/server-everything"],
4949
});
5050

51-
var client = await McpClientFactory.CreateAsync(clientTransport);
51+
var client = await McpClient.CreateAsync(clientTransport);
5252

5353
// Print the list of tools available from the server.
5454
foreach (var tool in await client.ListToolsAsync())
@@ -122,14 +122,14 @@ public static class EchoTool
122122
}
123123
```
124124

125-
Tools can have the `IMcpServer` representing the server injected via a parameter to the method, and can use that for interaction with
125+
Tools can have the `McpServer` representing the server injected via a parameter to the method, and can use that for interaction with
126126
the connected client. Similarly, arguments may be injected via dependency injection. For example, this tool will use the supplied
127-
`IMcpServer` to make sampling requests back to the client in order to summarize content it downloads from the specified url via
127+
`McpServer` to make sampling requests back to the client in order to summarize content it downloads from the specified url via
128128
an `HttpClient` injected via dependency injection.
129129
```csharp
130130
[McpServerTool(Name = "SummarizeContentFromUrl"), Description("Summarizes content downloaded from a specific URI")]
131131
public static async Task<string> SummarizeDownloadedContent(
132-
IMcpServer thisServer,
132+
McpServer thisServer,
133133
HttpClient httpClient,
134134
[Description("The url from which to download the content to summarize")] string url,
135135
CancellationToken cancellationToken)
@@ -224,7 +224,7 @@ McpServerOptions options = new()
224224
},
225225
};
226226

227-
await using IMcpServer server = McpServerFactory.Create(new StdioServerTransport("MyServer"), options);
227+
await using McpServer server = McpServer.Create(new StdioServerTransport("MyServer"), options);
228228
await server.RunAsync();
229229
```
230230

docs/concepts/elicitation/samples/client/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
66

7-
var clientTransport = new SseClientTransport(new()
7+
var clientTransport = new HttpClientTransport(new()
88
{
99
Endpoint = new Uri(endpoint),
1010
TransportMode = HttpTransportMode.StreamableHttp,
@@ -27,7 +27,7 @@
2727
}
2828
};
2929

30-
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport, options);
30+
await using var mcpClient = await McpClient.CreateAsync(clientTransport, options);
3131
// </snippet_McpInitialize>
3232

3333
var tools = await mcpClient.ListToolsAsync();

docs/concepts/elicitation/samples/server/Tools/InteractiveTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class InteractiveTools
1313
// <snippet_GuessTheNumber>
1414
[McpServerTool, Description("A simple game where the user has to guess a number between 1 and 10.")]
1515
public async Task<string> GuessTheNumber(
16-
IMcpServer server, // Get the McpServer from DI container
16+
McpServer server, // Get the McpServer from DI container
1717
CancellationToken token
1818
)
1919
{

docs/concepts/logging/samples/client/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
66

7-
var clientTransport = new SseClientTransport(new()
7+
var clientTransport = new HttpClientTransport(new()
88
{
99
Endpoint = new Uri(endpoint),
1010
TransportMode = HttpTransportMode.StreamableHttp,
1111
});
1212

13-
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport);
13+
await using var mcpClient = await McpClient.CreateAsync(clientTransport);
1414

1515
// <snippet_LoggingCapabilities>
1616
// Verify that the server supports logging

docs/concepts/progress/samples/client/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
var endpoint = Environment.GetEnvironmentVariable("ENDPOINT") ?? "http://localhost:3001";
77

8-
var clientTransport = new SseClientTransport(new()
8+
var clientTransport = new HttpClientTransport(new()
99
{
1010
Endpoint = new Uri(endpoint),
1111
TransportMode = HttpTransportMode.StreamableHttp,
@@ -20,7 +20,7 @@
2020
}
2121
};
2222

23-
await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport, options);
23+
await using var mcpClient = await McpClient.CreateAsync(clientTransport, options);
2424

2525
var tools = await mcpClient.ListToolsAsync();
2626
foreach (var tool in tools)

docs/concepts/progress/samples/server/Tools/LongRunningTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class LongRunningTools
1010
{
1111
[McpServerTool, Description("Demonstrates a long running tool with progress updates")]
1212
public static async Task<string> LongRunningTool(
13-
IMcpServer server,
13+
McpServer server,
1414
RequestContext<CallToolRequestParams> context,
1515
int duration = 10,
1616
int steps = 5)

samples/AspNetCoreMcpServer/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class SampleLlmTool
1212
{
1313
[McpServerTool(Name = "sampleLLM"), Description("Samples from an LLM using MCP's sampling feature")]
1414
public static async Task<string> SampleLLM(
15-
IMcpServer thisServer,
15+
McpServer thisServer,
1616
[Description("The prompt to send to the LLM")] string prompt,
1717
[Description("Maximum number of tokens to generate")] int maxTokens,
1818
CancellationToken cancellationToken)

samples/ChatWithTools/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
.UseOpenTelemetry(loggerFactory: loggerFactory, configure: o => o.EnableSensitiveData = true)
3333
.Build();
3434

35-
var mcpClient = await McpClientFactory.CreateAsync(
35+
var mcpClient = await McpClient.CreateAsync(
3636
new StdioClientTransport(new()
3737
{
3838
Command = "npx",

samples/EverythingServer/LoggingUpdateMessageSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace EverythingServer;
77

8-
public class LoggingUpdateMessageSender(IMcpServer server, Func<LoggingLevel> getMinLevel) : BackgroundService
8+
public class LoggingUpdateMessageSender(McpServer server, Func<LoggingLevel> getMinLevel) : BackgroundService
99
{
1010
readonly Dictionary<LoggingLevel, string> _loggingLevelMap = new()
1111
{

samples/EverythingServer/SubscriptionMessageSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using ModelContextProtocol;
33
using ModelContextProtocol.Server;
44

5-
internal class SubscriptionMessageSender(IMcpServer server, HashSet<string> subscriptions) : BackgroundService
5+
internal class SubscriptionMessageSender(McpServer server, HashSet<string> subscriptions) : BackgroundService
66
{
77
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
88
{

0 commit comments

Comments
 (0)