updateRule
Modify rule content on the Whistle MCP Server to manage proxy settings, enabling precise control over network request rules and configurations.
Instructions
更新规则内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ruleName | Yes | 规则名称 | |
| ruleValue | Yes | 规则内容 |
Implementation Reference
- src/index.ts:55-67 (handler)MCP handler implementation for the 'updateRule' tool, including inline schema validation via Zod and delegation to WhistleClient.updateRuleserver.addTool({ name: "updateRule", description: "更新规则内容", parameters: z.object({ ruleName: z.string().describe("规则名称"), ruleValue: z.string().describe("规则内容"), }), execute: async (args) => { const { ruleName, ruleValue } = args; const result = await whistleClient.updateRule(ruleName, ruleValue); return formatResponse(result); }, });
- src/WhistleClient.ts:40-62 (helper)Supporting helper method in WhistleClient that implements the core logic for updating a Whistle rule by posting form data to the appropriate Whistle API endpoint (enable-default for default rule, select for others)async updateRule(ruleName: string, ruleValue: string): Promise<any> { const isDefaultRule = ruleName.toLowerCase() === "default"; const formData = new URLSearchParams(); formData.append("clientId", `${Date.now()}-0`); formData.append("name", ruleName); formData.append("value", ruleValue); formData.append("selected", "true"); formData.append("active", "true"); formData.append("key", `w-reactkey-${Math.floor(Math.random() * 1000)}`); // Generate a random key formData.append("hide", "false"); formData.append("changed", "true"); const endpoint = isDefaultRule ? `${this.baseUrl}/cgi-bin/rules/enable-default` : `${this.baseUrl}/cgi-bin/rules/select`; const response = await axios.post(endpoint, formData, { headers: { "Content-Type": "application/x-www-form-urlencoded", }, }); return response.data; }