Skip to main content
Glama

clear_buffer

Clear the output buffer for a specified UART terminal session, removing stored data to start fresh with new serial communication.

Instructions

清空指定终端会话的输出缓冲区

Input Schema

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

Implementation Reference

  • The main tool handler function for 'clear_buffer'. Accepts session_id, delegates to TerminalManager.clear_buffer().
    def clear_buffer(session_id: str) -> dict[str, Any]:
        """清空会话输出缓冲区
    
        Args:
            session_id: 会话ID(串口路径)
    
        Returns:
            操作结果
        """
        manager = get_terminal_manager()
        return manager.clear_buffer(session_id)
  • TerminalSession.clear_buffer() - clears the session's internal deque buffer under a thread lock.
    def clear_buffer(self) -> None:
        """清空输出缓冲区"""
        with self._buffer_lock:
            self._buffer.clear()
            self._buffer_size = 0
  • TerminalManager.clear_buffer() - retrieves the session and calls session.clear_buffer(), returns success dict.
    def clear_buffer(self, session_id: str) -> dict[str, Any]:
        """清空终端缓冲区
    
        Args:
            session_id: 会话ID(串口路径)
    
        Returns:
            操作结果
    
        Raises:
            SessionNotFoundError: 会话不存在
        """
        session = self.get_session(session_id)
        session.clear_buffer()
        return {"success": True, "session_id": session_id}
  • Schema/tool definition for clear_buffer: name='clear_buffer', description, and inputSchema requiring session_id string.
    CLEAR_BUFFER_TOOL: dict[str, Any] = {
        "name": "clear_buffer",
        "description": "清空指定终端会话的输出缓冲区",
        "inputSchema": {
            "type": "object",
            "properties": {
                "session_id": {
                    "type": "string",
                    "description": "会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1",
                },
            },
            "required": ["session_id"],
        },
    }
  • Registration of clear_buffer in handle_list_tools() - exposes the tool via MCP list_tools endpoint.
        types.Tool(
            name=CLEAR_BUFFER_TOOL["name"],
            description=CLEAR_BUFFER_TOOL["description"],
            inputSchema=CLEAR_BUFFER_TOOL["inputSchema"],
        ),
    ]
  • Tool dispatch in handle_call_tool() - routes 'clear_buffer' calls to the clear_buffer function.
    elif name == "clear_buffer":
        result = clear_buffer(**arguments)
  • Import of CLEAR_BUFFER_TOOL and clear_buffer from tools.terminal in server.py.
    from .tools.terminal import (
        CLEAR_BUFFER_TOOL,
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses the action (clear buffer) but does not specify prerequisites (e.g., session must be open) or side effects (e.g., discarding unread data). Since no annotations exist, description should provide more context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single phrase, no unnecessary words. Information is front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one parameter and no output schema, the description fully covers purpose and parameter meaning. No additional context needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%; description adds meaning by mapping session_id to 'serial port path' with examples (/dev/ttyUSB0, COM1), exceeding the schema's basic description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states the verb '清空' (clear) and the resource '输出缓冲区' (output buffer) for a specific session, distinguishing it from siblings like read_data or send_command.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool or when to avoid it. Does not mention prerequisites or alternatives among sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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