freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

那我问你,MCP是什么?回答我!
yaklang 2025-03-24 14:53:02 7539
所属地 四川省

1742798603_67e0ff0b7c3bd5027792b.jpg!small1742798198_67e0fd7602c48df2851fc.png!small

1742798685_67e0ff5def614bbf14d2e.png!small我们知道,AI虽然非常强大,但常常会被迫“束手束脚”。例如,医生问诊需同时调取病历、化验结果和医学文献,复杂任务需要多个工具一起协同执行。MCP的核心价值在于:
  • 统一连接:通过MCP,AI可访问本地文件、云端数据库甚至实时金融数据。
  • 动态协作:多个工具互相协作,例如爬虫任务中一个工具负责爬取网页内容,另外一个工具负责处理爬取信息,最后一个工具用于生成报告。从此,AI从"QA问答机"升级为"全能执行者"。

1742798702_67e0ff6e3bc671c1014e1.png!small

1742798708_67e0ff748e07423a46a87.png!small

MCP的通信协议底层基于STDIO(标准输入输出)或SSE(Server-Send Events),顶层则基于JSON-RPC 2.0

此外,MCP的架构设计极简却高效,包含三大组件:

  • 主机(如Claude):调用客户端来获取服务器的资源/工具列表,解析AI响应以调用客户端发送任务请求,将客户端的响应提供给AI

  • 客户端:发送任务请求,处理服务器响应返回给主机

  • 服务器:解析任务请求以提供数据或工具服务
1742798711_67e0ff77787449d1bb7a2.png!small有了解过Function call的小伙伴们可能发现了,MCP最终实现的功能似乎与Function call类似,都是使得AI能够与外部链接,那么他们的区别是什么呢?
MCPFunction Call
协议栈应用层协议(OSI Layer 7)模型功能扩展
服务发现机制可以动态通知并修改预编译函数列表,无法修改
工具接入方式支持多个工具热插拔冷加载
实际上,MCP的Host也可以使用Function Call来实现,前提是模型本身要支持Function Call。一种更通用适合所有模型的的方法则是在System Prompt中告诉AI其能够使用的工具与资源。一个Prompt的例子如下(来自vscode插件-cline):
You must respond to the user's request by using at least one tool call. When formulating your response, follow these guidelines:

1. Begin your response with normal text, explaining your thoughts, analysis, or plan of action.
2. If you need to use any tools, place ALL tool calls at the END of your message, after your normal text explanation.
3. You can use multiple tool calls if needed, but they should all be grouped together at the end of your message.
4. After placing the tool calls, do not add any additional normal text. The tool calls should be the final content in your message.

Here's the general structure your responses should follow:

```
[Your normal text response explaining your thoughts and actions]

[Tool Call 1]
[Tool Call 2 if needed]
[Tool Call 3 if needed]
...
```
Remember:
- Choose the most appropriate tool(s) based on the task and the tool descriptions provided.
- Formulate your tool calls using the XML format specified for each tool.
- Provide clear explanations in your normal text about what actions you're taking and why you're using particular tools.
- Act as if the tool calls will be executed immediately after your message, and your next response will have access to their results.

# Tool Descriptions and JsonSchema
1.
{
  "title": "execute_command",
  "description": "Execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory.",
  "type": "object",
  "required": [
    "command"
  ],
  "properties": {
    "command": {
      "type": "string",
      "description": "Your command here"
    }
  }
}

2. list_files:
{
  "title": "list_files",
  "description": "List files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents.", 
  "type": "object",
  "required": [
    "path"
  ],
  "properties": {
    "path": {
      "type": "string",
      "description": "Directory path here"
    },
    "recursive": {
      "type": "boolean"
    }
  }
}
实际预见的是,连接的MCP服务器越多,提供的资源/工具越多,那么每次提问所要消耗的token也就越多。1742798719_67e0ff7f0732a05182b96.png!small

基于Yakit的MCP Host仍在开发中,但是Yaklang的MCP server实际上已经可以使用了。我们可以使用其他的MCP Host来尝鲜一下。

  1. 打开vscode,下载以下插件之一(前者Roo Code是社区驱动的Cline,新功能和更新比较频繁):

1742798722_67e0ff82a3da55d528ccc.png!small

  1. 打开Roo Code页面,点击MCP Servers设置,Edit MCP Settings:

1742798727_67e0ff87c1e10f00d9338.png!small

  1. 输入配置,其中command改为你实际的yak的路径:
{
  "mcpServers": {
    "yaklang-mcp": {
      "command": "yak.exe",
      "args": ["mcp"],
      "env": {},
      "disabled": false,
      "alwaysAllow": [],
      "timeout": 3600
    }
  }
}
  1. 开始使用,这里以弱口令爆破为例:

1742798735_67e0ff8f3a34d011109ca.png!small

1742798737_67e0ff91b340ede4c09ae.png!small

1742798759_67e0ffa7e5106238a14f2.png!small

END

Yak 语言官方教程:
https://yaklang.com/docs/intro/
Yakit 视频教程:
https://space.bilibili.com/437503777
Github下载地址:
https://github.com/yaklang/yakit
Yakit官网下载地址:
https://yaklang.com/
Yakit安装文档:
https://yaklang.com/products/download_and_install
Yakit使用文档:
https://yaklang.com/products/intro/
常见问题速查:
https://yaklang.com/products/FAQ

# AI安全 # yakit
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 yaklang 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
yaklang LV.8
做难而正确的事!
  • 153 文章数
  • 105 关注者
独立SyntaxFlow功能?IRify,启动!
2025-03-31
SyntaxFlow实战CVE漏洞?那很好了
2025-03-14
SyntaxFlow Java实战(一):值的搜索与筛选
2025-03-10