send_input
Send text input to a running interactive process by providing the session ID and text, with an option to append a newline character.
Instructions
Send text input to a running interactive process.
Args: session_id: The session ID returned by start_process. text: Text to send to the process stdin. press_enter: Whether to append a newline after the text.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| text | Yes | ||
| press_enter | No |
Implementation Reference
- MCP tool handler for 'send_input': retrieves session and delegates to Session.send_input()
@mcp.tool() def send_input( session_id: str, text: str, press_enter: bool = False, ) -> dict: """Send text input to a running interactive process. Args: session_id: The session ID returned by start_process. text: Text to send to the process stdin. press_enter: Whether to append a newline after the text. """ session = _mgr.get(session_id) if not session: return {"error": f"Session '{session_id}' not found"} try: session.send_input(text, press_enter=press_enter) return {"success": True} except RuntimeError as e: return {"error": str(e)} - Alternative handler for 'send_input' in the tools-based registration (used via create_tools())
def send_input(args: dict) -> dict: session = _get_session(args["session_id"]) session.send_input(args["text"], press_enter=args.get("press_enter", False)) return {"success": True} - Type-annotated parameters acting as schema/validation for send_input (session_id, text, press_enter)
def send_input( session_id: str, text: str, press_enter: bool = False, - Session.send_input(): core implementation that writes text to the process stdin (via pexpect for pty or subprocess.PIPE for pipe mode)
def send_input(self, text: str, press_enter: bool = False) -> None: if self.status != SessionStatus.RUNNING: raise RuntimeError(f"Process has {self.status.value}, cannot send input") if press_enter: text += os.linesep if self.mode == "pty": self._process.send(text) else: self._process.stdin.write(text.encode("utf-8")) self._process.stdin.flush() - src/interactive_process_mcp/tools.py:92-94 (registration)Registration of 'send_input' in the create_tools() tuple-list returned by tools.py
return [ ("start_process", start_process), ("send_input", send_input),