Remove the hosting and options dependencies from the ModelContextProtocol package #428
+99
−123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I started this change trying to keep the IMcpServerBuilder in the ModelContextProtocol package even after removing these dependencies, and while this is technically possible, it comes with too many downsides. Some of these we already knew, like the fact that anyone using AddMcpServer would still have to manually run the server (possibly via their own hosted service) after they built the ServiceProvider/Host.
However, the biggest issue, and the one that made me step back and reevaluate the approach was that the
IMcpServer
that gets registered by methods like WithStdioServerTransport via AddSingleSessionServerDependencies would not get any options configured using the options pattern unless someone knows to manually set up a new IMcpServer registration to read fromIOptions<McpServerOptions>
.I considered keeping
AddMcpServer(this IServiceCollection services, Action<McpServerOptions>? configureOptions = null)
in the ModelContextProtocol package and just removing theconfigureOptions
parameter. It'd then be possible to just add an overload in the AspNetCore package that does takeconfigureOptions
, but that would make things worse in my opinion. This would mean thatbuilder.Services.Configure<McpServerOptions>(options => { })
would only work if you called the overload in the AspNetCore package which I think would be extremely confusing.As ModelContextProtocol.TestServer demonstrates, you can still write a stdio server with just the ModelContextProtocol package, so I do like this change over removing the server completely from the core package. However, I do realize that it's far less convenient to configure a stdio server without the IMcpServerBuilder, and people writing stdio-only servers likely won't want the AspNetCore framework reference.
I think the best solution would be to introduce a ModelContextProtocol.Hosting package that is basically the same as what ModelContextProtocol was previously and depends on the ModelContextProtocol package as it is in this PR. So we'd have three packages:
This possibly helps address some concerns about dependency bloat for clients raised in #369 @KrzysztofCwalina.