diff --git a/docs/concepts/apps/apps.md b/docs/concepts/apps/apps.md index 0c3ef1ab2..912ebf040 100644 --- a/docs/concepts/apps/apps.md +++ b/docs/concepts/apps/apps.md @@ -16,12 +16,14 @@ uid: apps ## Installation -MCP Apps is provided in the `ModelContextProtocol.Extensions.Apps` package, which layers on top of the core SDK: +MCP Apps is provided in the `ModelContextProtocol.Extensions.Apps` package, which depends only on `ModelContextProtocol.Core`: ```shell dotnet add package ModelContextProtocol.Extensions.Apps ``` +To host a server, also reference `ModelContextProtocol` (for `AddMcpServer()`) or `ModelContextProtocol.AspNetCore` (for HTTP transports). + ## Overview The MCP Apps extension introduces the concept of **UI resources** — HTML pages served by the MCP server that a client can display alongside the conversation. Tools can be associated with a UI resource so the client knows which interface to show when a tool is called. diff --git a/docs/concepts/skills/skills.md b/docs/concepts/skills/skills.md index b4c2d6e91..d6845c9d4 100644 --- a/docs/concepts/skills/skills.md +++ b/docs/concepts/skills/skills.md @@ -17,6 +17,8 @@ methods for discovering skills and obtaining a verifiable manifest of their file Skills are provided by the `ModelContextProtocol.Extensions.Skills` package. The implementation follows the [Skills extension specification](https://github.com/modelcontextprotocol/ext-skills/blob/main/specification/beta/skills.mdx) (SEP-2640, extension id `io.modelcontextprotocol/skills`). +The package depends only on `ModelContextProtocol.Core`, so clients don't need the hosting dependencies. Servers also +reference `ModelContextProtocol` (for `AddMcpServer()`) or `ModelContextProtocol.AspNetCore`. > [!IMPORTANT] > Skills support is experimental. All public APIs use `[Experimental("MCPEXP005")]`; suppress that diagnostic diff --git a/docs/concepts/tasks/tasks.md b/docs/concepts/tasks/tasks.md index c1ab0c23a..3cc57f9bb 100644 --- a/docs/concepts/tasks/tasks.md +++ b/docs/concepts/tasks/tasks.md @@ -13,6 +13,9 @@ and the client polls for status, optionally exchanging additional input along th Tasks are provided by the `ModelContextProtocol.Extensions.Tasks` package and require MCP protocol version `2026-07-28` or later. The implementation follows [SEP-2663 (Tasks Extension)](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/seps/2663-tasks-extension.md). +The package depends only on `ModelContextProtocol.Core`, so clients don't need the hosting +dependencies. Servers also reference `ModelContextProtocol` (for `AddMcpServer()`) or +`ModelContextProtocol.AspNetCore`. ### Overview diff --git a/src/ModelContextProtocol/IMcpServerBuilder.cs b/src/ModelContextProtocol.Core/Server/IMcpServerBuilder.cs similarity index 62% rename from src/ModelContextProtocol/IMcpServerBuilder.cs rename to src/ModelContextProtocol.Core/Server/IMcpServerBuilder.cs index 016e9eb3e..db59c98c1 100644 --- a/src/ModelContextProtocol/IMcpServerBuilder.cs +++ b/src/ModelContextProtocol.Core/Server/IMcpServerBuilder.cs @@ -12,8 +12,12 @@ namespace Microsoft.Extensions.DependencyInjection; /// and server transports, allowing for comprehensive server configuration through a chain of method calls. /// /// -/// The builder is obtained from the extension -/// method and provides access to the underlying service collection via the property. +/// The builder is obtained from the AddMcpServer extension method in the ModelContextProtocol package +/// and provides access to the underlying service collection via the property. +/// +/// +/// This interface is defined in ModelContextProtocol.Core so that extension packages can add builder +/// extension methods without depending on the hosting implementation in the ModelContextProtocol package. /// /// public interface IMcpServerBuilder diff --git a/src/ModelContextProtocol.Core/Server/RequestContext.cs b/src/ModelContextProtocol.Core/Server/RequestContext.cs index 596712eea..6e4e5d997 100644 --- a/src/ModelContextProtocol.Core/Server/RequestContext.cs +++ b/src/ModelContextProtocol.Core/Server/RequestContext.cs @@ -8,7 +8,7 @@ namespace ModelContextProtocol.Server; /// Type of the request parameters specific to each MCP operation. /// /// The encapsulates all contextual information for handling an MCP request. -/// This type is typically received as a parameter in handler delegates registered with IMcpServerBuilder, +/// This type is typically received as a parameter in handler delegates registered with , /// and can be injected as parameters into s. /// public sealed class RequestContext : MessageContext diff --git a/src/ModelContextProtocol.Extensions.Apps/ModelContextProtocol.Extensions.Apps.csproj b/src/ModelContextProtocol.Extensions.Apps/ModelContextProtocol.Extensions.Apps.csproj index 604d7d824..4e803b430 100644 --- a/src/ModelContextProtocol.Extensions.Apps/ModelContextProtocol.Extensions.Apps.csproj +++ b/src/ModelContextProtocol.Extensions.Apps/ModelContextProtocol.Extensions.Apps.csproj @@ -32,7 +32,8 @@ - + + diff --git a/src/ModelContextProtocol.Extensions.Skills/ModelContextProtocol.Extensions.Skills.csproj b/src/ModelContextProtocol.Extensions.Skills/ModelContextProtocol.Extensions.Skills.csproj index cbee7a587..661ea2739 100644 --- a/src/ModelContextProtocol.Extensions.Skills/ModelContextProtocol.Extensions.Skills.csproj +++ b/src/ModelContextProtocol.Extensions.Skills/ModelContextProtocol.Extensions.Skills.csproj @@ -47,7 +47,8 @@ - + + diff --git a/src/ModelContextProtocol.Extensions.Skills/Server/McpSkillsBuilderExtensions.cs b/src/ModelContextProtocol.Extensions.Skills/Server/McpSkillsBuilderExtensions.cs index a2314c849..43ab79afb 100644 --- a/src/ModelContextProtocol.Extensions.Skills/Server/McpSkillsBuilderExtensions.cs +++ b/src/ModelContextProtocol.Extensions.Skills/Server/McpSkillsBuilderExtensions.cs @@ -118,7 +118,11 @@ public static IMcpServerBuilder WithSkillPackages(this IMcpServerBuilder builder var materialized = packages.ToArray(); McpServerSkillPackage.ValidatePackages(materialized, nameof(packages)); builder.WithSkills(materialized.Select(package => package.Skill)); - builder.WithResources(materialized.SelectMany(package => package.Resources)); + foreach (var resource in materialized.SelectMany(package => package.Resources)) + { + builder.Services.AddSingleton(resource); + } + return builder; } diff --git a/src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj b/src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj index cfeef00f4..64c626560 100644 --- a/src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj +++ b/src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj @@ -40,7 +40,8 @@ - + + diff --git a/src/ModelContextProtocol/TypeForwards.cs b/src/ModelContextProtocol/TypeForwards.cs new file mode 100644 index 000000000..6306d38dc --- /dev/null +++ b/src/ModelContextProtocol/TypeForwards.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +// IMcpServerBuilder was defined in this assembly before moving to ModelContextProtocol.Core. +[assembly: TypeForwardedTo(typeof(Microsoft.Extensions.DependencyInjection.IMcpServerBuilder))] diff --git a/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderTypeForwardingTests.cs b/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderTypeForwardingTests.cs new file mode 100644 index 000000000..dfb45c213 --- /dev/null +++ b/tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderTypeForwardingTests.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; +using ModelContextProtocol.Server; + +namespace ModelContextProtocol.Tests.Configuration; + +public class McpServerBuilderTypeForwardingTests +{ + [Fact] + public void IMcpServerBuilder_IsDefinedInCore_AndForwardedFromModelContextProtocol() + { + Assert.Same(typeof(McpServer).Assembly, typeof(IMcpServerBuilder).Assembly); + + // Code compiled against older ModelContextProtocol versions references IMcpServerBuilder + // in the ModelContextProtocol assembly, so it must resolve through the type forwarder. + var forwarded = typeof(McpServerServiceCollectionExtensions).Assembly + .GetType("Microsoft.Extensions.DependencyInjection.IMcpServerBuilder", throwOnError: true); + Assert.Same(typeof(IMcpServerBuilder), forwarded); + } +}