拆解 MCP 的运行原理

注意:此实验非常消耗模型 Token
背景:最近 MCP 火的发烫,什么是 MCP 就不讨论了,比较好奇 MCP 具体的运行逻辑。
现象:同时使用 Cursor 和 MaxKB 对接腾讯地图的 MCP Server,发现返回的内容有较大差别。(和模型能力有较大关系)

Cursor 的返回结果,使用的是 Claude- 3.5:

MaxKB 的返回结果,此时使用的是阿里百炼的 qwen-turbo 模型:

实验目的:从大模型的角度拆解 MCP 的运行原理是什么,使用 CloudFlare 代理 AI 模型,看一下具体的调用链路,做过程记录。

具体原理:

注:MCP Client 在 Call 大模型的时候会提交大量包含工具使用等内容的提示词

实验步骤:

用到的工具:CloudFlare、OpenRouter、MaxKB、腾讯地图 MCP Server、Cursor

1、构建 Cloudflare AI Gateway

通过 CloudFlare 代理大模型,从而记录 API 调用

2、创建一个 OpenRouter 的 Platform

代理 OpenRouter


保管此 API Endpoint

3、注册 OpenRouter 并获取 Key

目的是免费使用合适的大模型

4、在 MaxKB 中添加 CloudFlare 代理的 AI 模型

用对接 OpenAI 的方式对接 通过 CloudFlare 代理的运行在 OpenRouter 上的 Claude。(这里有点绕,,,)

基础模型:在 OpenRouter 模型列表中的模型名称,此处选用 Cloude-3.5-sonnet

API URL:CloudFlare AI Gateway 的 API Endpoint

API Key:OpenRouter 上获取的 Key

5、注册腾讯地图服务并获取 Key

为什么选用腾讯地图的 MCP 服务?因为腾讯地图官方提供托管面部署的 MCP Server。

登录腾讯地图开发者平台,地址:https://lbs.qq.com/dev/console/home

创建应用并获取 Key

开启 API 配额,要不 API 无法调用

6、在MaxKB中添加腾讯地图 MCP Server

MCP Server 配置参考样例:

{
  "tengxunditu": {
    "url": "https://mcp.map.qq.com/sse?key=xxxx-xxxx-xxxx-xxxx-xxxx-xxxx",
    "transport": "sse"
  }
}

详情参考官方手册:https://lbs.qq.com/service/MCPServer/MCPServerGuide/userGuide

7、在 MaxKB 的工作流中使用使用 MCP 方式调用

注:此时使用的是 Claude-3.5-sonnet ,效果和在 Cursor 上使用比较接近

8、查看 CloudFlare AI Gateway 的记录

如图是一个 MCP 任务的 API 调用及消耗,单次 MCP 执行约消耗 10W Tokens

log 太多,这里放一部分。

请求:
{
  "messages": [
    {
      "content": "问题:\n帮我规划从深圳会展中心去深圳宝安机场的驾车路线,中途去深圳车公庙地铁站附近加个油",
      "role": "user"
    }
  ],
  "model": "anthropic/claude-3.5-sonnet",
  "max_completion_tokens": 800,
  "stream": true,
  "temperature": 0.7,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "geocoder",
        "description": "提供由文字地址(包含省市区信息的完整地址)到经纬度的转换能力,并同时提供结构化的省市区地址信息",
        "parameters": {
          "type": "object",
          "properties": {
            "address": {
              "description": "包含省市区信息的的格式化地址 或 包含城市名的地点关键词",
              "type": "string"
            }
          },
          "required": [
            "address"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "placeSuggestion",
        "description": "根据要搜索地点的关键词和搜索的城市(城市名),搜索符合条件的地点信息, 返回包括地点名称、地址、经纬度、分类等(如搜索北京的景点、酒店、购物场景,搜索某个地方的详细地址等)",
        "parameters": {
          "type": "object",
          "properties": {
            "keyword": {
              "description": "关键词,地点名称",
              "type": "string"
            },
            "region": {
              "description": "搜索城市,如果不知道城市名,可不输入本参数",
              "type": "string"
            }
          },
          "required": [
            "keyword"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "placeSearchNearby",
        "description": "附近周边搜索,输入的搜索关键词,中心点经纬度(格式lat,lng)搜索其周边符合条件的地点信息 返回包括地点名称、地址、经纬度、分类等(如搜索北京的景点、酒店、购物场景,搜索某个地方的详细地址等)",
        "parameters": {
          "type": "object",
          "properties": {
            "keyword": {
              "description": "关键词,地点名称",
              "type": "string"
            },
            "location": {
              "description": "搜索中心点经纬度(可以通过地址解析将文字地址转为经纬度),格式lat,lng",
              "type": "string"
            }
          },
          "required": [
            "location",
            "keyword"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "directionDriving",
        "description": "根据起终点经纬度,规划驾车路线,支持参考路况、少收费、不走高速等偏好,同时支持返回路线预估用时,路线距离,过路费等信息",
        "parameters": {
          "type": "object",
          "properties": {
            "from": {
              "description": "起点经纬度,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)经纬度,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "placeAlongby",
        "description": "在路线的沿途进行搜索:输入路线的经纬度坐标串和搜索关键词,搜索该路线沿途符合该关键词的地点,路线的经纬度点串,可以通过驾车路线规划获取",
        "parameters": {
          "type": "object",
          "properties": {
            "keyword": {
              "description": "搜索关键词,例如:充电站、厕所、停车场、购物、加油站、银行ATM、加气站、便利店、服务区、汽车维修、中石油、中石化",
              "type": "string"
            },
            "polyline": {
              "description": "经纬度点构成的折线,结构是lat1,lng1,lat2,lng2,lat3,lng4....",
              "type": "string"
            }
          },
          "required": [
            "polyline",
            "keyword"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "placeDetail",
        "description": "POI详情信息,根据POI ID搜索相关信息,包括:名称、地址、经纬度、分类、省市区信息。如果查询结果为空,则返回POI ID不存在",
        "parameters": {
          "type": "object",
          "properties": {
            "id": {
              "description": "poiid",
              "type": "string"
            }
          },
          "required": [
            "id"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "matrix",
        "description": "用于批量计算多个起终点到多个终点的路面距离(或称导航距离)",
        "parameters": {
          "type": "object",
          "properties": {
            "from": {
              "description": "起点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "mode": {
              "description": "通行方式,驾车为driving, 步行为walking, 骑行为bicycling。 不支持其他通行方式",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to",
            "mode"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "reverseGeocoder",
        "description": "输入经纬度坐标,返回其所在位置的语义化地址、省、市、区、乡镇、门牌号、行政区划代码、商圈、地标、道路及交叉口、河流、湖泊、桥等",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "description": "经纬度坐标,结构是lat,lng",
              "type": "string"
            }
          },
          "required": [
            "location"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "ipLocation",
        "description": "通过终端设备IP地址获取其当前所在省、市、区信息。",
        "parameters": {
          "type": "object",
          "properties": {
            "ip": {
              "description": "IP地址(IPv4或IPv6)",
              "type": "string"
            }
          },
          "required": [
            "ip"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "weather",
        "description": "通过行政区划代码,查询对应城市的实时天气或预报天气。",
        "parameters": {
          "type": "object",
          "properties": {
            "adcode": {
              "description": "行政区划代码(可通过调用地址解析获取,输入地址或城市名,返回结果中的adcode即为行政区划代码)",
              "type": "string"
            },
            "type": {
              "description": "可选now或者future。用户查询当前天气为now,查询未来天气为future。可为空,默认为now。",
              "type": "string"
            }
          },
          "required": [
            "adcode"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "directionWalking",
        "description": "根据起终点经纬度,规划步行路线,返回包括路线总距离、预估用时等",
        "parameters": {
          "type": "object",
          "properties": {
            "from": {
              "description": "起点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "directionBicycling",
        "description": "根据起终点经纬度,规划自行车骑行路线,返回包括路线总距离、预估用时等",
        "parameters": {
          "type": "object",
          "properties": {
            "from": {
              "description": "起点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "directionTransit",
        "description": "公共交通路线规划,根据起终点经纬度,规划公交/地铁线路乘坐方案, 支持指定出发时间(确保线路在首末车时段内),支持时间短、少换乘、少步行、地铁优先等多种偏好,为您规划多组乘坐方案, 同时返回路线总预估用时、总距离、总步行距离、票价,具体线路如何换乘(线路名、上车站、下车站名等)、首末车时间等",
        "parameters": {
          "type": "object",
          "properties": {
            "from": {
              "description": "起点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "futureDrivingDirection",
        "description": "根据起终点经纬度、未来出发时间,规划驾车驾车路线,路线会考虑未来时间的预测路况进行规划,支持返回预估用时、总距离等信息",
        "parameters": {
          "type": "object",
          "properties": {
            "departure_time": {
              "description": "出发时间(时间戳格式)",
              "type": "string"
            },
            "from": {
              "description": "起点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to",
            "departure_time"
          ]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "waypointOrder",
        "description": "基于驾车路线规划,对输入的途经点以最顺路方式排序并规划路线,排序途经点最多16个。返回结果中的waypoints代表途经点的顺序",
        "parameters": {
          "type": "object",
          "properties": {
            "from": {
              "description": "起点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "need_waypoint_order": {
              "description": "如果waypoints不是空,则传true",
              "type": "string"
            },
            "to": {
              "description": "终点(目的地)点经纬度信息,结构是lat,lng。 如果输入的是包含省市区信息的完整地址,可以调用地址解析获取经纬度, 如果是地点名称,可调用地点搜索获取经纬度(返回多条结果时可取第1条)",
              "type": "string"
            },
            "waypoints": {
              "description": "途经点经纬度,支持最多16个,结构是lat1,lng1;lat2,lng2;lat3,lng3....如果输入的是地址,则需要调用geocoder获取经纬度信息",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to"
          ]
        }
      }
    }
  ]
}
----------------------------------------------------------------------------------------------------------------------------------------------------
返回:
{
  "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
  "provider": "Amazon Bedrock",
  "model": "anthropic/claude-3.5-sonnet",
  "choices": [
    {
      "delta": {
        "role": "assistant",
        "content": "我来帮您规划这段行程。这需要分几步:\n1. 先获取各个地点的具体位置和经纬度\n2. 规划加油站的最佳途经顺序\n3. 查看行驶路线\n\n让我们一步步来:\n\n1. 首先获取这些地点的经纬度:"
      }
    }
  ],
  "usage": {
    "prompt_tokens": 11944,
    "completion_tokens": 141,
    "total_tokens": 12085
  },
  "streamed_data": [
    {
      "nonce": "a3",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": ""
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "9cf808bed3270cb4",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "我"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "c3",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "来"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "1a5a3a1e8349",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "帮您"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "949c",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "规划这"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "11c0",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "段"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "7049e8514f81",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "行"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "cf6f8026cc652491",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "程。这"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "6b479e3a",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "需"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "519a5460e5bba1a0",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "要分"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "05d1",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "几"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "3ee4",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "步:"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "f83b",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "\n1. 先"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "e6b55adf",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "获"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "3c284b",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "取各"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "5d39ab42",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "个"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "bdb5",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "地"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "260762bf77b7",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "点的具"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "2e",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "体位置和"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "c43992a3f65bb6d1",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "经"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "19afbefb65",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "纬度"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "0400bd6349573f1c",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "\n2. 规"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "75c3db90fa",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "划加"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "6e371898d0e502",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "油站的最"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "b95ae22b01",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "佳途"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "1978d5d7",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "经"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "c540e9faad8cf5",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "顺序"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "dd2671b8c9",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "\n3. 查"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "fb5fdb",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "看行"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "b73a29511e7c",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "驶路线"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "09fe",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "\n\n让"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "6e",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "我们一"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "2e3ef81cd56e71d6",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "步步"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "69791b866a94b420",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "来:"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "db",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "\n\n1. "
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "1d445b",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "首"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "0cf97e2eec",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "先获取这"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "3cc30c",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "些地点的"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "6319ca0a9d8ec971",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "经"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "f23555",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": "纬度:"
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "55460da8",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": ""
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "51",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "delta": {
            "role": "assistant",
            "content": null,
            "tool_calls": [
              {
                "id": "tooluse_NiqffqaITCmVtmoeIMkFNg",
                "index": 0,
                "type": "function",
                "function": {
                  "name": "geocoder",
                  "arguments": ""
                }
              }
            ]
          },
          "index": 0,
          "finish_reason": null,
          "native_finish_reason": null
        }
      ]
    },
    {
      "nonce": "1f",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "delta": {
            "role": "assistant",
            "content": null,
            "tool_calls": [
              {
                "index": 0,
                "type": "function",
                "function": {
                  "arguments": ""
                }
              }
            ]
          },
          "index": 0,
          "finish_reason": null,
          "native_finish_reason": null
        }
      ]
    },
    {
      "nonce": "d180bed3",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "delta": {
            "role": "assistant",
            "content": null,
            "tool_calls": [
              {
                "index": 0,
                "type": "function",
                "function": {
                  "arguments": "{\""
                }
              }
            ]
          },
          "index": 0,
          "finish_reason": null,
          "native_finish_reason": null
        }
      ]
    },
    {
      "nonce": "1def6ce090",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "delta": {
            "role": "assistant",
            "content": null,
            "tool_calls": [
              {
                "index": 0,
                "type": "function",
                "function": {
                  "arguments": "ad"
                }
              }
            ]
          },
          "index": 0,
          "finish_reason": null,
          "native_finish_reason": null
        }
      ]
    },
    {
      "nonce": "75",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "delta": {
            "role": "assistant",
            "content": null,
            "tool_calls": [
              {
                "index": 0,
                "type": "function",
                "function": {
                  "arguments": "dress\""
                }
              }
            ]
          },
          "index": 0,
          "finish_reason": null,
          "native_finish_reason": null
        }
      ]
    },
    {
      "nonce": "39b54669",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "delta": {
            "role": "assistant",
            "content": null,
            "tool_calls": [
              {
                "index": 0,
                "type": "function",
                "function": {
                  "arguments": ": \"深圳会展中心\"}"
                }
              }
            ]
          },
          "index": 0,
          "finish_reason": null,
          "native_finish_reason": null
        }
      ]
    },
    {
      "nonce": "4509",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": ""
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "edb0917e",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": ""
          },
          "finish_reason": "tool_calls",
          "native_finish_reason": "tool_calls",
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "f8bb8536b4dc32",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": ""
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ]
    },
    {
      "nonce": "7450c6b8a93ceb",
      "id": "gen-1744110839-tKMReVlveRBEHdEelZCW",
      "provider": "Amazon Bedrock",
      "model": "anthropic/claude-3.5-sonnet",
      "object": "chat.completion.chunk",
      "created": 1744110839,
      "choices": [
        {
          "index": 0,
          "delta": {
            "role": "assistant",
            "content": ""
          },
          "finish_reason": null,
          "native_finish_reason": null,
          "logprobs": null
        }
      ],
      "usage": {
        "prompt_tokens": 11944,
        "completion_tokens": 141,
        "total_tokens": 12085
      }
    }
  ]
}
原创作者: xiaobaiysf 转载于: https://www.cnblogs.com/xiaobaiysf/p/18816233
### MCP芯片的工作原理 微处理器控制单元(Microcontroller Processing Unit, 简称MCP)是一种集成了多种外设功能的单片机,其设计目标是为了实现特定应用中的高效处理能力。以下是关于MCP芯片工作原理的具体描述: #### 1. 架构概述 MCP通常基于精简指令集计算(RISC)架构,能够快速执行基本操作命令。例如,在飞思卡尔MC9S08系列中,MCP的核心CPU具备高效的运算能力和较低的功耗特性[^1]。 #### 2. 存储器结构 MCP内部集成了一定容量的闪存和RAM,用于存储程序代码以及运行期间的数据缓存。对于副门控制器使用的MC9S08SG08芯片而言,尽管其存储器空间较小,但仍能满足嵌入式系统的典型需求。 #### 3. 输入/输出接口 MCP通过丰富的I/O端口与其他硬件设备交互。这些端口支持多路复用模式,允许开发者灵活配置GPIO、串行通信协议等功能。具体来说,MC9S08SG08提供了多达20个引脚来满足不同的连接需求。 #### 4. 定时与计数功能 内置定时器模块使得MCP可以精确测量时间间隔或者生成周期性的触发信号。这种特性广泛应用于电机驱动、PWM波形产生等领域。在引用材料提到的例子中,该类定时器被成功部署于汽车门窗升降机构之中。 #### 5. 模拟数字转换 (ADC) 为了采集外部模拟量并将其转化为数字形式供后续算法分析,许多型号的MCP都配备了高性能的模数转换电路。比如文中提及的产品就拥有专门针对车窗位置检测优化过的AD采样通道。 #### 6. 通讯协议支持 现代MCP普遍兼容主流工业标准总线技术如UART,SPI,I²C,LIN等,从而简化了复杂网络环境下节点间的信息交换过程。特别是LIN通信模块的存在让MC9S08SG08非常适合充当辅助角色参与到整车电气管理系统当中去。 ```python # 示例代码展示如何初始化一个简单的MCP ADC读取流程 def initialize_adc(mcp_instance): mcp_instance.set_mode('adc') # 设置为ADC模式 mcp_instance.configure_channel(0) # 配置第一个输入通道 def read_analog_value(): value = mcp.read() # 执行一次转换获取数值 return value # 返回结果给调用方 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值