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 device communication.

Instructions

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

Input Schema

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

Implementation Reference

  • MCP tool handler: calls terminal manager to send command to the specified session.
    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, )
  • Input schema and metadata for the send_command MCP tool.
    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 send_command tool in the MCP list_tools handler.
    types.Tool( name=SEND_COMMAND_TOOL["name"], description=SEND_COMMAND_TOOL["description"], inputSchema=SEND_COMMAND_TOOL["inputSchema"], ),
  • Dispatch to send_command handler in the MCP call_tool handler.
    elif name == "send_command": result = send_command(**arguments)
  • TerminalManager.send_command: core logic to get session and delegate to session.send_command.
    def send_command( 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