Mirror of https://github.com/modelcontextprotocol/csharp-sdk — The official C# SDK for Model Context Protocol servers and clients. Maintained in collaboration with Microsoft.
  • C# 99.8%
  • JavaScript 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Joel Forsyth 4d011995d1 Release SSE response stream reference when GET request ends
StreamableHttpServerTransport held a reference to the Kestrel SSE
response stream via _httpSseWriter for the entire session lifetime.
Since the transport is only disposed when the session itself is disposed
(via explicit DELETE or idle timeout), clients that disconnect without
sending DELETE — which is typical for long-lived SSE connections — left
the response stream pinned for the remainder of the idle timeout window.

Because the Kestrel HTTP connection (and its associated memory pool
buffers, Pipe readers/writers, socket send/receive buffers) is only
collectible once all references to the response stream are released,
this pinned ~20MiB of unmanaged memory per disconnected session until
cleanup. Under steady connect/disconnect churn (e.g., IDE availability
probes) this accumulated into sustained memory growth that eventually
OOMKilled the container.

Fix: release _httpSseWriter from within HandleGetRequestAsync's finally
block so the reference is dropped as soon as the GET request exits, not
just when the session is disposed. SendMessageAsync handles the
now-nullable field via the existing _getHttpResponseCompleted gate, and
any server-to-client messages sent after disconnect are still captured
by the event store writer for replay via Last-Event-ID.

Add a unit test that verifies _httpSseWriter is null once
HandleGetRequestAsync returns.

Relates to #766.
2026-06-05 16:52:49 -07:00
.config Bump docfx from 2.78.4 to 2.78.5 (#1408) 2026-03-02 09:17:42 -05:00
.devcontainer Fix dev container configuration to work in codespaces (#1555) 2026-05-07 04:43:44 -07:00
.github Validate user on Streamable HTTP session DELETE (#1604) 2026-06-03 02:00:35 -07:00
docs feat: Add Enterprise Managed Authorization (SEP-990) support (#1305) 2026-06-03 16:34:59 -07:00
samples Add InheritEnvironmentVariables to StdioClientTransportOptions (#1563) 2026-06-03 01:58:35 -07:00
src Release SSE response stream reference when GET request ends 2026-06-05 16:52:49 -07:00
tests Release SSE response stream reference when GET request ends 2026-06-05 16:52:49 -07:00
.editorconfig style: (#746) 2025-09-02 18:34:17 +03:00
.gitattributes Add gitattributes (#98) 2025-03-25 18:57:01 -07:00
.gitignore Use package-lock.json to pin conformance test dependencies (#1247) 2026-02-05 17:42:41 -08:00
CONTRIBUTING.md Add testing guidelines, update copilot instructions for tests (#1507) 2026-04-07 09:05:28 -07:00
Directory.Build.props Skip .NET Framework tests on non-Windows platforms (#1226) 2026-01-30 14:56:24 -08:00
Directory.Packages.props Bump Microsoft.Extensions.AI.Abstractions from 10.5.0 to 10.5.2 (#1561) 2026-05-07 16:11:27 -07:00
global.json Revert "Update to MTP (#958)" (#1011) 2025-11-21 14:53:16 -08:00
LICENSE Release v1.1.0 (#1411) 2026-03-06 12:52:11 -08:00
logo.png Add Directory.Build.props, apply CPM, use NB.GitVersioning, update package publishing 2025-03-19 17:27:18 +02:00
Makefile Add AOT compatibility publish test (#1246) 2026-02-09 22:00:12 +02:00
ModelContextProtocol.slnx Update release processes to support release servicing branches (#1620) 2026-06-03 01:50:51 -07:00
nuget.config Fix nuget config 2025-03-19 15:12:55 -04:00
Open.snk Add strong naming (#49) 2025-03-21 17:51:05 +00:00
package-lock.json Bump the npm_and_yarn group across 1 directory with 3 updates (#1565) 2026-05-07 16:09:47 -07:00
package.json Update tests for @modelcontextprotocol/server-everything 2026.1.26 (#1273) 2026-02-17 16:49:12 -08:00
README.md feat: Add Enterprise Managed Authorization (SEP-990) support (#1305) 2026-06-03 16:34:59 -07:00
SECURITY.md Update SECURITY.md to use GitHub Security Advisories (#1306) 2026-02-18 15:41:14 -08:00
THIRD-PARTY-NOTICES.txt Add McpServer/ClientResource{Template} and friends (#391) 2025-05-09 18:21:11 -04:00

MCP C# SDK

NuGet version

The official C# SDK for the Model Context Protocol, enabling .NET applications, services, and libraries to implement and interact with MCP clients and servers. Please visit the API documentation for more details on available functionality.

Packages

This SDK consists of three main packages:

  • ModelContextProtocol.Core NuGet version - For projects that only need to use the client or low-level server APIs and want the minimum number of dependencies.

  • ModelContextProtocol NuGet version - The main package with hosting and dependency injection extensions. References ModelContextProtocol.Core. This is the right fit for most projects that don't need HTTP server capabilities.

  • ModelContextProtocol.AspNetCore NuGet version - The library for HTTP-based MCP servers. References ModelContextProtocol.

Getting Started

To get started, see the Getting Started guide in the conceptual documentation for installation instructions, package-selection guidance, and complete examples for both clients and servers.

You can also browse the samples directory and the API documentation for more details on available functionality.

About MCP

The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). It enables secure integration between LLMs and various data sources and tools.

For more information about MCP:

Cross-Application Access (Identity Assertion Authorization Grant flow)

The SDK provides support for the Identity Assertion Authorization Grant flow via IdentityAssertionGrantProvider. See the Cross-Application Access section in the transport docs for full usage details.

License

This project is licensed under the Apache License 2.0.