Skip to main content
Glama

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
NameRequiredDescriptionDefault
session_idYes会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1
clearNo读取后是否清空缓冲区

Implementation Reference

  • 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"], }, }
  • 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"], ),
  • 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), }

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