From 1f3e37fed18068bfa3710cc3ecb391829eab0468 Mon Sep 17 00:00:00 2001 From: bluish <734499798@qq.com> Date: Thu, 29 Jan 2026 03:44:40 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=96=B0blog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/sponsorConfig.ts | 71 ++++--- src/content/posts/mcp_skills/index.md | 263 ++++++++++++++++++++++++++ src/content/posts/prompt.md | 2 +- 3 files changed, 296 insertions(+), 40 deletions(-) create mode 100644 src/content/posts/mcp_skills/index.md diff --git a/src/config/sponsorConfig.ts b/src/config/sponsorConfig.ts index 239c27b..f82caca 100644 --- a/src/config/sponsorConfig.ts +++ b/src/config/sponsorConfig.ts @@ -9,41 +9,34 @@ export const sponsorConfig: SponsorConfig = { // 赞助用途说明 usage: - "您的赞助将用于服务器维护、内容创作和功能开发,帮助我持续提供优质内容。", + // "您的赞助将用于服务器维护、内容创作和功能开发,帮助我持续提供优质内容。", + "点个赞支持一下", // 是否显示赞助者列表 - showSponsorsList: true, + showSponsorsList: false, // 是否在文章详情页底部显示赞助按钮 - showButtonInPost: true, + showButtonInPost: false, // 赞助方式列表 methods: [ - { - name: "支付宝", - icon: "fa6-brands:alipay", - // 收款码图片路径(需要放在 public 目录下) - qrCode: "/assets/images/sponsor/alipay.png", - link: "", - description: "使用 支付宝 扫码赞助", - enabled: true, - }, - { - name: "微信", - icon: "fa6-brands:weixin", - qrCode: "/assets/images/sponsor/wechat.png", - link: "", - description: "使用 微信 扫码赞助", - enabled: true, - }, - { - name: "爱发电", - icon: "simple-icons:afdian", - qrCode: "", - link: "https://afdian.com/a/cuteleaf", - description: "通过 爱发电 进行赞助", - enabled: true, - }, + // { + // name: "支付宝", + // icon: "fa6-brands:alipay", + // // 收款码图片路径(需要放在 public 目录下) + // qrCode: "/assets/images/sponsor/alipay.png", + // link: "", + // description: "使用 支付宝 扫码赞助", + // enabled: true, + // }, + // { + // name: "微信", + // icon: "fa6-brands:weixin", + // qrCode: "/assets/images/sponsor/wechat.png", + // link: "", + // description: "使用 微信 扫码赞助", + // enabled: true, + // }, { name: "Github", icon: "fa6-brands:github", @@ -57,18 +50,18 @@ export const sponsorConfig: SponsorConfig = { // 赞助者列表(可选) sponsors: [ // 示例:已实名赞助者 - { - name: "夏叶", - amount: "¥50", - date: "2025-10-01", - message: "感谢分享!", - }, + // { + // name: "夏叶", + // amount: "¥50", + // date: "2025-10-01", + // message: "感谢分享!", + // }, // 示例:匿名赞助者 - { - name: "匿名用户", - amount: "¥20", - date: "2025-10-01", - }, + // { + // name: "匿名用户", + // amount: "¥20", + // date: "2025-10-01", + // }, ], }; diff --git a/src/content/posts/mcp_skills/index.md b/src/content/posts/mcp_skills/index.md new file mode 100644 index 0000000..6be3a78 --- /dev/null +++ b/src/content/posts/mcp_skills/index.md @@ -0,0 +1,263 @@ +--- +title: MCP、SKILLS详解 +published: 2026-01-14 +pinned: false +description: 什么是MCP、SKILLS?它们是怎么工作的? +tags: [MCP、SKILLS] +category: 学习日志 +draft: false +--- +> 参考文章: +> * 1、[MCP官方文档](https://modelcontextprotocol.io/docs/getting-started/intro) +> * 2、[官方仓库](https://github.com/modelcontextprotocol/python-sdk) +# MCP +> MCP(模型上下文协议)是一个开源标准,用于连接 AI 应用程序到外部系统。使用 MCP,像 Claude 或 ChatGPT 这样的 AI 应用可以连接到数据源(例如本地文件、数据库)、工具(例如搜索引擎、计算器)和工作流程(例如专业提示),从而使其能够访问关键信息并执行任务。 +将 MCP 想象成 AI 应用的 USB-C 接口。就像 USB-C 为电子设备提供了一种标准化的连接方式一样,MCP 也为 AI 应用连接外部系统提供了一种标准化的方式。 + +简单来说,MCP是一种协议,类似HTTP协议。它定义了大模型工具的通信标准,不再像function call时期,每个工具需要针对性地定制。它做到了通用性,这让我们可以接入其他开发者或者公司开发的MCP拓展智能体的能力。想让智能体规划旅游路线?我们可以接入小红书的MCP搜索攻略,再接入高德地图的MCP进行路线规划。这样一个可以做旅游攻略的智能体就做好了。这大大减少了开发的时间和工作量。 + +# MCP的基础概念 +## MCP Host +AI应用程序,协调管理多个MCP客户端。常见的有Claude Code、Codex、Cursor、Cherry Studio等。 +## MCP Server +MCP服务端,拥有制作好的一系列工具,当客户端连接时,会发送服务端拥有的工具和描述,作为context提供给客户端。 +## MCP Client +MCP客户端,从MCP服务端获取context供MCP Host使用。 + +## 数据层和传输层 +### 数据层 +#### 生命周期管理 +管理客户端和服务端连接建立、能力协商、连接终止。 +目的是协商客户端和服务器都支持的功能。 +原语是定义服务端和客户端可以互相提供的内容。 +服务器原语包含以下三种: +* Tools:AI 应用程序可调用的可执行函数,用于执行操作(例如,文件操作、API 调用、数据库查询) +* Resources:为 AI 应用程序提供上下文信息的数据源(例如,文件内容、数据库记录、API 响应) +* Prompts:可重用的模板,帮助构建与语言模型的交互(例如,系统提示、少量示例) +客户端原语: +* Sampling:可以使用sampling/complete要求客户端进行大模型的补全 +* Elicitation:允许服务器从用户请求额外信息。当服务器作者希望从用户获取更多信息,或请求确认某个操作时,这很有用。他们可以使用 elicitation/request 方法从用户请求额外信息。 +* Logging:使服务器能够向客户端发送日志消息,用于调试和监控目的。 +还有更多的: +* Tasks (Experimental):持久执行包装器,支持延迟结果检索和 MCP 请求的状态跟踪(例如,高成本计算、工作流自动化、批量处理、多步操作) +每种原语都有相关的*/list、*/get、toos/call方法。 +#### 服务器功能 +服务器能够提供的能力,如可以提供给ai执行的工具、提供的数据资源、交互的提示词模板 +#### 客户端功能 +客户端功能:使服务器能够请求客户端从主机 LLM 中采样,从用户处获取输入,并将消息记录到客户端 +#### 附加功能 +附加功能:支持通知实时更新和长时间运行操作的过程跟踪 +### 传输层 +支持两种传输形式: +1、stdio 传输:使用标准输入/输出流,在本地同一台机器上的本地进程之间进行直接进程通信,提供最佳性能且无网络开销。 +2、流式 HTTP 传输:使用 HTTP POST 传输客户端到服务器的消息,并可选地使用 Server-Sent Events 实现流式传输功能。该传输方式支持远程服务器通信,并支持标准 HTTP 认证方法,包括授权令牌、API 密钥和自定义头信息。MCP 推荐使用 OAuth 获取认证令牌。 +MCP 使用 JSON-RPC 2.0 作为其底层 RPC 协议。客户端和服务端相互发送请求并作出相应回应。当不需要响应时,可以使用通知。 + + + +创建一个专业的技术架构流程图,展示MCP(Model Context Protocol)的完整交互过程。图像要求如下: +整体布局: + +采用从上到下的垂直流程图风格 +左侧显示"MCP Client(客户端)",右侧显示"MCP Server(服务器)" +使用清晰的箭头表示请求和响应的方向 +背景为浅色(白色或浅灰色),便于阅读 +采用现代扁平化设计风格 + +四个主要交互步骤(按顺序排列): +步骤1 - 初始化(Initialization): + +从Client到Server的箭头,标注"1. initialize request" +在箭头旁边显示JSON代码框: + +{ + "jsonrpc": "2.0", + "id": 1, + "method": "initialize", + "params": { + "protocolVersion": "2025-06-18", + "capabilities": { + "elicitation": {} + }, + "clientInfo": { + "name": "example-client", + "version": "1.0.0" + } + } +} +* 协议版本协商: protocolVersion 字段(例如,“2025-06-18”)确保客户端和服务器使用兼容的协议版本。这可以防止不同版本尝试交互时可能发生的通信错误。如果未能协商出相互兼容的版本,则应终止连接。 +* 能力发现: capabilities 对象允许每一方声明他们支持的功能,包括他们能够处理的原语(工具、资源、提示)以及他们是否支持通知等特性。这通过避免不支持的操作来实现高效通信。 +* 身份交换: clientInfo 和 serverInfo 对象提供用于调试和兼容性的识别和版本信息。 +* "elicitation": {} - 客户端声明它可以处理用户交互请求(可以接收 elicitation/create 方法调用) +从Server返回Client的箭头,标注"initialize response" +显示响应JSON: + +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "protocolVersion": "2025-06-18", + "capabilities": { + "tools": { + "listChanged": true + }, + "resources": {} + }, + "serverInfo": { + "name": "example-server", + "version": "1.0.0" + } + } +} +"tools": {"listChanged": true} - 服务器支持工具原语,并且当其工具列表发生变化时可以发送 tools/list_changed 通知 +"resources": {} - 服务器也支持资源原语(可以处理 resources/list 和 resources/read 方法) + +初始化成功后,客户端发送通知表示已准备就绪: +{ + "jsonrpc": "2.0", + "method": "notifications/initialized" +} +步骤2 - 工具发现(Tool Discovery): + +Client到Server箭头,标注"2. tools/list request" +JSON代码框: + +{ + "jsonrpc": "2.0", + "id": 2, + "method": "tools/list" +} + +Server返回箭头,显示"tools/list response" +响应JSON: + +{ + "jsonrpc": "2.0", + "id": 2, + "result": { + "tools": [ + { + "name": "calculator_arithmetic", + "title": "Calculator", + "description": "Perform mathematical calculations including basic arithmetic, trigonometric functions, and algebraic operations", + "inputSchema": { + "type": "object", + "properties": { + "expression": { + "type": "string", + "description": "Mathematical expression to evaluate (e.g., '2 + 3 * 4', 'sin(30)', 'sqrt(16)')" + } + }, + "required": ["expression"] + } + }, + { + "name": "weather_current", + "title": "Weather Information", + "description": "Get current weather information for any location worldwide", + "inputSchema": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "City name, address, or coordinates (latitude,longitude)" + }, + "units": { + "type": "string", + "enum": ["metric", "imperial", "kelvin"], + "description": "Temperature units to use in response", + "default": "metric" + } + }, + "required": ["location"] + } + } + ] + } +} + +name : 服务器命名空间内该工具的唯一标识符。它是工具执行的主键,应遵循清晰的命名模式(例如, calculator_arithmetic 而不是单纯的 calculate )。 +title : 客户端向用户展示的工具的名称 +description : 对工具功能进行详细说明以及何时使用该工具 +inputSchema : 一个定义预期输入参数的 JSON Schema,支持类型验证并提供关于必需和可选参数的清晰文档 + +步骤3 - 工具执行(Tool Execution): + +Client到Server箭头,标注"3. tools/call request" +JSON代码框: + +{ + "jsonrpc": "2.0", + "id": 3, + "method": "tools/call", + "params": { + "name": "weather_current", + "arguments": { + "location": "San Francisco", + "units": "imperial" + } + } +} +name : 必须与发现响应中的工具名称( weather_current )完全匹配。这确保服务器能够正确识别要执行的工具。 +arguments : 包含工具的 inputSchema 定义输入参数。在此示例中: +location : “旧金山”(必需参数) +units : “imperial” (可选参数,若未指定则默认为 “metric”) +Server返回箭头,显示响应 +响应JSON: + +{ + "jsonrpc": "2.0", + "id": 3, + "result": { + "content": [ + { + "type": "text", + "text": "Current weather in San Francisco: 68°F, partly cloudy with light winds from the west at 8 mph. Humidity: 65%" + } + ] + } +} +content 数组:工具响应返回一个内容对象数组,允许进行丰富、多格式的响应(文本、图片、资源等) +type内容类型:每个内容对象都有一个 type 字段。在这个例子中, "type": "text" 表示纯文本内容,但 MCP 支持多种内容类型以适应不同场景。 + +步骤4 - 通知(Notification): + +Server主动向Client发送箭头(虚线表示),标注"4. notifications/tools/list_changed" +JSON代码框: + +{ + "jsonrpc": "2.0", + "method": "notifications/tools/list_changed" +} +特性: +无需响应:请注意通知中没有 id 字段。这遵循 JSON-RPC 2.0 通知语义,即不期望或发送响应。 +基于能力的:此通知仅由在初始化期间(如步骤 1 所示)在其工具能力中声明了 "listChanged": true 的服务器发送。 +事件驱动:服务器根据内部状态变化决定何时发送通知,使 MCP 连接动态且响应迅速。 + +Client响应性地发送新的tools/list请求(循环回步骤2) +{ + "jsonrpc": "2.0", + "id": 4, + "method": "tools/list" +} +通知可以实现的特性: +动态环境:工具可能根据服务器状态、外部依赖或用户权限出现或消失 +效率:客户端无需轮询以检查变化;当更新发生时,他们会收到通知 +一致性:确保客户端始终拥有关于可用服务器能力的准确信息 +实时协作:支持响应式 AI 应用,使其能够适应变化的上下文 + +设计要素: + +所有JSON代码使用等宽字体,放在圆角矩形框内 +请求箭头使用实线蓝色,响应箭头使用实线绿色 +通知使用橙色虚线箭头强调其异步特性 +每个步骤用大号数字标注(1、2、3、4) +Client和Server用不同的背景色区分(Client浅蓝色,Server浅绿色) +在图的顶部添加标题"MCP Architecture - Client-Server Interaction Flow" +在底部添加图例说明:实线=请求/响应,虚线=通知 + +风格参考: + +类似AWS架构图或系统设计图的专业风格 +清晰、简洁、信息密度适中 +适合技术文档和演示使用 \ No newline at end of file diff --git a/src/content/posts/prompt.md b/src/content/posts/prompt.md index 6658cb4..83f6c30 100644 --- a/src/content/posts/prompt.md +++ b/src/content/posts/prompt.md @@ -1,6 +1,6 @@ --- title: 什么是大模型提示词? -published: 2025-01-03 +published: 2026-01-09 pinned: false description: 什么是大模型提示词? tags: [Prompt]