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.

v2.4.0发布于 2026-11-07 04:18 UTC4,628star +8 / 7 天847fork同步于 2026-11-11 05:35 UTC

怎么上手

由 README 提炼,执行前请确认
dotnet add package ModelContextProtocol
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

官方 C# SDK,让 .NET 应用快速实现 MCP 客户端与服务器

官方 C# SDK,用于快速搭建 MCP 服务端和客户端,让 .NET 应用接入 Model Context Protocol 生态。

核心能力

  • 提供客户端与低层服务器 API 的最小依赖包 Core
  • 主包内置托管与依赖注入扩展,适配多数项目
  • AspNetCore 包支持基于 HTTP 的 MCP 服务器
  • 提供 Apps、Skills、Tasks 等可选扩展包
  • 支持身份断言授权授予流程实现跨应用访问

容易踩的坑

按需选择包:仅用客户端或低层 API 选 Core,需要 HTTP 服务器才装 AspNetCore;完整安装与示例需参阅官方 Getting Started 文档,README 未直接给出

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.4.0
  1. 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

  2. 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.

  3. 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.

  4. 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 TimeProvider for deterministic client timeout tests. It also corrects optional server-identity handling; applications reading McpClient.ServerInfo should adopt nullable handling.

    Breaking Changes

    Refer to the C# SDK Versioning documentation for details on versioning and breaking change policies.

    1. McpClient.ServerInfo is nullable — #1903
      • Its return annotation changes from Implementation to Implementation?. Existing non-nullable assignments or dereferences can produce nullable warnings and fail warnings-as-errors builds.
      • On 2026-07-28 connections, ServerInfo is null when the server omits optional identity metadata from server/discover. Legacy initialize still requires serverInfo. Reading the property before connecting still throws InvalidOperationException.
      • 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.

    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 ServerInfo nullable #1903 by @Coding-Professional
    • Include JSON parse details in Streamable HTTP 400 responses #1844 by @ump45nose
    • Exclude OAuth from DiscoverProbeTimeout, expose McpClientOptions.TimeProvider for deterministic timeout tests, and default SSE to legacy initialization #1719 by @halter73 (co-authored by @Copilot)
      • OAuth remains subject to the overall InitializationTimeout and caller cancellation; it is excluded only from the short discovery-probe budget.
      • Modern discovery over SSE requires both explicit HttpTransportMode.Sse and ProtocolVersion = "2026-07-28"; pinning the version with AutoDetect is not equivalent.
    • Preserve numeric progress tokens in RequestOptions serialization #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 McpServerFactory references 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
  5. 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.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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

    The SDK packages are:

    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.