throttling
Simulate network conditions by applying preset bandwidth limits like 3G, 4G, or 5G to test application performance under different connection speeds.
Instructions
Set a network throttling preset in Charles.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| preset | Yes | 弱网预设名称。仅允许固定值:3G/4G/5G/fibre/100mbps/56k/256k/deactivate/off/on/start。 |
Implementation Reference
- charles_mcp/tools/reset.py:27-56 (handler)The `throttling` tool implementation that handles the input, validates the preset, and calls the Charles client.
async def throttling(ctx: ToolContext, preset: ThrottlingPreset) -> str: """Set a network throttling preset in Charles.""" logger.info("Tool called: throttling(preset=%s)", preset) deps = get_tool_dependencies(ctx) preset_clean = preset.strip() if not preset_clean: return ( "Error: parameter `preset` cannot be empty. " "Use one of the supported presets, for example: 3G / 4G / 5G / off / deactivate." ) preset_lower = preset_clean.lower() supported = {value.lower() for value in THROTTLING_PRESET_CHOICES} if preset_lower not in supported: return ( "Error: parameter `preset` is invalid. " f"Supported values: {', '.join(THROTTLING_PRESET_CHOICES)}. " 'Retry with something like throttling("3G") or throttling("off").' ) normalized_preset = "3G" if preset_lower in ("start", "on") else preset_clean try: async with deps.client_factory(deps.config) as client: success, message = await client.set_throttling(normalized_preset) return f"{'Success' if success else 'Error'}: {message}" except CharlesClientError as exc: logger.error("Throttling error: %s", exc) return f"Error: {exc}" - charles_mcp/tools/reset.py:26-27 (registration)The MCP tool decorator registration for `throttling`.
@mcp.tool() async def throttling(ctx: ToolContext, preset: ThrottlingPreset) -> str: - The `ThrottlingPreset` type definition used for input validation in the throttling tool.
ThrottlingPreset = Annotated[ str, Field( description=( "弱网预设名称。" "仅允许固定值:3G/4G/5G/fibre/100mbps/56k/256k/deactivate/off/on/start。" ), json_schema_extra={"enum": list(THROTTLING_PRESET_CHOICES)}, ), ]