Skip to content

Conversation

@xiangyan99
Copy link
Member

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

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Copy link
Contributor

Copilot AI left a 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.

@xiangyan99 xiangyan99 changed the title Added Microsoft.ModelContextProtocol.HttpServer.Distributed package Add Microsoft.ModelContextProtocol.HttpServer.Distributed package Jan 22, 2026
…ectory.Build.props

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants