-
Notifications
You must be signed in to change notification settings - Fork 347
Add Microsoft.ModelContextProtocol.HttpServer.Distributed package #1529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Microsoft.ModelContextProtocol.HttpServer.Distributed package #1529
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new Microsoft.ModelContextProtocol.HttpServer.Distributed package that adds distributed session affinity support for MCP HTTP servers, along with a dedicated test project and documentation.
Changes:
- Adds a distributed session affinity infrastructure (HybridCache-based
ISessionStore, endpoint filter, listening endpoint resolver, and semantic logging) and wires it via DI/endpoint extension methods. - Adds comprehensive unit and integration tests covering serialization, options validation, endpoint routing behavior, and real Kestrel multi-server scenarios.
- Defines packaging metadata, local build configuration, and standalone solution/props for the new package, plus README and release notes.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/Directory.Build.props |
Defines local build defaults (TFM, language, warnings) for the library and tests; note that IsPackable=false currently conflicts with the csproj’s package configuration. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/Directory.Packages.props |
Sets package versions for this sub-solution, decoupling it from the repo’s root central package versions. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/Microsoft.ModelContextProtocol.HttpServer.Distributed.slnx |
Adds a small solution that includes the new src and test projects for focused development. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Microsoft.ModelContextProtocol.HttpServer.Distributed.csproj |
Configures the new library as a NuGet package (ID, version, metadata, AOT compatibility, and runtime dependencies on HybridCache and YARP). |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Abstractions/ISessionStore.cs |
Introduces the abstraction for a session ownership store (GetOrClaimOwnershipAsync / RemoveAsync) used by the affinity layer. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Abstractions/SessionOwnerInfo.cs |
Defines the SessionOwnerInfo record (owner ID, address, claimed timestamp) that represents session ownership. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Abstractions/SessionAffinityOptions.cs |
Adds configurable options for session affinity (forwarder/client configs, HybridCache key, LocalServerAddress with a validation attribute). |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Abstractions/SessionAffinityOptionsValidator.cs |
Uses [OptionsValidator] to generate options validation based on SessionAffinityOptions’ data annotations. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Abstractions/ISessionAffinityBuilder.cs |
Provides a simple builder interface exposing IServiceCollection for the affinity setup API. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/Abstractions/IListeningEndpointResolver.cs |
Defines how to resolve the local server address for advertising/forwarding (explicit vs. from server bindings). |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/HybridCacheSessionStore.cs |
Implements ISessionStore on top of HybridCache, including sliding-style expiration and semantic logging for retrieval/removal. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/SessionOwnerInfoSerializer.cs |
Adds a source-generated IHybridCacheSerializer<SessionOwnerInfo> using SerializerContext for AOT-safe JSON serialization. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/SerializerContext.cs |
Declares the JsonSerializerContext with camelCase naming and WhenWritingNull ignore behavior for SessionOwnerInfo. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/ListeningEndpointResolver.cs |
Implements IListeningEndpointResolver to pick the effective local endpoint from options or IServerAddressesFeature with a priority strategy. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/SessionAffinityEndpointFilter.cs |
Core endpoint filter that resolves/claims session ownership, forwards non-owned requests via YARP, and cleans up stale sessions. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/ServiceCollectionExtensions.cs |
Adds AddMcpHttpSessionAffinity to wire up HybridCache (with custom serializer), the session store, YARP, the resolver, and the endpoint filter. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/SessionAffinityBuilder.cs |
Concrete ISessionAffinityBuilder implementation wrapping the service collection. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/MapSessionAffinityExtensions.cs |
Provides the WithSessionAffinity endpoint convention extension that injects SessionAffinityEndpointFilter into MapMcp endpoints. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/src/SemanticLogging.cs |
Defines event IDs and source-generated LoggerMessage extension methods for structured logging of session and forwarding operations. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/Microsoft.ModelContextProtocol.HttpServer.Distributed.Tests.csproj |
Creates the test project with references to the library and test dependencies (xUnit v3, NSubstitute, TestHost, MCP client/server). |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/SessionOwnerInfoSerializerTests.cs |
Verifies JSON serialization/deserialization behavior for SessionOwnerInfo including null handling, camelCase naming, and multi-segment buffers. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/SessionAffinityOptionsValidationTests.cs |
Tests data-annotation validation, options validator registration, and URI scheme correctness for SessionAffinityOptions. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/ListeningEndpointResolverTests.cs |
Thoroughly tests ListeningEndpointResolver across explicit config, binding combinations, localhost detection, and edge cases. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/SessionAffinityEndpointFilterTests.cs |
Unit-tests the endpoint filter’s behavior for local vs remote ownership, forwarding errors, 404 cleanup, scheme selection, and restart/stale-session scenarios. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/KeyedServiceTests.cs |
Ensures DI registration for the session affinity services works with/without a HybridCache service key and that the session store behaves correctly. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/RealServerIntegrationTests.cs |
Adds integration tests using real Kestrel servers and shared cache to validate session affinity and load-balancing semantics end-to-end. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/TESTSERVER_SESSION_AFFINITY.md |
Describes design options and tradeoffs for handling session affinity in tests, especially around TestServer vs real Kestrel. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/README.md |
Provides package overview, configuration guidance, and usage samples for enabling distributed session affinity (some API/property names currently diverge from the actual code). |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/RELEASE_NOTES.md |
Introduces a release notes file for this package, but the documented version does not yet match the csproj version. |
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/Directory.Build.props
Outdated
Show resolved
Hide resolved
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/RELEASE_NOTES.md
Outdated
Show resolved
Hide resolved
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/KeyedServiceTests.cs
Outdated
Show resolved
Hide resolved
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/RealServerIntegrationTests.cs
Show resolved
Hide resolved
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/RealServerIntegrationTests.cs
Show resolved
Hide resolved
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/RealServerIntegrationTests.cs
Show resolved
Hide resolved
core/Microsoft.ModelContextProtocol.HttpServer.Distributed/tests/RealServerIntegrationTests.cs
Show resolved
Hide resolved
...soft.ModelContextProtocol.HttpServer.Distributed/tests/SessionAffinityEndpointFilterTests.cs
Show resolved
Hide resolved
…ectory.Build.props Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
What does this PR do?
[Provide a clear, concise description of the changes]Added the Microsoft.ModelContextProtocol.HttpServer.Distributed package
[Any additional context, screenshots, or information that helps reviewers]GitHub issue number?
[Link to the GitHub issue this PR addresses]Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationeng/scripts/Process-PackageReadMe.ps1. See Package README/servers/Azure.Mcp.Server/docs/azmcp-commands.mdand/or/docs/fabric-commands.md.\eng\scripts\Update-AzCommandsMetadata.ps1to update tool metadata in azmcp-commands.md (required for CI)ToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.json/servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline