按需选择包:仅用客户端或低层 API 选 Core,需要 HTTP 服务器才装 AspNetCore;完整安装与示例需参阅官方 Getting Started 文档,README 未直接给出
csharp-sdk
modelcontextprotocol活跃维护官方 C# SDK,用于快速搭建 MCP 服务端和客户端,让 .NET 应用接入 Model Context Protocol 生态。
The official C# SDK for Model Context Protocol servers and clients. Maintained in collaboration with Microsoft.
dotnet add package ModelContextProtocolREADME 未说明
官方 C# SDK,让 .NET 应用快速实现 MCP 客户端与服务器
官方 C# SDK,用于快速搭建 MCP 服务端和客户端,让 .NET 应用接入 Model Context Protocol 生态。
核心能力
- 提供客户端与低层服务器 API 的最小依赖包 Core
- 主包内置托管与依赖注入扩展,适配多数项目
- AspNetCore 包支持基于 HTTP 的 MCP 服务器
- 提供 Apps、Skills、Tasks 等可选扩展包
- 支持身份断言授权授予流程实现跨应用访问
容易踩的坑
- v2.4.0最新正式版2026-11-07 · 2026-11-07 04:18 UTC
Version 2.4.0 adds experimental MCP Skills support through the new ModelContextProtocol.Extensions.Skills package, alongside OAuth hardening and reliability improvements for transport, session, and discovery flows. MCP Apps also now match protocol property names case-sensitively.
What's Changed
- Add the experimental MCP Skills extension #1856 by @girishkvs (co-authored by @PederHP)
- Align Skills with server primitives and typed request handlers #1993 by @halter73 (co-authored by @Copilot)
- Require explicit opt-in for the legacy OAuth metadata fallback #1952 by @halter73 (co-authored by @Copilot)
- Preserve refresh tokens when OAuth refresh responses omit replacements #1968 by @halter73 (co-authored by @Copilot)
- Preserve canonical OAuth resource identifiers during refresh #1967 by @halter73 (co-authored by @Copilot)
- Fix cancellation being reported as missing OAuth metadata #1891 by @Empiree
- Cancel open subscriptions/listen requests when the transport stops delivering messages #1933 by @pournasserian (co-authored by @Copilot)
- Fix dropped notifications and cancellation when a request is canceled #1917 by @zerotohero3
- Prevent server/discover probes from committing the negotiated protocol version #1956 by @PrathmeshPawar2110 (co-authored by @claude)
- Fall back to SSE when AutoDetect receives a 405 with a JSON-RPC error body #1849 by @ump45nose
- Fix legacy output schemas for delegating server tools #1928 by @Oxygen56
- Match protocol property names case-sensitively #1934 by @FenjuFu
Documentation Updates
- Clarify Skills discovery and documentation #2000 by @halter73 (co-authored by @Copilot)
- Fix Markdown link-check warnings and update the Skills specification link #1975 by @jeffhandley (co-authored by @Copilot)
Test Improvements
- Prevent discovery probe timeouts in controlled test connections #1946 by @tarekgh
- Apply test discovery timeouts to Sampling_Stdio #1950 by @girishkvs
- Use a task that runs until cancelled in the task store cancellation test #1955 by @girishkvs
- Fix parallel integration test server startup #1982 by @jeffhandley (co-authored by @Copilot)
Repository Infrastructure Updates
- Bump fast-uri from 3.1.5 to 3.1.7 #1850
- Bump actions/deploy-pages from 5.0.0 to 5.0.1 #1858
- Support release-line docs publishing and release coordination #1972 by @jeffhandley (co-authored by @Copilot)
- Bump docfx from 2.78.5 to 2.81.0 #1961
- Bump actions/setup-node from 7.0.0 to 7.1.0 #1927
- Bump becheran/mlc from 1.2.0 to 1.3.0 #1907
- Bump the other-testing group with 2 updates #1960
- Bump actions/download-artifact from 8.0.1 to 8.0.2 #1926
- Bump Anthropic from 12.40.0 to 13.3.0 #1962
- Bump the opentelemetry-testing group with 6 updates #1959
- Bump actions/upload-artifact from 7.0.1 to 7.0.2 #1925
- Fix CI selection of patched .NET SDKs #1995 by @tarekgh
Acknowledgements
- @Empiree made their first contribution in #1891
- @zerotohero3 made their first contribution in #1917
- @girishkvs made their first contribution in #1856
- @FenjuFu made their first contribution in #1934
- @PrathmeshPawar2110 made their first contribution in #1956
- @Oxygen56 made their first contribution in #1928
- @pournasserian made their first contribution in #1933
- @nagavitalp submitted issue #1897 (resolved by #1934)
- @oleksandrdubyna88 submitted issue #1914 (resolved by #1933)
- @AdCodicem submitted issue #1916 (resolved by #1928)
- @gavin-wolfe submitted issue #1954 (resolved by #1956)
- @as992949791 submitted issue #1958 (resolved by #1968)
- @jeffhandley @tarekgh @halter73 @girishkvs @FenjuFu @PederHP @zerotohero3 @chrikrah @ump45nose @pournasserian reviewed pull requests
Full Changelog: https://github.com/modelcontextprotocol/csharp-sdk/compare/v2.3.1...v2.4.0
- v2.3.12026-11-03 · 2026-11-03 07:33 UTC
查看更新说明
This patch release includes a security fix for authenticated stateful sessions.
What's Changed
- Harden authenticated stateful MCP sessions (commit
bfbd893) by @halter73 (co-authored by @Copilot @jeffhandley @tarekgh)
Repository Infrastructure Updates
- Align docs publishing with shared orchestration #1981 by @jeffhandley (co-authored by @Copilot)
- Fix Markdown link-check warnings and outdated Skills specification link #1979 by @jeffhandley (co-authored by @Copilot)
Full Changelog: https://github.com/modelcontextprotocol/csharp-sdk/compare/v2.3.0...v2.3.1
[!NOTE] These release notes were drafted with GitHub Copilot.
- Harden authenticated stateful MCP sessions (commit
- v1.4.22026-11-03 · 2026-11-03 07:33 UTC
查看更新说明
This patch release includes security fixes for OAuth authentication and authenticated HTTP sessions.
What's Changed
- Validate OAuth PKCE support and metadata issuer #1949 by @halter73 (co-authored by @PranavSenthilnathan @Copilot)
Deployments using metadata-free 2025-03-26 OAuth discovery may explicitly enable the legacy endpoint fallback only after independently verifying PKCE enforcement; otherwise, update metadata to advertise S256. The process-wide opt-in is
ModelContextProtocol.Authentication.AllowLegacyOAuthMetadataFallback; it does not bypass validation of discovered metadata.- Harden authenticated HTTP session handling (7c5d15e) by @halter73 (co-authored by @jeffhandley @PranavSenthilnathan @Copilot)
Documentation Updates
- Sanitize 1.x documentation #1729 by @jeffhandley
- Document standing support for new MCP revisions #1827 by @jeffhandley (co-authored by @halter73 @Copilot)
Repository Infrastructure Updates
- Update SourceLink for 1.x documentation builds #1944 by @jeffhandley (co-authored by @Copilot)
- Enable CodeQL for release branches #1947 by @halter73 (co-authored by @Copilot)
- Add versioned docs publishing infrastructure #1980 by @jeffhandley (co-authored by @Copilot)
- Fix Markdown link-check warnings and outdated Skills specification link #1978 by @jeffhandley (co-authored by @Copilot)
Acknowledgements
- @halter73 @jeffhandley @PranavSenthilnathan @tarekgh reviewed pull requests
Full Changelog: https://github.com/modelcontextprotocol/csharp-sdk/compare/v1.4.1...v1.4.2
[!NOTE] These release notes were drafted with GitHub Copilot.
- v2.3.02026-10-20 · 2026-10-20 23:39 UTC
查看更新说明
This release improves HTTP discovery, OAuth, protocol interoperability, and shutdown reliability, preserves registration order for server primitives, and exposes a
TimeProviderfor deterministic client timeout tests. It also corrects optional server-identity handling; applications readingMcpClient.ServerInfoshould adopt nullable handling.Breaking Changes
Refer to the C# SDK Versioning documentation for details on versioning and breaking change policies.
McpClient.ServerInfois nullable — #1903- Its return annotation changes from
ImplementationtoImplementation?. Existing non-nullable assignments or dereferences can produce nullable warnings and fail warnings-as-errors builds. - On
2026-07-28connections,ServerInfoisnullwhen the server omits optional identity metadata fromserver/discover. Legacyinitializestill requiresserverInfo. Reading the property before connecting still throwsInvalidOperationException. - Migrate with a null check or a fallback such as
client.ServerInfo?.Name ?? "Unknown server". Self-reported identity must not be used for security decisions. - This corrective source-compatibility change is intentionally included in 2.3.0.
- Its return annotation changes from
What's Changed
- Correct protocol-version telemetry for stateless server spans #1810 by @luisangelrod
- Preserve HTTP errors and correct discovery fallback handling #1791 by @PranavSenthilnathan (co-authored by @Copilot)
- Make modern Streamable HTTP status mapping deterministic #1837 by @jstar0
- Modern responses wait for the first protocol message before sending headers; long-running silent handlers may need progress output or an appropriate HTTP timeout. Legacy eager-header behavior is preserved.
- Accept opaque legacy metadata and correct request-scoped capabilities and discovery advertisement #1852 by @halter73 (co-authored by @Copilot)
- Avoid redundant SSE fallback after discovery is rejected with 400 or 404 #1855 by @scottt732
- Close server stdin before waiting for graceful stdio process exit #1838 by @luisangelrod
- Preserve insertion order when listing server tools, prompts, and resources #1924 by @PederHP (co-authored by Claude Opus 5.5)
- Allow missing optional server identity in discovery and make
ServerInfonullable #1903 by @Coding-Professional - Include JSON parse details in Streamable HTTP 400 responses #1844 by @ump45nose
- Exclude OAuth from
DiscoverProbeTimeout, exposeMcpClientOptions.TimeProviderfor deterministic timeout tests, and default SSE to legacy initialization #1719 by @halter73 (co-authored by @Copilot)- OAuth remains subject to the overall
InitializationTimeoutand caller cancellation; it is excluded only from the short discovery-probe budget. - Modern discovery over SSE requires both explicit
HttpTransportMode.SseandProtocolVersion = "2026-07-28"; pinning the version withAutoDetectis not equivalent.
- OAuth remains subject to the overall
- Preserve numeric progress tokens in
RequestOptionsserialization #1832 by @dfedoryshchev - Dispose legacy SSE POST responses to release connections deterministically #1841 by @yalcinfu22 (co-authored by Claude Fable 5)
Documentation Updates
- Document standing support for new MCP specification revisions #1826 by @halter73 (co-authored by @Copilot)
Test Improvements
- Stabilize discovery-capable test connections while retaining initialization deadlines #1943 by @tarekgh
Repository Infrastructure Updates
- Add a source selector for manual documentation publishes #1828 by @jeffhandley (co-authored by @Copilot)
- Update SourceLink's private build dependency to resolve a vulnerable Git dependency #1873 by @halter73 (co-authored by @Copilot)
- Correct obsolete
McpServerFactoryreferences in Copilot instructions #1892 by @Zir0-93 - Update Microsoft.Extensions.AI and AI.Abstractions to 10.11.0 and align shared System dependencies to 10.0.13 #1940
- v2.2.02026-08-13 · 2026-08-13 08:45 UTC
查看更新说明
This release adds hybrid stateful/stateless HTTP serving so clients using the 2025-11-25 and 2026-07-28 protocol revisions can share an endpoint, and fixes a malformed header-decoding edge case.
What's Changed
- Add HttpServerSessionMode for hybrid stateful/stateless HTTP serving #1796 by @saicharanpardhu (co-authored by @Copilot @jeffhandley)
- Fix McpHeaderEncoder.DecodeValue throwing on the degenerate base64 wrapper #1805 by @latent-9
Test Improvements
- Fix duplicated word in test comment #1809 by @latent-9
Repository Infrastructure Updates
- Enable package validation for the MCP extension packages #1793 by @jeffhandley (co-authored by @Copilot)
- Add a release-manager agent that orchestrates the release skills #1794 by @jeffhandley (co-authored by @Copilot)
- Bump Anthropic from 12.39.0 to 12.40.0 #1808
- Bump @hono/node-server from 1.19.14 to 2.1.0 in the npm_and_yarn group across 1 directory #1812
- Fix dead relative link to versioning docs in bump-version skill #1807 by @latent-9
Acknowledgements
- @latent-9 made their first contribution in #1807
- @saicharanpardhu made their first contribution in #1796
- @saicharanpardhu submitted issue #1777 (resolved by #1796)
- @jeffhandley @tarekgh @halter73 reviewed pull requests
Full Changelog: https://github.com/modelcontextprotocol/csharp-sdk/compare/v2.1.0...v2.2.0
[!NOTE] These release notes were drafted with GitHub Copilot and reviewed before publishing.
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
MCP C# SDK
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
The SDK packages are:
-
ModelContextProtocol.Core
- For projects that only need to use the client or low-level server APIs and want the minimum number of dependencies.
-
ModelContextProtocol
- 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
- The library for HTTP-based MCP servers. References
ModelContextProtocol. -
ModelContextProtocol.Extensions.Apps
- MCP Apps extension for building interactive UI applications that render inside MCP hosts.
-
ModelContextProtocol.Extensions.Skills
- MCP Skills extension for serving and consuming Agent Skills with verifiable file manifests.
-
ModelContextProtocol.Extensions.Tasks
- MCP Tasks extension for running long-running tool invocations asynchronously with status polling and input requests.
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.