addRuleToGroup
Add a specified rule to a designated group within the Whistle MCP Server to manage proxy configurations efficiently.
Instructions
将规则添加到分组
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| groupName | Yes | 分组名称 | |
| ruleName | Yes | 要添加的规则名称 |
Implementation Reference
- src/WhistleClient.ts:285-302 (handler)The core handler function that executes the logic for adding a rule to a group by making a POST request to Whistle's `/cgi-bin/rules/move-to` endpoint with form data specifying the source rule and target group (prefixed with \r).async moveRuleToGroup(ruleName: string, groupName: string): Promise<any> { const formData = new URLSearchParams(); formData.append("clientId", `${Date.now()}-1`); formData.append("from", ruleName); formData.append("to", `\r${groupName}`); // Adding carriage return to denote a group formData.append("group", "false"); // Not moving a group, but a rule const response = await axios.post( `${this.baseUrl}/cgi-bin/rules/move-to`, formData, { headers: { "Content-Type": "application/x-www-form-urlencoded", }, } ); return response.data; }
- src/index.ts:162-165 (schema)Zod input schema defining the required parameters for the tool: groupName (target group) and ruleName (rule to add).parameters: z.object({ groupName: z.string().describe("分组名称"), ruleName: z.string().describe("要添加的规则名称"), }),
- src/index.ts:159-173 (registration)Registers the 'addRuleToGroup' tool in the FastMCP server, including name, description, schema, and a thin execute wrapper that calls the WhistleClient handler and formats the response.server.addTool({ name: "addRuleToGroup", description: "将规则添加到分组", parameters: z.object({ groupName: z.string().describe("分组名称"), ruleName: z.string().describe("要添加的规则名称"), }), execute: async (args) => { const result = await whistleClient.moveRuleToGroup( args.ruleName, args.groupName ); return formatResponse(result); }, });
- src/index.ts:21-30 (helper)Helper function used by the tool's execute to format the response in a standard MCP-compatible structure.function formatResponse(data: any) { return { content: [ { type: "text" as const, text: JSON.stringify(data), }, ], }; }