Introduction to the C# SDK for Model Context Protocol (MCP)

dotnet www.youtube.com

Brief Summary

This video introduces the Model Context Protocol (MCP) and demonstrates how to build MCP clients and servers using the official C# SDK. MCP standardizes how applications provide context to Large Language Models (LLMs), acting as a "USBC port" for AI by connecting AI models to various data sources and tools. The video covers the key components of MCP (hosts, clients, and servers), explains how to set up a local MCP server using NuGet packages, and shows how to integrate it with VS Code and GitHub Copilot.

  • MCP standardizes context delivery to LLMs.
  • The video guides through building MCP servers and clients using C#.
  • Integration with VS Code and GitHub Copilot is demonstrated.

Introduction to Model Context Protocol (MCP)

The Model Context Protocol (MCP) is an open protocol designed to standardize how applications provide context to Large Language Models (LLMs). MCP serves as a standardized method for connecting AI models to various data sources and tools, similar to how a USBC port connects devices to peripherals. Key components include hosts (like VS Code), clients (protocol clients maintaining a one-to-one connection with the server), and servers (lightweight programs providing specific functionalities via the standardized MCP).

MCP Architecture and Communication

The architecture involves hosts like VS Code and GitHub Copilot communicating with various servers via the MCP protocol. These servers can run locally or remotely, interacting with local data sources, calculating logic, or communicating with remote servers and services. The official C# SDK facilitates building both MCP clients and servers, supporting local and remote events through standard IO transport and server events.

Setting Up a Local MCP Server with C#

To begin, create a new console application and install the ModelContextProtocol and Microsoft.Extensions.Hosting NuGet packages. The ModelContextProtocol package is essential for creating local MCP servers, while Microsoft.Extensions.Hosting allows for creating a hosting environment for the MCP server. Open the Program.cs file to write the MCP server.

Writing the MCP Server Code

The code involves using statements for dependency injection, hosting, and the ModelContextProtocol.Server. An empty application builder is created to enable dependency injection and server setup, utilizing the Microsoft Extension Hosting NuGet package. The MCP server is added to the services and configured with standard IO server transport. The assembly is then used to locate all items marked as tools to be exposed to the client.

Creating Tools for the MCP Server

A static class named echo tools is created, containing methods to return or reverse strings based on what the MCP client sends as a tool. The MCP Server Tool attribute is added to the class to signify that it contains MCP server tools. Methods like Echo (which returns "hello" followed by the input message) and ReverseEcho (which reverses the input message) are created. The Subscription attribute is crucial for MCP clients to identify which tools to call.

Integrating MCP Server with VS Code and GitHub Copilot

The process involves compiling the MCP server and configuring the project to support MCP server in VS Code. A .vscode folder is added with an MCP.json file to add a new server. The path is copied, and the standard IO command is selected, pasting the path with net run project. The MCP server.json file contains the necessary information to start the execution, calling the CSRO to display the two available tools.

Demonstration with GitHub Copilot

GitHub Copilot is switched to agent mode, showing the two available tools: ReverseEcho and Echo. A request is made to reverse a sentence, and the agent mode identifies the available tools, determining that ReverseEcho can be called. The tool is executed locally, demonstrating the ease of building MCP servers and clients with C#.

Resources and Conclusion

The Model Context Protocol configuration and C# SDK are available on GitHub, where all source code, samples, and documentation can be found.

Summarize any YouTube video in seconds

Get summaries like this one for any video, in your language, with the free Summ app.

Download on the Apple Store
Get it on Google Play

Transcript

Full transcript of “Introduction to the C# SDK for Model Context Protocol (MCP)”. Click a timestamp to open the video at that moment. Need another video? Use the YouTube transcript generator.

0:01 오늘은 MCP용 공식 C SDK를 사용하여 강력한 모델 컨텍스트 프로토콜 클라이언트와 서버를 구축하는 방법을 보여드리겠습니다 . 가장 먼저 궁금한 것은 MCP가 무엇인지일 것입니다. 이러한 모델 컨텍스트 프로토콜은 무엇입니까? 그럼 계속해서 들어가보도록 하겠습니다. 가장 중요한 점은 MCP가 애플리케이션이 LLM에 컨텍스트를 제공하는 방식을 표준화하는 개방형 프로토콜이라는 것입니다. 모델 컨텍스트 프로토콜 웹사이트에서 MCP를 AI 애플리케이션을 위한 USBC 포트와 같다고 생각하면 된다고 설명하는 방식이 정말 마음에 듭니다. USBC가 다양한 주변 기기 및 액세서리에 장치를 연결하는 표준화된 방법을 제공하는 것처럼 MCP는 AI 모델을 다양한 데이터 소스 및 도구에 연결하는 표준화된 방법을 제공합니다. 호스트, 클라이언트, 서버 등 여러 구성 요소가 있습니다. 호스트는

0:53 MCP를 통해 데이터에 액세스하려는 VS Code나 다른 ID 및 AI 도구와 같은 프로그램입니다. 클라이언트는 서버와 일대일 연결을 유지하는 프로토콜 클라이언트입니다 . 그리고 서버는 각각 표준화된 모델 컨텍스트 프로토콜을 통해 특정 기능을 제공하는 가벼운 프로그램입니다. 그럼 이게 어떻게 생겼을까요? 글쎄요, 호스트와 고객이 있죠. 예를 들어 VS Code와 Get Copilot이 있죠 . 이러한 서버는 MCP 프로토콜을 통해 로컬 머신이나 원격으로 실행 중인 다양한 서버와 통신합니다. 예를 들어, 서버가 로컬 데이터 소스와 통신하거나 다른 논리를 계산할 수 있습니다. MCP 서버는 로컬에서 실행되면서 웹 API를 통해 인터넷에 있는 다양한 데이터 소스와 통신할 수 있습니다 . 또는 원격 서버가 servercent 이벤트를 통해 원격 서버와 통신하고, 그 후 원격 서비스와도 통신할 수도 있습니다. 그리고 가장 좋은 점은 MCP용 공식 CDK를 사용하여

1:39 MCP 클라이언트와 서버를 빌드할 수 있다는 것입니다 . 클라이언트와 서버 모두 사용 가능하며, 서버는 로컬 이벤트의 경우 표준 IO 전송을 통해 로컬 및 원격 이벤트를 모두 지원하고 , 원격 이벤트의 경우 서버 이벤트를 지원합니다. 이제 이것을 만드는 방법을 살펴보겠습니다 . 가장 중요한 점은 C에서 모델 컨텍스트 프로토콜을 위한 Nougat 패키지 시리즈가 제공된다는 것입니다. 주요 모델 컨텍스트 프로토콜은 Nougat이고, 원격 서버 시나리오를 위한 모델 컨텍스트 프로토콜.aspn.net 코어입니다 . 시작하려면 새 콘솔 애플리케이션을 만드세요. 이 경우 MCP라는 새로운 콘솔 앱을 만들겠습니다. 그런 다음 두 개의 서로 다른 Nougat 패키지를 설치합니다. 첫 번째는

2:26 모델 컨텍스트 프로토콜입니다. 예를 들어, 내 컴퓨터에서 실행되는 로컬 MCP 서버를 만들거나, 해당 서버에 대한 이미지를 만들어 Docker에 설정할 수 있는 서버를 만들 예정이기 때문입니다. Microsoft Extension Hosting도 설치하겠습니다 . 그러면 MCP 서버가 실행될 호스팅 환경을 만들 수 있습니다 . 이제 콘솔 애플리케이션이 있으므로 프로그램 CS를 열고 MCP 서버를 작성할 수 있습니다. 첫 번째는 종속성 주입 호스팅 및 시스템 구성 요소 모델과 같은 표준적인 것을 사용하는 몇 가지 문장입니다. 또한 세 번째인 모델 컨텍스트 protocol.server도 살펴보겠습니다. 그것이 주요 내용이 될 것입니다. 여기에서 빈 애플리케이션 빌더를 만들 수 있습니다. 그러면

3:11 종속성 주입과 같은 기능을 사용하고 서버를 설정할 수 있게 됩니다. 이는 우리가 설치한 Microsoft 확장 호스팅 누가 패키지에서 나오는 것입니다 . 이제 MCP 서버를 서비스에 추가할 수 있습니다. 표준 io 서버 전송으로 구성합니다 . 마지막으로, 이것을 조립도구와 함께 사용합니다 . 그리고 이 작업을 통해 우리는 클라이언트에게 공개할 도구로 표시한 모든 항목을 어셈블리에서 찾을 수 있습니다 . 이제부터 애플리케이션을 빌드하고 실행해보겠습니다. 이제 클라이언트 에서 사용될 MCP 서버에 공개하고자 하는 일련의 도구도 만들어야 합니다 . 여기에는 echo tools라는 정적 클래스가 있습니다. 따라서 MCP 클라이언트가 도구로 전송하는 내용을 기반으로 문자열을 되돌리거나 반전하는 몇 가지 메서드를 만들 것입니다

3:59 . 먼저 MCP 서버 도구 유형이라는 속성을 추가합니다 . 이는 이 클래스에 MCP 서버 도구가 있다는 것을 의미합니다 . 그리고 우리는 그저 우리만의 방법을 만들어냅니다 . 여기 첫 번째는 에코입니다. 메시지를 문자열로 받아서 C에서 메시지가 무엇인지 알려주는 hello를 반환합니다 . 속성 MCP 서버 도구를 사용한 다음 설명을 추가하는 것을 볼 수 있습니다. 구독이 중요한 이유는 MCP 클라이언트가 어떤 도구를 호출해야 할지 알아내기 위해 구독을 사용하기 때문입니다. 여기에 또 하나 만들어 볼게요. MCP 서버 도구 이며 이 경우에는 단순히 메시지를 가져와서 역방향 에코를 사용합니다 . 이제 해야 할 일은

4:45 GitHub Copilot을 사용하여 VS Code와 같은 도구에서 MCP 서버를 구성하는 것뿐입니다. 실제로 어떻게 적용되는지 살펴보겠습니다. 여기 VS Code 내부에도 똑같은 코드가 있습니다. 우리가 할 일은 먼저 MCP 서버를 컴파일하고, 그런 다음 MCP 서버 지원을 받도록 프로젝트를 구성하는 것입니다. VS Code라는 새 폴더를 추가하고 MCP.json이라는 파일을 추가할 겁니다. 그러면 새 서버를 추가할 수 있을 겁니다. 그러니 이 경로를 복사한 후 서버 추가를 클릭하겠습니다 . 표준 IO 명령을 선택 하고 net run project를 전달하여 해당 위치에 붙여넣겠습니다. 이제 MCP server.json에는 실행을 시작하는 데 필요한 정보가 있습니다 . 그러면 컴퓨터에서 실행 중인 CSRO를 호출하여 사용 가능한 도구 두 가지를 보여줍니다.

5:32 여기서 GitHub Copilot을 열어보겠습니다. MCP 서버를 사용할 수 있는 에이전트 모드로 전환하겠습니다. 여기서는 역방향 에코와 에코라는 두 가지가 사용 가능한 것을 볼 수 있습니다 . 그래서 이제 나는 재빠른 갈색 여우가 게으른 개를 뛰어넘는 장면을 반대로 보여달라고 요청할 수 있게 됐습니다. 이제 에이전트 모드가 실행되면 사용 가능한 도구를 살펴보고 필요한 경우 어떤 도구를 호출할 수 있는지 파악합니다. 여기서는 역방향 에코를 호출할 수 있다고 하며, 내 컴퓨터에서 로컬로 실행 중이므로 실행할지 여부를 알려줍니다. 그리고 우리는 시작합니다. 이렇게 하면 C로 MCP 서버와 클라이언트를 쉽게 구축할 수 있습니다.

6:18 모델 컨텍스트 프로토콜 구성과 C SDK로 가서 GitHub에서 시작할 수 있습니다. 여기에서 모든 소스 코드 , 샘플, 문서를 찾을 수 있습니다. 즐거운 코딩 되세요. [음악]

Share

More video summaries