MCP协议学习笔记(1)

目录

MCP介绍

什么是MCP

开源设计

MCP Host vs MCP Client

MCP开发

官方参考文档

中文站参考文档

其它分析文档

Cline集成

其它分析视频

MCP是啥?技术原理是什么?一个视频搞懂MCP的一切

Windsurf集成MCP Server


MCP介绍

2024年11月25日,Anthropic公司发布了《Introducing the Model Context Protocol》

原文如下:https://www.anthropic.com/news/model-context-protocol

Today, we're open-sourcing the Model Context Protocol (MCP), a new standard for connecting AI assistants to the systems where data lives, including content repositories, business tools, and development environments. Its aim is to help frontier models produce better, more relevant responses.

As AI assistants gain mainstream adoption, the industry has invested heavily in model capabilities, achieving rapid advances in reasoning and quality. Yet even the most sophisticated models are constrained by their isolation from data—trapped behind information silos and legacy systems. Every new data source requires its own custom implementation, making truly connected systems difficult to scale.

MCP addresses this challenge. It provides a universal, open standard for connecting AI systems with data sources, replacing fragmented integrations with a single protocol. The result is a simpler, more reliable way to give AI systems access to the data they need.

今天,我们开源了模型上下文协议(MCP),这是一个新的标准,用于将AI助手连接到数据所在系统,包括内容存储库、业务工具和开发环境。其目的是帮助前沿模型生成更好、更相关的响应。

随着AI助手获得主流采用,行业在模型能力方面进行了大量投资,实现了推理和质量的快速进步。然而,即使是最先进的模型也受限于与数据的隔离——被困在信息孤岛和遗留系统中。每个新的数据源都需要单独定制实现,使得真正互联的系统难以扩展。

MCP解决了这一挑战。它提供了一个通用的开放标准,用于将AI系统与数据源连接起来,用单一协议取代碎片化的集成。结果是,为AI系统访问所需数据提供了一种更简单、更可靠的方法。

什么是MCP

Introduction - Model Context Protocol

MCP is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.

开源设计

开源仓库

Model Context Protocol · GitHub

架构

Core architecture - Model Context Protocol

MCP Host vs MCP Client

To understand the difference between an MCP host and an MCP client, it's essential to grasp the overall architecture of the Model Context Protocol (MCP). Here's a breakdown:

  • MCP Host:
    • This is the user-facing AI application or agent environment. Think of it as the main application that the user interacts with. Examples include the Claude desktop app, an IDE plugin, or any custom LLM-based application.
    • The host's primary role is to connect to and utilize the capabilities of multiple MCP servers.
    • Essentially, the host is the application that houses the AI that utilizes external tools and data.
  • MCP Client:
    • The client is an intermediary component that resides within the MCP host.
    • Its function is to manage the secure connections between the host and individual MCP servers.
    • Critically, there is one MCP client for each MCP server that the host connects to, providing isolation and security.
    • Essentially the client is the connection manager for each individual server that the host is connected to.

In simpler terms:

  • The host is the overall application.
  • The client is the connection point to a specific server, that is contained within the host.

Therefore, the host contains one or more clients, each of which connect to a seperate server.

Key points to remember:

  • MCP Host facilitates the integration of LLMs with external data sources and tools.
  • The client-server architecture ensures modularity and security.

I hope this explanation is helpful.

当然,以下是对 MCP 主机和 MCP 客户端之间区别的中文翻译:

MCP 主机 (MCP Host):

  • 这是面向用户的 AI 应用程序或代理环境。可以将其视为用户与之交互的主要应用程序。示例包括 Claude 桌面应用程序、IDE 插件或任何自定义的基于 LLM 的应用程序。
  • 主机的主要作用是连接并利用多个 MCP 服务器的功能。
  • 本质上,主机是包含使用外部工具和数据的 AI 的应用程序。

MCP 客户端 (MCP Client):

  • 客户端是驻留在 MCP 主机内的中间组件。
  • 其功能是管理主机和各个 MCP 服务器之间的安全连接。
  • 至关重要的是,主机连接的每个 MCP 服务器都有一个 MCP 客户端,从而提供隔离和安全性。
  • 本质上,客户端是主机连接的每个单独服务器的连接管理器。

简单来说:

  • 主机是整体应用程序。
  • 客户端是到特定服务器的连接点,包含在主机内。

因此,主机包含一个或多个客户端,每个客户端都连接到单独的服务器。

需要记住的要点:

  • MCP 主机促进了 LLM 与外部数据源和工具的集成。
  • 客户端-服务器架构确保了模块化和安全性。

MCP 主机和 MCP 客户端的总结,包括中文和英文:

中文总结:

  • MCP(模型上下文协议) 是一种旨在简化人工智能(AI)模型与外部数据源和工具集成的协议。
  • MCP 主机(MCP Host):
    • 是用户直接交互的 AI 应用程序,例如 Claude 桌面应用或 IDE 插件。
    • 负责协调和利用 LLM 以及各种外部工具和数据源。
    • 通过 MCP 客户端与 MCP 服务器建立连接,从而实现与外部资源的交互。
    • 是整个集成过程的中心。
  • MCP 客户端(MCP Client):
    • 是位于 MCP 主机内部的中间组件。
    • 负责管理与特定 MCP 服务器的安全连接。
    • 每个连接的 MCP 服务器都有一个对应的 MCP 客户端,以确保隔离和安全。
    • 是主机与服务器之间的连接管理器。
  • 简单来说:主机是整体应用,客户端是主机内连接具体服务器的连接点。

英文总结:

  • MCP (Model Context Protocol) is a protocol designed to simplify the integration of artificial intelligence (AI) models with external data sources and tools.
  • MCP Host:
    • Is the user-facing AI application, such as the Claude desktop app or an IDE plugin.
    • Is responsible for coordinating and utilizing LLMs and various external tools and data sources.
    • Establishes connections with MCP servers through MCP clients, enabling interaction with external resources.
    • Is the central coordinating portion of the overall system.
  • MCP Client:
    • Is an intermediary component residing within the MCP host.
    • Is responsible for managing secure connections with specific MCP servers.
    • Each connected MCP server has a corresponding MCP client to ensure isolation and security.
    • Is the connection manager between the host and individual servers.
  • Simply put: the host is the overall application, the client is the connection point to a specific server within the host.

MCP开发

官方参考文档

dev a server

For Server Developers - Model Context Protocol

dev a client

For Client Developers - Model Context Protocol

claud desktop as a host

For Claude Desktop Users - Model Context Protocol

中文站参考文档

一个中文站社区,可以自行查看

构建 MCP 客户端-Python – MCP 中文站(Model Context Protocol 中文)

其它分析文档

https://zhuanlan.zhihu.com/p/29001189476

讲解了概念,重点分析,Claud模型是如何调用function call的应用的。以下摘录自原文:

总结:模型是通过 prompt engineering,即提供所有工具的结构化描述和 few-shot 的 example 来确定该使用哪些工具。另一方面,Anthropic 肯定对 Claude 做了专门的训练(毕竟是自家协议,Claude 更能理解工具的 prompt 以及输出结构化的 tool call json 代码)

Cline集成

cline是比较流行的AI编程工具,相关介绍可以参考

https://zhuanlan.zhihu.com/p/15806278946

https://zhuanlan.zhihu.com/p/20222456593

讲解了概念,重点分析的是,一个本地SQL服务作为MCP Server提供服务的实践。

其它分析视频

MCP是啥?技术原理是什么?一个视频搞懂MCP的一切

MCP是啥?技术原理是什么?一个视频搞懂MCP的一切。Windows系统配置MCP,Cursor Cline使用MCP_哔哩哔哩_bilibili

介绍了概念、Cursor实践、如何添加nodejs、python版本的常见的 MCP Server,还介绍了一些聚合网站smithery.ai等

以下是一些概念介绍

VSCode+Cline实践

Windows实践过程中,安装nodejs遇到的问题:

npx -v npx : File C:\Program Files\nodejs\npx.ps1 cannot be loaded because running scripts is disabled on this system. For mor e information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + npx -v + ~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

解决办法:以管理员权限运行Powershell,输入命令,Set-ExecutionPolicy RemoteSigned解决以上问题;

Windsurf集成MCP Server

Github - MCP Server | Windsurf Directory

注意:

  1. MCP 服务器使用 Token 进行身份验证

    • 当 MCP 服务器启动时,它会读取 GITHUB_PERSONAL_ACCESS_TOKEN 环境变量,并使用这个 token 来调用 GitHub API。

    • GitHub API 会根据这个 token 识别出你的 GitHub 账号,并允许你执行与该 token 权限相关的操作。

学习MCP2515可以按照以下步骤进行: 1. 获取相关资料:首先,您需要获取MCP2515的数据手册、应用笔记和参考资料等。这些资料将提供MCP2515的详细功能介绍、寄存器配置说明、通信协议和示例代码等。 2. 理解CAN总线协议:MCP2515是一个CAN控制器,因此您需要先了解CAN总线的基本原理和协议。学习CAN总线的基本概念、数据帧结构、帧ID、位定时和波特率等重要概念。 3. 硬件搭建:为了学习和测试MCP2515,您需要一个支持SPI通信的开发板或单片机,并连接MCP2515到相应的引脚上。确保硬件连接正确,并为MCP2515提供适当的电源和时钟。 4. 学习SPI通信:使用SPI接口与MCP2515进行通信是必要的。学习SPI通信的原理、时序和基本操作。了解如何初始化SPI通信并发送读写命令和数据。 5. 实验示例代码:根据MCP2515的数据手册和应用笔记,尝试编写一些简单的示例代码,例如初始化MCP2515、配置寄存器、发送和接收CAN数据帧等。通过实验示例代码,深入理解MCP2515的功能和使用方法。 6. 应用开发:一旦熟悉MCP2515的基本操作,您可以尝试将其应用于实际项目中。根据您的需求,编写代码实现更复杂的功能,例如过滤器设置、中断处理、多个CAN节点之间的通信等。 7. 社区和论坛:参与相关的社区和论坛,与其他使用MCP2515的开发者交流经验和解决问题。在这些平台上,您可以找到更多的应用案例、代码示例和技术支持。 请记住,学习MCP2515需要时间和实践。通过阅读文档、实验和不断尝试,您将逐渐掌握MCP2515的使用方法和应用技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值