Skip to content

Support dependency-injected Skills catalogs and request services - #1969

Open
halter73 wants to merge 9 commits into
mainfrom
halter73-skills-dependency-injection
Open

halter73 wants to merge 9 commits into
mainfrom
halter73-skills-dependency-injection

Conversation

@halter73

Copy link
Copy Markdown
Contributor

Summary

Fixes #1941.

  • Add generic and factory-based Skills catalog registration, defaulting to transient with optional scoped or singleton lifetimes. Supplied instances remain caller-owned.
  • Resolve catalogs from the actual request services. Stateless HTTP reuses HttpContext.RequestServices without creating another scope; session-based transports use the existing MCP request lifecycle and async disposal.
  • Give catalogs standard typed request contexts, and document database-backed registration, ownership, concurrency, and transport-specific scope behavior.
  • Consolidate custom method handlers onto one contextual registration path instead of adding a parallel handler API.

API changes

The unshipped IMcpSkillCatalog methods now receive RequestContext<ListSkillsRequestParams> or RequestContext<GetSkillRequestParams>, with cursor/URI in Params. The redundant McpSkillRequestContext is removed.

The shipped experimental McpServerRequestHandler.Handler (MCPEXP002) now takes McpRequestHandler<JsonNode?, JsonNode?> instead of a raw JsonRpcRequest delegate. Custom handlers get the request-bound server and services while retaining control of JSON serialization. Existing handlers access the raw envelope through context.JsonRpcRequest. Tasks is updated, and package validation suppressions are limited to this intentional experimental signature change. Stable API declarations are unchanged.

The handler direction was checked against draft modelcontextprotocol/modelcontextprotocol#3371, particularly local context, middleware composition, and cleanup. This PR does not implement full SEP-3371 conformance or add typed authorization-filter integration for Skills.

Validation

  • Full solution build with warnings treated as errors.
  • Full non-manual .NET 10 unit and ASP.NET Core suites.
  • Focused Skills, custom-handler, Tasks, and HTTP coverage across supported test target frameworks, including .NET Framework 4.7.2 where applicable.
  • Native AOT publish and execution on win-x64.
  • Core, Skills, and Tasks package validation.

Note

This implementation and pull request description were generated with GitHub Copilot and refined with maintainer direction.

halter73 and others added 4 commits October 27, 2026 15:25
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use typed Core request contexts for catalog methods and resolve every catalog registration through DI while retaining caller ownership of supplied instances.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Unify custom handlers on RequestContext and the built-in request lifecycle, removing the parallel contextual handler API and routing plumbing. Intentionally revise the MCPEXP002 Handler contract with narrow compatibility suppressions and migration guidance.

Default generic and factory Skills catalogs to transient, remove custom lifetime validation, and cover middleware context propagation, concurrent capabilities, and request scope reuse.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the dependency-injected Skills catalog changes.

No open issues 🎉

What changed in this PR

Adds dependency-injected Skills catalogs to the C# SDK, addressing #1941 by resolving catalogs from request services and using the existing request-scope lifecycle.

Changes:

  • Adds generic and factory catalog registration with configurable lifetimes, while keeping supplied instances caller-owned.
  • Moves Skills and experimental custom handlers to standard request contexts, providing request-bound servers and services.
  • Adds lifetime, disposal, concurrency, transport, and Native AOT coverage, plus registration and migration documentation.
File Description
tests/​ModelContextProtocol.Tests/​Server/​McpServerSkillsRegistrationTests.cs Covers new registration overloads and supplied-instance ownership.
tests/​ModelContextProtocol.Tests/​Server/​McpServerSkillsDependencyInjectionTests.cs Tests catalog lifetimes, request services, concurrency, and disposal.
tests/​ModelContextProtocol.Tests/​Server/​McpServerSkillsCatalogTests.cs Adapts catalog tests to typed contexts and checks URI mutation handling.
tests/​ModelContextProtocol.Tests/​Server/​InMemoryMcpSkillCatalogTests.cs Uses typed contexts and adds null-context validation tests.
tests/​ModelContextProtocol.Tests/​Server/​CustomRequestHandlerTests.cs Tests contextual handlers, metadata, filters, and server messaging.
tests/​ModelContextProtocol.Tests/​Server/​CustomRequestHandlerScopeTests.cs Checks borrowed scope ownership and operation without services.
tests/​ModelContextProtocol.Tests/​Server/​CustomRequestHandlerCollisionTests.cs Expands custom-handler registration validation coverage.
tests/​ModelContextProtocol.AspNetCore.Tests/​SkillsDependencyInjectionTests.cs Verifies transport-specific scopes and asynchronous disposal.
tests/​ModelContextProtocol.AspNetCore.Tests/​SkillsAuthorizationTests.cs Migrates authorization catalogs to typed request contexts.
tests/​ModelContextProtocol.AspNetCore.Tests/​HttpHeaderConformanceTests.cs Tests missing and mismatched custom routing headers.
tests/​ModelContextProtocol.AotCompatibility.TestApp/​Program.cs Exercises injected catalogs and scoped disposal under Native AOT.
src/​ModelContextProtocol.Extensions.Tasks/​Server/​McpTasksBuilderExtensions.cs Migrates Tasks handlers to the contextual delegate signature.
src/​ModelContextProtocol.Extensions.Skills/​Server/​McpSkillsBuilderExtensions.cs Adds DI overloads and resolves catalogs from request services.
src/​ModelContextProtocol.Extensions.Skills/​Server/​McpSkillRequestContext.cs Removes the redundant Skills-specific request context.
src/​ModelContextProtocol.Extensions.Skills/​Server/​InMemoryMcpSkillCatalog.cs Reads catalog parameters from standard typed contexts.
src/​ModelContextProtocol.Extensions.Skills/​Server/​IMcpSkillCatalog.cs Updates the catalog contract and documents service ownership.
src/​ModelContextProtocol.Extensions.Skills/​ModelContextProtocol.Extensions.Skills.csproj Includes trimming-annotation polyfills for generic registration.
src/​ModelContextProtocol.Core/​Server/​McpServerRequestHandler.cs Changes experimental handlers to receive standard request contexts.
src/​ModelContextProtocol.Core/​Server/​McpServerOptions.cs Documents contextual handlers, scope behavior, and collision rules.
src/​ModelContextProtocol.Core/​Server/​McpServerImpl.cs Routes custom handlers through the existing invocation lifecycle.
src/​ModelContextProtocol.Core/​CompatibilitySuppressions.xml Adds targeted suppressions for the experimental signature change.
docs/​list-of-diagnostics.md Explains migration to contextual custom handlers.
docs/​concepts/​skills/​skills.md Documents DI registration, ownership, transport scopes, and authorization responsibilities.

Review effort: Balanced

Read Skills and Tasks operation arguments from context.Params while retaining the validated envelope context for protocol and capability checks. Add composition regressions for replacement and null parameter values.

Explicitly document the source and binary break in the experimental custom-handler delegate, and replace the unresolvable ServiceLifetime.Transient cross-reference with code formatting so the docs build passes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tarekgh

tarekgh commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

CC @girishkvs for awareness

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Skills catalog dependency-injection and request-lifecycle changes.

No open issues 🎉

Review effort: Balanced

@tarekgh tarekgh left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I resolved the conflict with main.

@girishkvs

Copy link
Copy Markdown
Contributor

@halter73 @tarekgh Fine with this covering part of #1941. Could we keep #1941 open until the rest goes in, by changing Fixes #1941 in the description to Part of #1941? The remaining design is on #1941.

— girishkvs's Copilot 🤖

@tarekgh

tarekgh commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

@girishkvs thanks for your follow up. @halter73 is exploring other design alternative for the changes in this PR. We'll keep you informed regarding which direction we will go with and then we can ensure we are not missing any part of #1941. Consider the current PR is still WIP.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants