关于 MCP Server
这是一个简化的 C# MCP 服务示例仓库,包含 SportKnowHow_McpServer 和调用它的 SportApp,适合研究 MCP 服务与主机应用的开发。示例展示工具、资源、提示词及资源更新订阅。
主要功能
- 01提供工具、资源和提示词
- 02通过 stdio 通信
- 03支持资源更新订阅
- 04包含 C# 服务与控制台示例
- 05提供 Azure OpenAI 设置脚本
适用场景
- 01构建 C# MCP 服务示例
- 02在应用中调用 MCP 工具
- 03请求提示词和资源模板
- 04接收资源变更通知
MCP 相关
该项目实现 MCP 服务,向客户端提供工具、资源和提示词。配套的 SportApp 展示通过 stdio 启动服务、调用能力及订阅资源更新。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
README 原文English
来自项目 READMEREADME 暂无中文译文,以下为英文原文;中文介绍见上方。
MCP Server
Overview
MCP is an open protocol that standardizes how applications provide context to LLMs and is often called the "USB-C port for AI Applications". MCP provides a standardized way to connect AI models to different data sources, prompts and tools.
An MCP (Model Context Protocol) server provides Resources, Tools, and Prompts to an application, enabling it to enhance its communication with a Large Language Model (LLM) or Small Language Model (SLM). The application initiates the MCP server—typically within its own security context—and communicates with it via standard I/O (stdio)

An application is not limited to a single MCP server; it can start and interact with multiple MCP servers simultaneously, each providing distinct Resources, Tools, and Prompts. While there is a one-to-one relationship between each MCP client (initiated by the application) and its corresponding MCP server, the application can manage several such pairs. In the given example, three MCP servers are launched, each contributing their own contextual assets to enhance model interactions.
Tools: Often used to provide functionality to the application (e.g. retrieve private information, perform specific tasks etc.). A list of available MCP server tools can be provided by the app to the LLM/SLM instance (with function calling capabilities) where most SDKs wrap the necessary function or tool calls to the MCP server automatically.
Resources: Data which the app can request from the MCP server to e.g. ground LLM/SLM calls. The app can also subscribe to a MCP resource to get continous updates (if new information is available). The MCP server implements the necessary update logic.
Prompts: The MCP server can provide prompt templates for the app to send to LLMs/SLMs.
Repo Content
The repo contains a simplified c# MCP Server and a c# console application consuming Tools, Resources and and a script to setup an Azure OpenAI instance with a deployed gpt-4 model instance:
| Folder | Appliation |
|---|---|
| ./src/SportApp | A simplified c# console application which uses Tools, Prompts and Resources from SportKnowHow_McpServer |
| ./src/SportKnowHow_McPServer | A simplified c# Mcp Server |
| ./setup/setup.azcli | A powershell Azure CLI script to setup the necessary Azure OpenAI instance with deployed gpt-4 instance |
Demo Application
Overview "SportsApp"

-
SportApp starts the provided MCP server using dotnet run and stdio
//MCP Server: start parameter string command = "dotnet"; string[] arguments = new string[] { "run", "--project", "./src/SportKnowHow_MCPServer/SportKnowHow_MCPServer.csproj"}; //MCP Server: communication protocol StdioClientTransportOptions stdioClientTransportOptions = new StdioClientTransportOptions() { Name = "Sport Know How (MCP Server)", Command = command, Arguments = arguments, }; StdioClientTransport stdioClientTransport = new StdioClientTransport(stdioClientTransportOptions); //Start MCP Server await using IMcpClient mcpClient = await McpClientFactory.CreateAsync(stdioClientTransport); -
All available tools provided by the MCP server are listed
-
The tool with id
RetrieveWinnerwith parametereventName' andeventDate` is executed//List available tools IList<McpClientTool> mcpClientTools = await mcpClient.ListToolsAsync(); //Manual tool call string toolName = "RetrieveWinner"; Dictionary<string, object?> callParameter = new Dictionary<string, object?> { { "eventName", "Super Sports Champtionship" }, { "eventDate", "2025-01-01"} }; CallToolResponse callToolResponse = await mcpClient.CallToolAsync(toolName, callParameter); -
The MCP server tools are provided to a LLM/SLM completion call using
Microsoft.Extensions.AI. There's no need to intercept the LLM/SLM function tooling requests aschatClient.RetResponse()takes care of calling the MCP Server tools as requested by the LLM and provides results back to the LLM.//Use tools in chat completions ... string systemMessage = "You help with information around international sport events."; string userMessage = "Who won the Super Sports Championship 2025?"; var chatMessages = new List<ChatMessage> { new ChatMessage (Microsoft.Extensions.AI.ChatRole.System, systemMessage), new ChatMessage (Microsoft.Extensions.AI.ChatRole.User, userMessage) }; ChatResponse chatResponse = await chatClient.GetResponseAsync( chatMessages, new ChatOptions { Tools = mcpClientTools.ToArray() } ); ... -
Within the MCP server defined prompts are listed and a specific prompt (
CreateMatchSummaryPrompt) with parameters is requested.// List available prompts IList<McpClientPrompt> mcpClientPrompts = await mcpClient.ListPromptsAsync(); // Retrieve specific prompt string promptName = "CreateMatchSummaryPrompt"; Console.WriteLine($"Retrieve prompt: {promptName}"); Dictionary<string, object?> promptParameter = new Dictionary<string, object?> { { "eventName", "Munich Flying Dolphins vs. Berlin Bears" }, { "winner", "Munich Flying Dolphins" }, { "score", "24:31" }, { "enthusiasm", "high" } }; GetPromptResult getPromptResult = await mcpClient.GetPromptAsync(promptName, promptParameter); -
Within the MCP server defined resources templates and resources are listed and requested.
//List available resource templates string resourceTemplateUri = ""; IList<McpClientResourceTemplate> mcpClientResourceTemmplates = await mcpClient.ListResourceTemplatesAsync(); //Retrieve a specific resource template resourceTemplateUri = resourceTemplateUri.Replace("{id}", "NurembergFlyingTigers"); ReadResourceResult readResourceTemplateResult = await mcpClient.ReadResourceAsync(resourceTemplateUri); //List available resources string resourceUri = ""; IList<McpClientResource> mcpClientResources = await mcpClient.ListResourcesAsync(); // Retrieve a specific resource ReadResourceResult readResourceResult = await mcpClient.ReadResourceAsync(resourceUri); -
A subsription with the MCP server is created. The MCP server can send updates whenever the underlying resource is changed.
// Subscribe to resources mcpClient.RegisterNotificationHandler("notifications/resource/updated", NotificationHandler); await mcpClient.SubscribeToResourceAsync("sportIntelligence://team/MunichFlyingDolphins");
Overview "SportKnowHow_McpServer
- MCP Server creation with Tools, Prompts and Resource support.
//create MCP server HostApplicationBuilder hostApplicationBuilder = Host.CreateApplicationBuilder(args); hostApplicationBuilder.Logging.AddConsole(consoleLogOptions => { consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace; }); hostApplicationBuilder.Services .AddMcpServer() .WithStdioServerTransport() .WithTools<SportEventTools>() .WithPrompts<SportEventPrompts>() .WithResources<SportEventResources>() .WithSubscribeToResourcesHandler(SubscribeToResourcesHandler) .WithUnsubscribeFromResourcesHandler(UnsubscribeFromResourcesHandler) .WithReadResourceHandler(ReadResourceHandler); hostApplicationBuilder.Services.AddSingleton(resourceSubscriptions); hostApplicationBuilder.Services.AddHostedService<SubscriptionMessageSender>();
Summary
MCP Server which often exectue in the security context of the calling applications make it easy to provide tools,resources and prompts to calling applications. Just like shown in the sample SportApp application the ModelContextProtocol nuget package simplifies the development of Mcp Server and Mcp Host applicatons.
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。