set_charging
Control robot vacuum charging actions on Ecovacs MCP Server. Use 'go-start' to return the robot to the charging station or 'stopGo' to halt the process. Specify the robot nickname for targeted control.
Instructions
Make robot return to charging station
Args: nickname: Robot nickname, used to find device act: Robot action, go-start begin returning to charging station, stopGo stop returning to charging station
Returns: Dict: Dictionary containing execution results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| act | No | Robot action, go-start begin returning to charging station, stopGo stop returning to charging station | go-start |
| nickname | Yes | Robot nickname, used to find device |
Implementation Reference
- ecovacs_mcp/robot_mcp_stdio.py:74-89 (handler)The main handler implementation for the 'set_charging' tool. This async function is decorated with @mcp.tool() for automatic registration and uses Pydantic Field for input schema validation. It invokes the API to command the robot to charge.@mcp.tool() async def set_charging( nickname: str = Field(description="Robot nickname, used to find device"), act: str = Field(description="Robot action, go-start begin returning to charging station, stopGo stop returning to charging station", default="go-start") ) -> dict: """ Make robot return to charging station Args: nickname: Robot nickname, used to find device act: Robot action, go-start begin returning to charging station, stopGo stop returning to charging station Returns: Dict: Dictionary containing execution results """ return await call_api(ENDPOINT_ROBOT_CTL, {"nickName": nickname, "cmd": "Charge", "act": act})
- ecovacs_mcp/robot_mcp_stdio.py:74-74 (registration)The @mcp.tool() decorator registers the set_charging function as an MCP tool.@mcp.tool()
- ecovacs_mcp/robot_mcp_stdio.py:75-78 (schema)Input schema defined using Pydantic Field in the function signature, specifying parameters for robot nickname and charging action.async def set_charging( nickname: str = Field(description="Robot nickname, used to find device"), act: str = Field(description="Robot action, go-start begin returning to charging station, stopGo stop returning to charging station", default="go-start") ) -> dict:
- ecovacs_mcp/robot_mcp_stdio.py:21-57 (helper)Shared helper function call_api used by set_charging to make HTTP requests to the Ecovacs API.async def call_api(endpoint: str, params: dict, method: str = 'post') -> dict: """ General API call function Args: endpoint: API endpoint params: Request parameters method: Request method, 'get' or 'post' Returns: Dict: API response result, format {"msg": "OK", "code": 0, "data": [...]} """ # Build complete URL url = f"{API_URL}/{endpoint}" # Ensure all parameters are strings params = {k: str(v) for k, v in params.items()} # Add API key if API_KEY: params.update({"ak": API_KEY}) try: async with httpx.AsyncClient() as client: headers = {"Content-Type": "application/json"} if method.lower() == 'get': response = await client.get(url, params=params, timeout=REQUEST_TIMEOUT) else: response = await client.post(url, json=params, headers=headers, timeout=REQUEST_TIMEOUT) response.raise_for_status() return response.json() except Exception as e: # Return unified error format when an error occurs return {"msg": f"Request failed: {str(e)}", "code": -1, "data": []}