Skip to main content
Glama

close_port

Close an active serial port connection to free system resources and prevent unauthorized access to UART devices.

Instructions

关闭指定串口连接

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portYes串口路径

Implementation Reference

  • The main handler function for the 'close_port' tool. It retrieves the serial manager and calls its close_port method, returning the result as a dict.
    def close_port(port: str) -> dict[str, Any]:
        """关闭串口
    
        Args:
            port: 串口路径
    
        Returns:
            操作结果
        """
        manager = get_serial_manager()
        return manager.close_port(port)
  • The JSON schema definition for the 'close_port' tool input, defining the required 'port' parameter.
    CLOSE_PORT_TOOL: dict[str, Any] = {
        "name": "close_port",
        "description": "关闭指定串口连接",
        "inputSchema": {
            "type": "object",
            "properties": {
                "port": {
                    "type": "string",
                    "description": "串口路径",
                },
            },
            "required": ["port"],
        },
    }
  • Registration of the 'close_port' tool in the MCP server's list_tools handler.
    types.Tool(
        name=CLOSE_PORT_TOOL["name"],
        description=CLOSE_PORT_TOOL["description"],
        inputSchema=CLOSE_PORT_TOOL["inputSchema"],
    ),
  • Dispatch logic in the MCP server's call_tool handler that invokes the close_port function.
    elif name == "close_port":
        result = close_port(**arguments)
  • Core implementation in SerialManager that performs the actual port closing logic, removing the port from the managed ports and closing the serial 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}
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the action ('关闭/close') but doesn't disclose behavioral traits: whether this is destructive (likely yes, as it closes a connection), what happens on success/failure, if it requires specific permissions, or if there are side effects (e.g., freeing resources). The description is minimal and lacks critical context for a mutation tool.

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, efficient sentence with zero waste. It's front-loaded and directly states the tool's purpose without unnecessary words. Every part of the sentence earns its place by specifying the action and target.

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

Completeness2/5

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

Given the tool's complexity (a mutation operation to close a connection) and lack of annotations or output schema, the description is incomplete. It doesn't cover behavioral aspects like effects, error handling, or return values. For a tool that likely alters system state, more context is needed to ensure safe and correct usage.

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

Parameters3/5

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

Schema description coverage is 100%, with the single parameter 'port' documented as '串口路径' (serial port path). The description doesn't add meaning beyond this, as it only references '指定串口' (specified serial port) without explaining format, examples, or constraints. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose4/5

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

The description '关闭指定串口连接' clearly states the action (关闭/close) and target resource (串口连接/serial port connection). It distinguishes from siblings like 'close_session' (which closes sessions) and 'clear_buffer' (which clears buffers), though it doesn't explicitly differentiate them. The purpose is specific and unambiguous.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requires an open port), exclusions (e.g., don't use if port is already closed), or relationships to siblings like 'open_port' (for opening) or 'close_session' (for session management). Usage context is implied but not stated.

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