close_port
Close a specified UART serial port connection by providing the port path, ending communication with the device.
Instructions
关闭指定串口连接
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| port | Yes | 串口路径 |
Implementation Reference
- src/uart_mcp/tools/port_ops.py:67-77 (handler)The close_port tool handler function that delegates to SerialManager.close_port().
def close_port(port: str) -> dict[str, Any]: """关闭串口 Args: port: 串口路径 Returns: 操作结果 """ manager = get_serial_manager() return manager.close_port(port) - src/uart_mcp/serial_manager.py:433-456 (handler)The core SerialManager.close_port() method that actually closes the serial port connection.
def close_port(self, port: str) -> dict[str, Any]: """关闭串口 Args: port: 串口路径 Returns: 操作结果 Raises: PortClosedError: 串口未打开 """ with self._lock: if port not in self._ports: raise PortClosedError(port) managed = self._ports.pop(port) try: managed.serial.close() except Exception as e: logger.warning("关闭串口时发生异常:%s - %s", port, e) logger.info("串口关闭成功:%s", port) return {"success": True, "port": port} - The schema/input validation definition for the close_port tool (name, description, inputSchema with required port parameter).
CLOSE_PORT_TOOL: dict[str, Any] = { "name": "close_port", "description": "关闭指定串口连接", "inputSchema": { "type": "object", "properties": { "port": { "type": "string", "description": "串口路径", }, }, "required": ["port"], }, } - src/uart_mcp/server.py:152-153 (registration)Registration of close_port in the MCP server's call_tool handler, dispatching to the close_port function.
elif name == "close_port": result = close_port(**arguments) - src/uart_mcp/server.py:77-81 (registration)Registration of close_port in the MCP server's list_tools handler via CLOSE_PORT_TOOL schema.
types.Tool( name=CLOSE_PORT_TOOL["name"], description=CLOSE_PORT_TOOL["description"], inputSchema=CLOSE_PORT_TOOL["inputSchema"], ),