Skip to main content
Glama

close_port

Closes an active serial port connection to free system resources and terminate data transmission. Specify the port path to disconnect.

Instructions

关闭指定串口连接

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portYes串口路径

Implementation Reference

  • The primary handler function for the MCP 'close_port' tool. It invokes the serial manager's close_port method to perform the actual closure.
    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's input parameters, used during MCP tool registration.
    CLOSE_PORT_TOOL: dict[str, Any] = { "name": "close_port", "description": "关闭指定串口连接", "inputSchema": { "type": "object", "properties": { "port": { "type": "string", "description": "串口路径", }, }, "required": ["port"], }, }
  • Registers the 'close_port' tool in the MCP server's list_tools() handler by creating a Tool object with its schema.
    types.Tool( name=CLOSE_PORT_TOOL["name"], description=CLOSE_PORT_TOOL["description"], inputSchema=CLOSE_PORT_TOOL["inputSchema"], ),
  • Dispatch logic in the MCP call_tool handler that routes 'close_port' calls to the specific close_port function.
    elif name == "close_port": result = close_port(**arguments)
  • Low-level helper method in SerialManager that performs the actual serial port closure, handles locking, error cases, and returns success status.
    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}

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