\x06 进行通信:MCP : b'\x06' # MCP协议消息##START\x06[任务ID][序列号][JSON数据]##ENDmcp00001{
"type": "register",
"data": {
"services": {
"服务名称": {
"description": "服务描述",
"parameters": {
"type": "object",
"properties": {
"参数名": {
"type": "数据类型",
"description": "参数描述",
"enum": ["可选值列表"] // 可选
}
},
"required": ["必需参数列表"]
}
}
}
}
}{
"type": "register",
"data": {
"services": {
"get_current_time": {
"description": "获取当前时间信息,包括日期和时间",
"parameters": {
"type": "object",
"properties": {
"format": {
"type": "string",
"enum": ["simple", "detailed"],
"description": "时间格式,simple为简单格式,detailed为详细格式"
}
}
}
},
"create_file": {
"description": "在本地创建文件并写入内容",
"parameters": {
"type": "object",
"properties": {
"filename": {
"type": "string",
"description": "文件名"
},
"content": {
"type": "string",
"description": "文件内容"
}
},
"required": ["filename", "content"]
}
}
}
}
}{
"type": "call",
"data": {
"call_id": "唯一调用标识符",
"method": "服务名称",
"params": {
"参数名": "参数值"
}
}
}{
"type": "result",
"data": {
"call_id": "对应的调用标识符",
"result": {
"success": true/false,
"data": "返回数据",
"error": "错误信息(仅失败时)"
}
}
}1. 用户发送请求到服务器
2. 服务器解析请求,判断需要调用客户端服务
3. 服务器发送MCP调用消息到客户端
4. 客户端接收调用消息,执行对应服务
5. 客户端返回执行结果
6. 服务器根据结果生成响应给用户string: 字符串类型number: 数字类型integer: 整数类型boolean: 布尔类型array: 数组类型object: 对象类型required: 必需参 数列表enum: 枚举值限制minimum/maximum: 数值范围限制minLength/maxLength: 字符串长度限制{
"success": true, // 执行是否成功
"data": "具体返回数据", // 成功时的数据
"error": "错误描述" // 失败时的错误信息
}{
"type": "result",
"data": {
"call_id": "调用标识符",
"result": {
"success": false,
"error": "详细错误信息"
}
}
}# 1. 客户端注册服务
C -> S: ##START\x06mcp00001[0000]{
"type": "register",
"data": {
"services": {
"get_current_time": {
"description": "获取当前时间",
"parameters": {
"type": "object",
"properties": {
"format": {
"type": "string",
"enum": ["simple", "detailed"]
}
}
}
}
}
}
}##END
# 2. 用户请求时间
C -> S: ##START\x04task12340000现在几点了?##END
C -> S: ##START\x03task12340001##END
# 3. 服务器调用客户端服务
S -> C: ##START\x06mcp00001[0000]{
"type": "call",
"data": {
"call_id": "call_001",
"method": "get_current_time",
"params": {
"format": "simple"
}
}
}##END
# 4. 客户端返回结果
C -> S: ##START\x06mcp00001[0000]{
"type": "result",
"data": {
"call_id": "call_001",
"result": {
"success": true,
"data": "2025-01-22 14:30:25"
}
}
}##END
# 5. 服务器响应用户
S -> C: ##START\x04task12340000现在是2025年1月22日14点30分25秒##END
S -> C: ##START\x03task12340001##END