今天没什么事,花十分钟水一水文章。
交互
按照https://mp.weixin.qq.com/s/DsKQ0vp4ywRlJRAdORKvqQ获取OpenRouter apikey。而后在cloudflare中配置ai gateway,并在右上角获取到api gateway地址
而后在cline中配置,如下图,选择openai compatible
配置好MCP server后,在聊天框中触发mcp,即可在cloudflare面板中看到具体的请求。
可以看到在cline中会启动子进程,获取到现有的tools,当用户请求时,把获取到的tools及其描述放到提示词里面。
{
"model": "google/gemini-2.5-pro-exp-03-25:free",
"messages": [
{
"role": "system",
"content": "You are Cline, `use_mcp_tool` tool, and access the server's resources via the `access_mcp_resource` tool.nn## git (`python -m mcp_server_ida`)nn### Available Tools
把用户输入作为user放到请求的task里面
{
"role": "user",
"content": [
{
"type": "text",
"text": "<task>n"xxx</task>"
},
{
而后大模型会在response里面根据用户输入选择对应的tools并组合对应的参数,传给mcp client
{
"id": "gen--",
"provider": "Google AI Studio",
"model": "google/gemini-2.5-pro-exp-03-25",
"choices": [
{
"delta": {
"role": "assistant",
"content": "Okay, I will call the tool from the `mcp`.nn<use_mcp_tool>n<server_name>mcp</server_name>n<tool_name></tool_name>n<arguments>n{n"": "",n"": \n}n</arguments>n</use_mcp_tool>"
}
之后mcp client就可以把参数通过stdio传给mcp server,之后再次请求,把执行结果给大模型。
{
"role": "user",
"content": [
{
"type": "text",
"text": "[use_mcp_tool for 'mcp'] Result:"
},
{
"type": "text",
"text": "successfully."
},
大模型就可以根据mcp server执行结果,生成自然语言的回复给用户
{
"id": "gen-1744277319-",
"provider": "Google AI Studio",
"model": "google/gemini-2.5-pro-exp-03-25",
"choices": [
{
"delta": {
"role": "assistant",
"content": "<attempt_completion>n<result>nn</result>n</attempt_completion>"
}
}
],
那么从上面的交互过程你能想到什么攻击方式吗?
原文始发于微信公众号(闲聊趣说):透视MCP交互
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论