微信扫码
添加专属顾问
 
                        我要投稿
MCP协议:大语言模型的革命性连接桥梁 核心内容: 1. MCP协议的定义及其解决的核心问题 2. MCP协议如何实现大模型与外部数据、工具的交互 3. MCP协议的客户端与服务器架构及交互方式
 
                                由 Anthropic 于2024年11月提出的开放协议,旨在解决大语言模型(LLM)与外部数据源、工具的标准化连接问题。
我的理解里面,mcp 就相当于人的手。如果是大模型是模拟人的大脑,我们之前和大模型的交互一直处在对话交流的形态。
但是有了 mcp,大脑的指令就能通过手来做实际的事情。
这里实际的事情包括但不限于:
所以 mcp 首先是需要有一个 client,这个 client 能处理接受用户需求,然后请求大模型,并且将大模型返回的信息分析出来指令,根据这些指令来调用 mcp 服务。
其次 mcp 要有一个 server,就是封装真实的行为的服务接口。比如我要用 Blender 软件绘制 3D 图片,那么我要在本地搭建一个 http 服务器,能调用 Blender 的各种对外接口来执行绘制。并且将这种能力提供给 mcp client。
一般来说,mcp 的 client 和 mcp 的 server 是在同一个机器上的。
在官网这里 https://modelcontextprotocol.io/introduction 将客户端分为 MCP Host, MCP Client。其实是一个意思。Host 指的是宿主,比如像 cursor,claude app 这样的软件,其中和 MCP server 交互的部分叫做 MCP Client。
这张图就很清晰说明了。
MCP Client 和 MCP Server 交互的时候,会分别通过 tools/list, resources/list,prompts/list 来获取这个 MCPServer 提供的哪些能力。
其中 tools/list 的接口示例:
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "search_arxiv",
        "description": "Search arXiv articles by keyword",
        "inputSchema": {
          "type": "object",
          "properties": {
            "keyword": {
              "type": "string",
              "title": "Search Query"
            },
            "max_results": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          },
          "required": ["keyword"]
        }
      },
      {
        "name": "create_issue",
        "description": "Create GitHub issue",
        "inputSchema": {
          "type": "object",
          "properties": {
            "repo": {"type": "string"},
            "title": {"type": "string"},
            "body": {"type": "string"}
          },
          "required": ["repo", "title"]
        }
      }
    ]
  }
}
resources/list 的接口示例
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "resources": [
      {
        "uri": "file:///var/log/app.log",
        "name": "Application Logs",
        "mimeType": "text/plain",
        "description": "Real-time server logs"
      },
      {
        "uriTemplate": "postgres://db/users/{user_id}",
        "name": "User Records",
        "mimeType": "application/json",
        "description": "Query user data by ID"
      }
    ]
  }
}
prompts/list 的接口示例
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "prompts": [
      {
        "name": "generate_report",
        "description": "Generate technical report template",
        "argumentsSchema": {
          "type": "object",
          "properties": {
            "title": {"type": "string"},
            "sections": {
              "type": "array",
              "items": {"type": "string"}
            }
          }
        }
      },
      {
        "name": "explain_code",
        "description": "Generate code explanation",
        "argumentsSchema": {
          "type": "object",
          "properties": {
            "code": {"type": "string"},
            "language": {"type": "string"}
          },
          "required": ["code"]
        }
      }
    ]
  }
}
如上我就提供了几个如下的功能。
tools/search_arxiv 获取论文resources/read 加载本地参考文献prompts/summarize 生成文献综述官网的 https://modelcontextprotocol.io/quickstart/server 有教你如何本地安装一个查看天气的 MCP Server。
这个 MCP Server 提供了两个工具 :get-alertsandget-forecast
我自己亲测,官网的这个是可行的。
这里说几个官网没有说到的点:
mcp 命令
mcp dev weather.py (这个命令要在 venv 环境下运行)(weather) ➜  weather git:(master) ✗ mcp dev weather.py
Need to install the following packages:
@modelcontextprotocol/inspector@0.6.0
Ok to proceed? (y) y
Starting MCP inspector...
Proxy server listening on port 3000
? MCP Inspector is up and running at http://localhost:5173 ?
在本地浏览器打开 5173 端口,出现页面
你也可以很方便在上面调用某个 tool 工具
我们这个 MCP Server 是通过 uv 命令启动起来的,它的配置文件如下:
{
 "mcpServers": {
  "weather": {
   "command": "uv",
   "args": [
    "--directory",
    "/Users/jianfengye/Documents/workspace/mcp/weather",
    "run",
    "weather.py"
   ]
  }
 }
}
在 cursor 配置好,enable 就能看到这个服务提供的 tools
你可以在 cursor 中使用 @mcp 来询问美国纽约的天气
这里注意的点就是官网给出的接口只能查询美国的,所以不要尝试查询中国地区的天气。
开源社区有一个:https://github.com/punkpeye/awesome-mcp-servers
可以访问 https://glama.ai/mcp/servers 进行查询。
Claude 官方也创建了一个 MCP Server 集中地:https://cursor.directory
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-10-31
Opera One升级内置AI 迎来智能助手新纪元
2025-10-31
LangExtract——大模型文本提炼工具
2025-10-31
用户测评|DeepSeek-OCR,你用了吗?
2025-10-31
从Palantir智能化技术路线看AI时代企业级架构平台的核心战略位置
2025-10-31
OpenAI 公开 Atlas 架构:为 Agent 重新发明浏览器
2025-10-31
Palantir 本体论模式:重塑企业 AI 应用的 “语义根基” 与产业启示
2025-10-31
树莓派这种“玩具级”设备,真能跑大模型吗?
2025-10-30
Cursor 2.0的一些有趣的新特性
 
            2025-08-21
2025-08-21
2025-08-19
2025-09-16
2025-10-02
2025-09-08
2025-09-17
2025-08-19
2025-09-29
2025-08-20