close_session
Close a specific iTerm2 session by providing its session ID. Optionally force close without confirmation.
Instructions
Close a specific session.
:param session_id: The session UUID to close. :param force: If True, skip iTerm2's "running process" confirmation prompt.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| force | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/iterm2_mcp/server.py:347-356 (handler)The `close_session` tool handler. Decorated with @mcp.tool(), it accepts a session_id (str) and optional force (bool) parameter. Resolves the session via _session() helper, calls sess.async_close(force=force), and returns a confirmation string.
@mcp.tool() async def close_session(session_id: str, force: bool = False) -> str: """Close a specific session. :param session_id: The session UUID to close. :param force: If True, skip iTerm2's "running process" confirmation prompt. """ sess = await _session(session_id) await sess.async_close(force=force) return f"Closed session {session_id}" - src/iterm2_mcp/server.py:347-347 (registration)The `@mcp.tool()` decorator registers `close_session` as an MCP tool on the FastMCP server instance.
@mcp.tool() - src/iterm2_mcp/server.py:48-69 (helper)The `_session()` helper function resolves a session_id string to an iterm2.Session object, used by close_session to find the target session.
async def _session(session_id: str | None) -> iterm2.Session: """Resolve a session by ID, falling back to the currently active session. :param session_id: A specific session UUID to target, or ``None`` to use the currently focused window/tab/pane. """ app = await _app() if session_id: sess = app.get_session_by_id(session_id) if sess is None: raise ValueError(f"No session found with ID {session_id!r}") return sess win = app.current_terminal_window if win is None: raise RuntimeError("No active iTerm2 window.") tab = win.current_tab if tab is None: raise RuntimeError("No active tab in the current window.") sess = tab.current_session if sess is None: raise RuntimeError("No active session in the current tab.") return sess