disableRule
Disable specific proxy rules in Whistle MCP Server by providing the rule name, allowing precise control over network request management.
Instructions
禁用规则
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ruleName | Yes | 规则名称 |
Implementation Reference
- src/WhistleClient.ts:168-209 (handler)The main handler function that implements disabling a rule. It retrieves the rule details, constructs form data, and sends a POST request to Whistle's API endpoint (/cgi-bin/rules/unselect or /disable-default) to unselect/disable the specified rule.async unselectRule(ruleName: string): Promise<any> { const rules = await this.getRules(); if (!rules) { throw new Error("No rules found"); } const isDefaultRule = ruleName.toLowerCase() === "default"; let ruleContent; if (isDefaultRule) { ruleContent = rules.defaultRules; } else { const rule = rules.list.find((rule: any) => rule.name === ruleName); if (!rule) { throw new Error(`Rule with name '${ruleName}' not found`); } ruleContent = rule.data; } const formData = new URLSearchParams(); formData.append("clientId", `${Date.now()}-0`); formData.append("name", ruleName); formData.append("value", ruleContent); formData.append("selected", "true"); formData.append("active", "true"); formData.append("key", `w-reactkey-${Math.floor(Math.random() * 1000)}`); formData.append("hide", "false"); formData.append("changed", "true"); const endpoint = isDefaultRule ? `${this.baseUrl}/cgi-bin/rules/disable-default` : `${this.baseUrl}/cgi-bin/rules/unselect`; const response = await axios.post(endpoint, formData, { headers: { "Content-Type": "application/x-www-form-urlencoded", }, }); return response.data; }
- src/index.ts:106-116 (registration)Registers the disableRule tool with the FastMCP server, specifying its name, description, input schema, and execute function that delegates to WhistleClient.unselectRule and formats the response.server.addTool({ name: "disableRule", description: "禁用规则", parameters: z.object({ ruleName: z.string().describe("规则名称"), }), execute: async (args) => { const result = await whistleClient.unselectRule(args.ruleName); return formatResponse(result); }, });
- src/index.ts:109-111 (schema)Zod schema for the disableRule tool input, requiring a 'ruleName' string parameter.parameters: z.object({ ruleName: z.string().describe("规则名称"), }),
- src/index.ts:21-30 (helper)Helper function used by disableRule (and other tools) to format responses in the expected MCP content structure.function formatResponse(data: any) { return { content: [ { type: "text" as const, text: JSON.stringify(data), }, ], }; }