create_session
Establish an interactive terminal session on an open UART serial port to send commands and receive responses, with configurable line endings and local echo settings.
Instructions
在已打开串口上创建终端会话,支持配置换行符和本地回显
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| port | Yes | 串口路径,如 /dev/ttyUSB0 或 COM1 | |
| line_ending | No | 换行符类型:CR(回车)、LF(换行)、CRLF(回车换行) | CRLF |
| local_echo | No | 是否本地回显发送的命令 | |
| buffer_size | No | 输出缓冲区大小(字节),默认 64KB |
Implementation Reference
- src/uart_mcp/tools/terminal.py:12-37 (handler)The core handler function for the 'create_session' tool. It invokes the terminal manager to create a session on the specified serial port with given configuration and returns the session info as a dict.
def create_session( port: str, line_ending: str = "CRLF", local_echo: bool = DEFAULT_LOCAL_ECHO, buffer_size: int = DEFAULT_BUFFER_SIZE, ) -> dict[str, Any]: """在已打开串口上创建终端会话 Args: port: 串口路径 line_ending: 换行符类型(CR/LF/CRLF) local_echo: 是否本地回显 buffer_size: 输出缓冲区大小 Returns: 会话信息 """ manager = get_terminal_manager() session_info = manager.create_session( port=port, line_ending=line_ending, local_echo=local_echo, buffer_size=buffer_size, ) return session_info.to_dict() - Input schema definition for the 'create_session' tool, including parameters like port (required), line_ending, local_echo, and buffer_size.
CREATE_SESSION_TOOL: dict[str, Any] = { "name": "create_session", "description": "在已打开串口上创建终端会话,支持配置换行符和本地回显", "inputSchema": { "type": "object", "properties": { "port": { "type": "string", "description": "串口路径,如 /dev/ttyUSB0 或 COM1", }, "line_ending": { "type": "string", "description": "换行符类型:CR(回车)、LF(换行)、CRLF(回车换行)", "enum": ["CR", "LF", "CRLF"], "default": "CRLF", }, "local_echo": { "type": "boolean", "description": "是否本地回显发送的命令", "default": False, }, "buffer_size": { "type": "integer", "description": "输出缓冲区大小(字节),默认 64KB", "default": DEFAULT_BUFFER_SIZE, }, }, "required": ["port"], }, } - src/uart_mcp/server.py:104-107 (registration)Registration of the 'create_session' tool in the MCP server's list_tools() method, using the schema from terminal.py.
name=CREATE_SESSION_TOOL["name"], description=CREATE_SESSION_TOOL["description"], inputSchema=CREATE_SESSION_TOOL["inputSchema"], ), - src/uart_mcp/server.py:163-164 (registration)Dispatch logic in the MCP server's call_tool() handler that invokes the create_session function when the tool is called.
elif name == "create_session": result = create_session(**arguments)