Skip to main content
Glama

enableRule

Activate specific rules in the Whistle proxy server using the Model Context Protocol (MCP) to manage network requests, monitor traffic, and enhance proxy control.

Instructions

启用规则

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ruleNameYes规则名称

Implementation Reference

  • src/index.ts:94-104 (registration)
    Registration of the 'enableRule' tool in FastMCP server, including name, description, Zod input schema (ruleName: string), and execute handler that delegates to WhistleClient.selectRule and formats the response.
    server.addTool({ name: "enableRule", description: "启用规则", parameters: z.object({ ruleName: z.string().describe("规则名称"), }), execute: async (args) => { const result = await whistleClient.selectRule(args.ruleName); return formatResponse(result); }, });
  • Main handler logic for enabling a rule: fetches rules, gets rule content, prepares form data to select/activate the rule via Whistle's CGI API endpoint (/rules/select or /rules/enable-default for default rule), handling special case for 'default' rule.
    async selectRule(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/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; }
  • Helper function used by all tools to format responses as MCP content blocks with JSON-stringified data.
    function formatResponse(data: any) { return { content: [ { type: "text" as const, text: JSON.stringify(data), }, ], }; }
  • Zod schema for enableRule tool input: requires 'ruleName' as string.
    parameters: z.object({ ruleName: z.string().describe("规则名称"), }),
  • Helper method called by selectRule to fetch current rules list from Whistle API.
    async getRules(): Promise<any> { const response = await axios.get(`${this.baseUrl}/cgi-bin/rules/list`); return response.data; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/7gugu/whistle-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server