MiMo Code 是一款面向开发者的 AI 编码代理。它能够理解你的代码库、规划改动、安全地编辑代码,并与你团队已有的工具协同工作。
安装mitmproxy
简介
mitmproxy 是一款开源的网络代理工具,可以用于拦截、查看、修改和重放 HTTP、HTTPS、HTTP2、WebSockets,以及 TCP 数据。它的核心特性包括交互式 UI、CLI 接口,和 Python API。mitmproxy 提供了多种有效的工具,包括 mitmproxy 命令行界面,mitmweb 网络界面,mitmdump 备份工具等。
安装mitmproxy
github:https://github.com/mitmproxy/mitmproxy
建议通过python安装,较为简单,也可以去github下载安装程序
pip install mitmproxy
安装信任证书
在初次使用mitmproxy后会在~/.mitmproxy 目录下生成证书,双击mitmproxy-ca-cert.pem即可完成证书的安装,安装位置选择:系统。但是此时证书为非信任状态,打开钥匙串访问程序-选择系统-双击mitmproxy-在信任选项中选择(使用此证书时:始终信任).
使用mitmproxy抓包mimocode
启动mitmproxy
mitproxy默认的启动端口是8080,也可以不使用-p指定端口
mitmproxy -p 8080
启动mimocode
http_proxy=http://127.0.0.1:8080 https_proxy=http://127.0.0.1:8080 mimo
保存抓包日志
在mimocode发送一次请求后在mitmproxy即可看到所有请求,用鼠标单击自己想看的那一条记录,按x即可保存日志,可选curl、raw等格式,选择完格式后需要输入文件名,比如1.txt,然后回车,即可保存当前请求的日志记录。
分析抓包日志
根据抓包日志,抓到两个请求
https://api.xiaomimimo.com/api/free-ai/bootstrap
{
"client":"你的客户端id"
}
https://api.xiaomimimo.com/api/free-ai/openai/chat
Authorization: Bearer 你的jwt
Content-Type: application/json
User-Agent: mimocode/0.1.1 ai-sdk/provider-utils/4.0.23 runtime/bun/1.3.14
X-Mimo-Source: mimocode-cli-free
x-session-affinity: ses_12bbf2bd9ffe6Pf261nTsaem4X
{
"model": "mimo-auto",
"messages": [
{
"role": "system",
"content": "You are MiMoCode, an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user."
},
{
"role": "user",
"content": "你好"
}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}
由于chat接口的请求报文比较大,包含了特别多的提示词和工具等,所以这里只粘贴一部分报文。
结合小米mimo项目开源代码分析,bootstrap接口是获取请求chat的jwt,而chat则是标准的openai兼容格式接口。
client生成逻辑为:hostname | platform | arch | cpu_model | username
具体生成示例脚本如下:
import hashlib
import os
import platform
import socket
cpu = "unknown-cpu"
try:
with open("/proc/cpuinfo") as f:
for line in f:
if line.startswith("model name"):
cpu = line.split(":")[1].strip()
break
except FileNotFoundError:
# macOS fallback
import subprocess
try:
cpu = subprocess.check_output(
["sysctl", "-n", "machdep.cpu.brand_string"],
text=True
).strip()
except Exception:
pass
try:
username = os.getlogin()
except Exception:
username = "unknown-user"
seed = "|".join([
socket.gethostname(),
platform.system().lower(),
platform.machine().lower(),
cpu,
username,
])
fingerprint = hashlib.sha256(seed.encode()).hexdigest()
print(fingerprint)
需要注意的是,如果报文中没有”role”: “system”的内容则请求chat接口会直接报403