Repository navigation
Conversation
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>
…-skills-dependency-injection
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>
Contributor
There was a problem hiding this comment.
🟢 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>
Contributor
|
CC @girishkvs for awareness |
tarekgh
approved these changes
Oct 29, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1941.
HttpContext.RequestServiceswithout creating another scope; session-based transports use the existing MCP request lifecycle and async disposal.API changes
The unshipped
IMcpSkillCatalogmethods now receiveRequestContext<ListSkillsRequestParams>orRequestContext<GetSkillRequestParams>, with cursor/URI inParams. The redundantMcpSkillRequestContextis removed.The shipped experimental
McpServerRequestHandler.Handler(MCPEXP002) now takesMcpRequestHandler<JsonNode?, JsonNode?>instead of a rawJsonRpcRequestdelegate. Custom handlers get the request-bound server and services while retaining control of JSON serialization. Existing handlers access the raw envelope throughcontext.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
Note
This implementation and pull request description were generated with GitHub Copilot and refined with maintainer direction.