Skip to main content
Glama

close_session

Terminate an active serial port session to release system resources and prevent unauthorized access to connected devices.

Instructions

关闭指定的终端会话

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1

Implementation Reference

  • The top-level handler function for the 'close_session' tool. It retrieves the terminal manager and calls its close_session method.
    def close_session(session_id: str) -> dict[str, Any]: """关闭指定终端会话 Args: session_id: 会话ID(串口路径) Returns: 操作结果 """ manager = get_terminal_manager() return manager.close_session(session_id)
  • Core implementation in TerminalManager that safely closes a session: removes it from the sessions dict, stops the read thread, and returns success.
    def close_session(self, session_id: str) -> dict[str, Any]: """关闭终端会话 Args: session_id: 会话ID(串口路径) Returns: 操作结果 Raises: SessionNotFoundError: 会话不存在 """ with self._lock: if session_id not in self._sessions: raise SessionNotFoundError(session_id) session = self._sessions.pop(session_id) session.stop() logger.info("关闭终端会话:%s", session_id) return {"success": True, "session_id": session_id}
  • Tool schema definition including name, description, and input schema requiring 'session_id'.
    CLOSE_SESSION_TOOL: dict[str, Any] = { "name": "close_session", "description": "关闭指定的终端会话", "inputSchema": { "type": "object", "properties": { "session_id": { "type": "string", "description": "会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1", }, }, "required": ["session_id"], }, }
  • Registration of the close_session tool in the MCP server's list_tools handler.
    types.Tool( name=CLOSE_SESSION_TOOL["name"], description=CLOSE_SESSION_TOOL["description"], inputSchema=CLOSE_SESSION_TOOL["inputSchema"], ),
  • Dispatch to the close_session handler in the MCP server's call_tool handler.
    elif name == "close_session": result = close_session(**arguments)

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