replayRequest
Replay captured network requests in Whistle MCP Server to test or debug API calls. Specify URL, method, headers, and body, then retrieve results using the getInterceptInfo interface for analysis.
Instructions
在whistle中重放捕获的请求(本接口请求后不会直接返回结果, 需要使用getInterceptInfo接口获取结果)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | 请求体,可以是字符串或对象 | |
| headers | No | 请求头,可以是对象或字符串 | |
| method | No | 请求方法,默认为GET | |
| url | Yes | 请求URL | |
| useH2 | No | 是否使用HTTP/2 |
Implementation Reference
- src/WhistleClient.ts:639-697 (handler)Core implementation of replayRequest: constructs form data from options and POSTs to Whistle's /cgi-bin/composer endpoint to replay the request.async replayRequest(options: { useH2?: boolean; // 是否使用HTTP/2 url: string; // 请求URL method?: string; // 请求方法,默认GET headers?: Record<string, string> | string; // 请求头,可以是对象或字符串 body?: string | Record<string, any>; // 请求体 }): Promise<any> { // 准备请求参数 const formData = new URLSearchParams(); // 是否使用HTTP/2 formData.append("useH2", options.useH2 ? "true" : ""); // 添加URL (必需) formData.append("url", options.url); // 添加请求方法 formData.append("method", options.method || "GET"); // 处理请求头 if (options.headers) { let headerStr = ""; if (typeof options.headers === "string") { headerStr = options.headers; } else { headerStr = Object.entries(options.headers) .map(([key, value]) => `${key}: ${value}`) .join("\r\n"); } formData.append("headers", headerStr); } // 处理请求体 if (options.body) { if (typeof options.body === "string") { formData.append("body", options.body); } else { // 对象类型的请求体转为JSON字符串 formData.append("body", JSON.stringify(options.body)); } } // 发送重放请求到composer接口 const response = await axios.post( `${this.baseUrl}/cgi-bin/composer`, formData, { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", Accept: "application/json, text/javascript, */*; q=0.01", "Cache-Control": "no-cache", Pragma: "no-cache", }, } ); return response.data; }
- src/index.ts:421-427 (schema)Zod schema defining the input parameters for the replayRequest MCP tool.parameters: z.object({ url: z.string().describe("请求URL"), method: z.string().optional().describe("请求方法,默认为GET"), headers: z.string().optional().describe("请求头,可以是对象或字符串"), body: z.string().optional().describe("请求体,可以是字符串或对象"), useH2: z.boolean().optional().describe("是否使用HTTP/2") }),
- src/index.ts:418-432 (registration)Registers the replayRequest tool with the FastMCP server, providing schema and thin wrapper execute handler that delegates to WhistleClient.server.addTool({ name: "replayRequest", description: "在whistle中重放捕获的请求(本接口请求后不会直接返回结果, 需要使用getInterceptInfo接口获取结果)", parameters: z.object({ url: z.string().describe("请求URL"), method: z.string().optional().describe("请求方法,默认为GET"), headers: z.string().optional().describe("请求头,可以是对象或字符串"), body: z.string().optional().describe("请求体,可以是字符串或对象"), useH2: z.boolean().optional().describe("是否使用HTTP/2") }), execute: async (args) => { const result = await whistleClient.replayRequest(args); return formatResponse(result); }, });