受欢迎的博客标签

MCP Server in C# .NET - How it works?(AI Chat Application Using MCP)

Published

MCP provides a structured framework for AI agents to communicate with data sources seamlessly. The protocol consists of three primary components:

MCP Host(chat application)
MCP Client
MCP Server

 

1. MCP Host
The MCP Host is at the core of the system. It can be an application like a chat assistant,  or any AI-powered tool requiring access to external data. The host includes one or more MCP clients.

2. MCP Client
The MCP Client operates within the MCP Host, acting as an intermediary between the host application and the MCP Server. 

3. MCP Server
The MCP Server serves as a bridge between the MCP Client and external data sources. It can connect to:

Databases (SQL, NoSQL)
APIs (REST, GraphQL, or any other standard)
Local files and code repositories

 

 

“What is the weather like in New York?”

 

1.MCP Client Requests Tools: The MCP Host (chat application) needs to access relevant data, so it queries the MCP Server for available tools.
2.MCP Server Provides Available Tools: The server returns a list of available services, such as a weather API.
3.MCP Host Consults LLM: The host then sends the user’s query, along with the available tools, to a large language model (LLM).
4.LLM Determines the Best Tool: The LLM processes the request and determines that the best tool for the job is the weather API.
5.MCP Client Calls the MCP Server: The client makes a request to the MCP Server to fetch weather data.
6.MCP Server Executes Query: The server retrieves weather information from an external API and returns the response.
7.Final Answer Returned to User: The MCP Host compiles the response and presents it to the user in the chat application.

 

当你提出问题时:

MCP client 将你的问题发送给 LLM ; - 将 MCP Tool 转换为 Function 添加到对话上下文中
LLM 分析可用的 tools 并决定使用哪些 tool;- AI 回答要调用的 Function call 步骤和参数
MCP client 通过 MCP server 执行选择的 tool - 接着由MCP客户端实现将 Function 定位 MCP Server,并顺序调用每个 Tool
结果被发回给 LLM; - MCP客户端将每个 Function 的执行结果和用户的提问等信息,一起再次提交给 AI 模型服务器
LLM 制定自然语言响应;
响应显示给你;

Note

当用户输入,提出问题时 ,客户端首先将用户提问和 mcp server服务所提供的 function call 一起发送到 AI 模型服务器。

并不是 AI 模型直接调用 MCP Server 的,依然 Client 进行是 Function call 

 

1.MCP Host - ai qwen-max

https://blog.csdn.net/a123_z/article/details/146907261

 

https://github.com/zhanglilong23/mcpdemo/

 

2. very good

https://www.cnblogs.com/whuanle/p/18837493

 

https://medium.com/garantibbva-teknoloji/model-context-protocol-mcp-a-new-standard-for-ai-agents-878a1378f41d