read_output
Retrieve content from the terminal output buffer of a serial port session, with an option to clear the buffer after reading.
Instructions
读取终端输出缓冲区的内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | 会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1 | |
| clear | No | 读取后是否清空缓冲区 |
Implementation Reference
- src/uart_mcp/tools/terminal.py:75-89 (handler)The handler function for the MCP 'read_output' tool, which retrieves output from the terminal session buffer via the terminal manager.def read_output( session_id: str, clear: bool = True, ) -> dict[str, Any]: """读取终端输出缓冲区内容 Args: session_id: 会话ID(串口路径) clear: 是否清空缓冲区 Returns: 输出内容 """ manager = get_terminal_manager() return manager.read_output(session_id=session_id, clear=clear)
- Input schema definition for the 'read_output' tool.READ_OUTPUT_TOOL: dict[str, Any] = { "name": "read_output", "description": "读取终端输出缓冲区的内容", "inputSchema": { "type": "object", "properties": { "session_id": { "type": "string", "description": "会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1", }, "clear": { "type": "boolean", "description": "读取后是否清空缓冲区", "default": True, }, }, "required": ["session_id"], }, }
- src/uart_mcp/server.py:118-122 (registration)Registration of the 'read_output' tool in the MCP list_tools handler.types.Tool( name=READ_OUTPUT_TOOL["name"], description=READ_OUTPUT_TOOL["description"], inputSchema=READ_OUTPUT_TOOL["inputSchema"], ),
- src/uart_mcp/server.py:169-170 (registration)Dispatch to the 'read_output' handler in the MCP call_tool handler.elif name == "read_output": result = read_output(**arguments)
- TerminalManager.read_output method that gets data from session buffer, decodes to text, and formats the response dictionary.def read_output(self, session_id: str, clear: bool = True) -> dict[str, Any]: """读取终端输出 Args: session_id: 会话ID(串口路径) clear: 是否清空缓冲区 Returns: 输出内容 Raises: SessionNotFoundError: 会话不存在 """ session = self.get_session(session_id) data = session.read_output(clear) # 解码为字符串,替换不可解码的字符 text = data.decode("utf-8", errors="replace") return { "data": text, "bytes_read": len(data), }