Building MCP Servers with C#: Connect AI Agents to Your .Net Applications with the Model Context Protocol
暫譯: 使用 C# 建立 MCP 伺服器:透過模型上下文協議將 AI 代理連接到您的 .Net 應用程式
Versluis, Gerald
買這商品的人也買了...
-
嵌入式系統設計實務-電路與驅動程式$250$225 -
$1,710Using SQLite (Paperback) -
ASP.NET 本質論$520$410 -
$700Professional Scrum Development with Microsoft Visual Studio 2012 (Paperback) -
Beginning Big Data with Power BI and Excel 2013: Big Data Processing and Analysis Using PowerBI in Excel 2013 (Paperback)$1,740$1,653 -
$474系統分析與設計 : 敏捷疊代方法 (原書第6版) -
IoT Solutions in Microsoft's Azure IoT Suite: Data Acquisition and Analysis in the Real World$3,410$3,239 -
$957深度學習 -
演算法之美:隱藏在資料結構背後的原理 (C++版)$650$507 -
$534JSON 實戰 -
$283大數據技術 -
手機攝影必學 BOOK:用OX帶你學會拍人物、食物、風景等情境照片$398$298 -
創意競擇:從賈伯斯黃金年代的軟體設計機密流程,窺見蘋果的創意方法、本質與卓越關鍵$460$391 -
Web 開發者一定要懂的駭客攻防術 (Web Security for Developers: Real Threats, Practical Defense)$420$331 -
資料科學的統計實務 : 探索資料本質、扎實解讀數據,才是機器學習成功建模的第一步$599$539 -
Martin Fowler 的企業級軟體架構模式:軟體重構教父傳授 51個模式,活用設計思考與架構決策 (Patterns of Enterprise Application Architecture)$800$624 -
我懂了!專案管理 (暢銷紀念版)$400$316 -
電腦視覺機器學習實務|建立端到端的影像機器學習 (Practical Machine Learning for Computer Vision: End-To-End Machine Learning for Images)$780$616 -
$2,070Learning Blazor: Build Single-Page Apps with Webassembly and C# (Paperback) -
ASP.NET Core Razor Pages in Action (Paperback)$2,160$2,052 -
超圖解 ESP32 應用實作$820$647 -
無瑕的程式碼 軟體工匠篇:程式設計師必須做到的紀律、標準與倫理 (Clean Craftsmanship: Disciplines, Standards, and Ethics)$720$561 -
從源頭就優化 - 動手開發自己的編譯器實戰$880$695 -
UX 商業價值實現之道|打造成功的數位產品服務 (UX for Business: How to Design Valuable Digital Companies)$780$616 -
建構可擴展系統|設計分散式架構 (Foundations of Scalable Systems: Designing Distributed Architectures)$780$616
相關主題
商品描述
The Model Context Protocol (MCP) is quickly becoming the standard way for AI models to talk to external tools, data, and services. Anthropic announced it late 2024, and Microsoft, OpenAI, Google, and others all jumped on board pretty quickly. It gives a universal protocol so AI agents can call into code: reading databases, calling APIs, accessing files, whatever is needed. People like to call it "USB-C for AI."
This book teaches .NET developers how to build MCP servers using the official C# SDK (ModelContextProtocol on NuGet). Start with the basics, learn how the protocol works, prepare the dev environment, then build increasingly complex servers. The book walks through the three MCP primitives: tools (functions the AI can call), resources (data the AI can read), and prompts (reusable templates), with examples you can actually run as you go.
GitHub Copilot, Claude, ChatGPT, and other AI assistants are adding MCP support right now. If you can build MCP servers, your code and APIs become accessible to every major AI platform at once. Readers build a complete capstone project that ties together tools, resources, prompts, DI, database integration, and deployment. The last chapters cover enterprise stuff like auth, resilience, and observability, plus getting it running with Docker, Azure, and CI/CD. So you can actually ship what you build.
What You Will Learn
- Understand how MCP works architecturally. Learn how hosts, clients, and servers communicate with JSON-RPC 2.0, how capability negotiation works, and what the transport layers do.
- Build MCP tools with the C# SDK. Create tools with typed parameters, async execution, progress reporting, and proper error handling using the official ModelContextProtocol NuGet package.
- Expose data through MCP resources. Serve static and templated resources with proper URI schemes and MIME types so AI models can read your application data.
- Create reusable prompt templates. Build parameterized prompts with multiple messages that guide AI behavior and can be shared across teams.
- Pick the right transport layer. Understand when to use stdio vs Streamable HTTP and implement both with ASP.NET Core.
- Use proper .NET patterns in MCP servers. Use dependency injection, IOptions configuration, structured logging, HttpClientFactory, the same patterns you'd use in any production ASP.NET Core app.
- Deploy MCP servers for real. Containerize with Docker, publish as .NET tools on NuGet, deploy to Azure, and set up CI/CD with GitHub Actions.
Who This Book is For
This book is for any .NET developers seeking to use Model Context Protocol to develop intelligent applications.
商品描述(中文翻譯)
模型上下文協議(Model Context Protocol, MCP)正迅速成為人工智慧模型與外部工具、數據和服務進行交互的標準方式。Anthropic 在 2024 年底宣布了這一協議,微軟、OpenAI、谷歌等公司也迅速加入了這一行列。它提供了一個通用協議,使得 AI 代理可以調用代碼:讀取數據庫、調用 API、訪問文件,滿足各種需求。人們喜歡稱之為「AI 的 USB-C」。
本書教導 .NET 開發者如何使用官方的 C# SDK(ModelContextProtocol 在 NuGet 上)來構建 MCP 伺服器。從基礎開始,了解協議的運作方式,準備開發環境,然後構建越來越複雜的伺服器。本書將介紹三個 MCP 原語:工具(AI 可以調用的函數)、資源(AI 可以讀取的數據)和提示(可重用的模板),並提供可以實際運行的示例。
GitHub Copilot、Claude、ChatGPT 和其他 AI 助手目前正在添加 MCP 支持。如果您能構建 MCP 伺服器,您的代碼和 API 將同時對每個主要的 AI 平台可用。讀者將構建一個完整的畢業專案,將工具、資源、提示、依賴注入、數據庫集成和部署結合在一起。最後幾章涵蓋企業級的內容,如身份驗證、韌性和可觀察性,以及如何使用 Docker、Azure 和 CI/CD 使其運行。因此,您可以實際交付您所構建的內容。
您將學到什麼
- 理解 MCP 的架構運作。學習主機、客戶端和伺服器如何通過 JSON-RPC 2.0 進行通信,能力協商如何運作,以及傳輸層的功能。
- 使用 C# SDK 構建 MCP 工具。創建具有類型參數、異步執行、進度報告和適當錯誤處理的工具,使用官方的 ModelContextProtocol NuGet 套件。
- 通過 MCP 資源暴露數據。提供靜態和模板資源,使用適當的 URI 協議和 MIME 類型,以便 AI 模型可以讀取您的應用數據。
- 創建可重用的提示模板。構建帶有多條消息的參數化提示,指導 AI 行為,並可以在團隊之間共享。
- 選擇正確的傳輸層。理解何時使用 stdio 與 Streamable HTTP,並使用 ASP.NET Core 實現兩者。
- 在 MCP 伺服器中使用適當的 .NET 模式。使用依賴注入、IOptions 配置、結構化日誌記錄、HttpClientFactory,這些都是您在任何生產環境的 ASP.NET Core 應用中會使用的模式。
- 實際部署 MCP 伺服器。使用 Docker 容器化,作為 .NET 工具發佈到 NuGet,部署到 Azure,並使用 GitHub Actions 設置 CI/CD。
本書適合誰
本書適合任何希望使用模型上下文協議開發智能應用的 .NET 開發者。
作者簡介
Gerald Versluis is a software developer from the Netherlands. He works at Microsoft on the .NET Maui team, helping to build amazing cross-platform frameworks for developing mobile and desktop apps. He is the host of a hugely successful YouTube channel with over 100k subscribers and often speaks about app development at conferences like Microsoft Build, NET Conf, and more.
作者簡介(中文翻譯)
Gerald Versluis 是來自荷蘭的軟體開發人員。他在微軟的 .NET Maui 團隊工作,幫助建立出色的跨平台框架,以開發行動和桌面應用程式。他擁有一個非常成功的 YouTube 頻道,訂閱人數超過 10 萬,並且經常在 Microsoft Build、.NET Conf 等會議上講述應用程式開發的相關內容。