list_ports
Discover available serial port devices by retrieving their paths, descriptions, and hardware IDs for UART communication setup.
Instructions
列出所有可用串口设备,返回设备路径、描述信息和硬件ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/uart_mcp/tools/list_ports.py:11-21 (handler)The main handler function that executes the list_ports tool logic by calling the serial manager to list available ports.def list_ports() -> list[dict[str, str]]: """列出所有可用串口设备 返回系统中所有可用的串口设备列表,已过滤黑名单中的串口。 Returns: 串口信息列表,每个元素包含 port、description、hwid 字段 """ manager = get_serial_manager() ports = manager.list_ports() return [p.to_dict() for p in ports]
- The schema definition for the list_ports tool, including name, description, and empty input schema.LIST_PORTS_TOOL: dict[str, Any] = { "name": "list_ports", "description": "列出所有可用串口设备,返回设备路径、描述信息和硬件ID", "inputSchema": { "type": "object", "properties": {}, "required": [], }, }
- src/uart_mcp/server.py:67-71 (registration)Registration of the list_ports tool in the handle_list_tools() handler, which provides the tool specification to MCP clients.types.Tool( name=LIST_PORTS_TOOL["name"], description=LIST_PORTS_TOOL["description"], inputSchema=LIST_PORTS_TOOL["inputSchema"], ),
- src/uart_mcp/server.py:148-149 (registration)Dispatch/registration logic in handle_call_tool() that invokes the list_ports handler when called.if name == "list_ports": result = list_ports()
- Core helper method in SerialManager that enumerates system serial ports using pyserial, filters blacklisted ports, and returns PortInfo objects.def list_ports(self) -> list[PortInfo]: """列出所有可用串口 返回系统中所有可用的串口,已过滤黑名单中的串口。 Returns: 串口信息列表 """ blacklist = get_blacklist_manager() ports: list[PortInfo] = [] for port_info in serial.tools.list_ports.comports(): if blacklist.is_blacklisted(port_info.device): logger.debug("串口在黑名单中,已过滤:%s", port_info.device) continue ports.append( PortInfo( port=port_info.device, description=port_info.description or "", hwid=port_info.hwid or "", ) ) return ports