模型上下文协议

介绍

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.

Why MCP?

MCP helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides:

  • A growing list of pre-built integrations that your LLM can directly plug into
  • The flexibility to switch between LLM providers and vendors
  • Best practices for securing your data within your infrastructure

基础架构

At its core, MCP follows a client-server architecture where a host application can connect to multiple servers:

  • MCP Hosts: Programs like Claude Desktop, IDEs, or AI tools that want to access data through MCP
  • MCP Clients: Protocol clients that maintain 1:1 connections with servers
  • MCP Servers: Lightweight programs that each expose specific capabilities through the standardized Model Context Protocol
  • Local Data Sources: Your computer’s files, databases, and services that MCP servers can securely access
  • Remote Services: External systems available over the internet (e.g., through APIs) that MCP servers can connect to

举几个通俗的例子来说明含义:

  • MCP Hosts: 就是运行在你电脑上的应用程序,比如说Claude Desktop,VS Code,AI助手等,他们希望可以通过MCP协议来访问数据。比如说: 你在用Claude Desktop,想让他帮你分析本地的excel的文件;或者你在Vscode里面,用一个AI插件来帮你读写文件代码文件;或者一个AI助手的应用,想访问你的本地数据库做智能问答。

  • MCP Clients: 和MCP服务器保持一对一连接的协议客户端,负责发起请求和接收数据。 比如说,Claude Desktop 里的“文件浏览”功能,就是一个 MCP Client,它和 MCP Server 建立连接,请求文件内容;或者说一个命令行工具, 通过MCP协议连接到本地的图片识别的服务,上传图片并获取识别结果。

  • MCP Servers: 轻量级的程序,每个都通过MCP协议暴露某一类能力(比如文件访问,数据库查询等)。比如说,一个MCP Server负责让外部程序读取你电脑上的文件,另外一个MCP Server负责让外部的程序访问本地的SQLite数据库。还有一个MCP server负责调用你电脑上的摄像头,返回拍摄的照片。

  • Local Data Sources: 你电脑上的各种数据资源,比如文件、数据库、服务等,MCP server可以完全访问他们。例如: 你的电脑里的所有文件,你本地与逆行的MYSQL或者SQLite数据库,电脑上的打印机,摄像头等硬件服务。

  • Remote Services: 通过互联网可以访问外部系统或者API,MCP Server也可以连接这些服务。 例如: 一个MCP Server连接到OpenAI的API,帮你调用GPT模型;连接到Google Drive API,帮你读写云端的文件。 甚至是连接到公司内部的RESTFul API,获取业务数据。

简单的总结一下就是:

  1. Host 是“想要用数据的应用”,比如 Claude Desktop、VS Code。
  2. Client 是“发起请求的协议客户端”,比如 Claude Desktop 里的某个功能模块。
  3. Server 是“提供具体能力的小服务”,比如文件访问、数据库访问等。
  4. Local Data Sources 是“你电脑上的数据资源”。
  5. Remote Services 是“互联网上的外部服务”。

参考链接

版权声明: 如无特别声明,本文版权归 sshipanoo 所有,转载请注明本文链接。

(采用 CC BY-NC-SA 4.0 许可协议进行授权)

本文标题:《 Model Context Protocol 》

本文链接:http://0.0.0.0:3015/ai/mcp.html

本文最后一次更新为 天前,文章中的某些内容可能已过时!