Skip to main content
Glama

list_ports

Lists all available serial port devices with their device paths, descriptions, and hardware IDs to enable selection and management of serial connections.

Instructions

列出所有可用串口设备,返回设备路径、描述信息和硬件ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the list_ports tool. Calls the serial manager's list_ports() and converts PortInfo objects to dictionaries.
    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]
  • Tool definition/schema for list_ports, including name, description, and empty inputSchema (no parameters required).
    LIST_PORTS_TOOL: dict[str, Any] = {
        "name": "list_ports",
        "description": "列出所有可用串口设备,返回设备路径、描述信息和硬件ID",
        "inputSchema": {
            "type": "object",
            "properties": {},
            "required": [],
        },
    }
  • Registration in handle_list_tools() - the tool is listed as an available tool via types.Tool using LIST_PORTS_TOOL constants.
    @server.list_tools()  # type: ignore[no-untyped-call, untyped-decorator]
    async def handle_list_tools() -> list[types.Tool]:
        """返回可用工具列表"""
        return [
            types.Tool(
                name=LIST_PORTS_TOOL["name"],
                description=LIST_PORTS_TOOL["description"],
                inputSchema=LIST_PORTS_TOOL["inputSchema"],
            ),
  • Registration in handle_call_tool() dispatcher - when name=='list_ports', calls the list_ports() handler function and returns JSON result.
    if name == "list_ports":
        result = list_ports()
  • The SerialManager.list_ports() helper method that queries pyserial for comports(), 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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states the action and return values, but does not mention whether it is read-only, any permissions required, or potential side effects. For a list operation, minimal disclosure is acceptable, but the lack of any behavioral context limits transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that immediately conveys the purpose and output. No unnecessary words or information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple list tool with no parameters and no output schema, the description sufficiently covers what the tool does and returns (device path, description, hardware ID). It lacks performance or error details, but is complete enough for an agent to use correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has no parameters and 100% coverage. The description adds meaning by indicating that all available ports are listed (no filtering), which clarifies the parameterless behavior beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('列出所有可用串口设备' - list all available serial port devices) and the resource (serial port devices), and specifies the returned information (device path, description, hardware ID). It distinguishes from sibling tools like open_port or clear_buffer, which operate on specific ports or sessions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description does not provide any guidance on when to use this tool versus alternatives, such as before opening a port or when needing port details. It lacks explicit context for usage or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/donnel666/uart-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server