Skip to main content
Glama

send_command

Send commands to serial port devices through the UART MCP Server, with optional automatic line ending addition for proper command execution.

Instructions

向终端发送命令,可选择是否自动添加换行符

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1
commandYes要发送的命令内容
add_line_endingNo是否自动添加换行符

Implementation Reference

  • The primary handler function for the 'send_command' MCP tool. It receives tool arguments and delegates to the TerminalManager to send the command.
    def send_command(
        session_id: str,
        command: str,
        add_line_ending: bool = True,
    ) -> dict[str, Any]:
        """向终端发送命令
    
        Args:
            session_id: 会话ID(串口路径)
            command: 要发送的命令
            add_line_ending: 是否自动添加换行符
    
        Returns:
            发送结果
        """
        manager = get_terminal_manager()
        return manager.send_command(
            session_id=session_id,
            command=command,
            add_line_ending=add_line_ending,
        )
  • JSON Schema defining the input parameters for the send_command tool, used for validation in MCP.
    SEND_COMMAND_TOOL: dict[str, Any] = {
        "name": "send_command",
        "description": "向终端发送命令,可选择是否自动添加换行符",
        "inputSchema": {
            "type": "object",
            "properties": {
                "session_id": {
                    "type": "string",
                    "description": "会话ID(即串口路径),如 /dev/ttyUSB0 或 COM1",
                },
                "command": {
                    "type": "string",
                    "description": "要发送的命令内容",
                },
                "add_line_ending": {
                    "type": "boolean",
                    "description": "是否自动添加换行符",
                    "default": True,
                },
            },
            "required": ["session_id", "command"],
        },
    }
  • Registration of the send_command tool in the MCP server's list_tools handler.
    types.Tool(
        name=SEND_COMMAND_TOOL["name"],
        description=SEND_COMMAND_TOOL["description"],
        inputSchema=SEND_COMMAND_TOOL["inputSchema"],
    ),
  • Dispatch/call handler for send_command tool in the MCP server's call_tool method.
    elif name == "send_command":
        result = send_command(**arguments)
  • Core implementation in TerminalManager.send_command, which retrieves the session and calls the session's send_command method.
        self, session_id: str, command: str, add_line_ending: bool = True
    ) -> dict[str, Any]:
        """向终端发送命令
    
        Args:
            session_id: 会话ID(串口路径)
            command: 要发送的命令
            add_line_ending: 是否自动添加换行符
    
        Returns:
            发送结果
    
        Raises:
            SessionNotFoundError: 会话不存在
            SessionClosedError: 会话已关闭
            SendCommandFailedError: 发送失败
        """
        session = self.get_session(session_id)
    
        if not session.is_active:
            raise SessionClosedError(session_id)
    
        bytes_written = session.send_command(command, add_line_ending)
        return {"success": True, "bytes_written": bytes_written}

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