Skip to main content
Glama

create_session

Establish an interactive terminal session on an open serial port to communicate with UART devices, with configurable line endings and local echo settings.

Instructions

在已打开串口上创建终端会话,支持配置换行符和本地回显

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
portYes串口路径,如 /dev/ttyUSB0 或 COM1
line_endingNo换行符类型:CR(回车)、LF(换行)、CRLF(回车换行)CRLF
local_echoNo是否本地回显发送的命令
buffer_sizeNo输出缓冲区大小(字节),默认 64KB

Implementation Reference

  • The handler function for the 'create_session' MCP tool. It invokes the TerminalManager to create a session and returns the session info as a dictionary.
    def create_session( port: str, line_ending: str = "CRLF", local_echo: bool = DEFAULT_LOCAL_ECHO, buffer_size: int = DEFAULT_BUFFER_SIZE, ) -> dict[str, Any]: """在已打开串口上创建终端会话 Args: port: 串口路径 line_ending: 换行符类型(CR/LF/CRLF) local_echo: 是否本地回显 buffer_size: 输出缓冲区大小 Returns: 会话信息 """ manager = get_terminal_manager() session_info = manager.create_session( port=port, line_ending=line_ending, local_echo=local_echo, buffer_size=buffer_size, ) return session_info.to_dict()
  • The JSON schema definition for the 'create_session' tool inputs, specifying parameters and validation rules.
    CREATE_SESSION_TOOL: dict[str, Any] = { "name": "create_session", "description": "在已打开串口上创建终端会话,支持配置换行符和本地回显", "inputSchema": { "type": "object", "properties": { "port": { "type": "string", "description": "串口路径,如 /dev/ttyUSB0 或 COM1", }, "line_ending": { "type": "string", "description": "换行符类型:CR(回车)、LF(换行)、CRLF(回车换行)", "enum": ["CR", "LF", "CRLF"], "default": "CRLF", }, "local_echo": { "type": "boolean", "description": "是否本地回显发送的命令", "default": False, }, "buffer_size": { "type": "integer", "description": "输出缓冲区大小(字节),默认 64KB", "default": DEFAULT_BUFFER_SIZE, }, }, "required": ["port"], }, }
  • Registration of the 'create_session' tool in the MCP server's list_tools handler.
    name=CREATE_SESSION_TOOL["name"], description=CREATE_SESSION_TOOL["description"], inputSchema=CREATE_SESSION_TOOL["inputSchema"],
  • Dispatch logic in the MCP server's call_tool handler that invokes the create_session function.
    elif name == "create_session": result = create_session(**arguments)
  • Core helper method in TerminalManager that performs the actual session creation, validation, and starts the background reader thread.
    def create_session( self, port: str, line_ending: str = DEFAULT_LINE_ENDING.name, local_echo: bool = DEFAULT_LOCAL_ECHO, buffer_size: int = DEFAULT_BUFFER_SIZE, ) -> SessionInfo: """创建终端会话 Args: port: 串口路径 line_ending: 换行符类型(CR/LF/CRLF) local_echo: 是否本地回显 buffer_size: 输出缓冲区大小 Returns: 会话信息 Raises: SessionExistsError: 会话已存在 PortNotOpenError: 串口未打开 InvalidLineEndingError: 无效的换行符配置 """ # 验证换行符配置 try: line_ending_enum = LineEnding[line_ending.upper()] except KeyError: raise InvalidLineEndingError(line_ending) # 检查串口是否已打开 manager = get_serial_manager() try: manager.get_status(port) except Exception: raise PortNotOpenError(port) with self._lock: # 检查会话是否已存在 if port in self._sessions: raise SessionExistsError(port) # 创建会话 session = TerminalSession( port=port, line_ending=line_ending_enum, local_echo=local_echo, buffer_size=buffer_size, ) session.start() self._sessions[port] = session logger.info("创建终端会话:%s", port) return session.get_info()

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