create_tab
Open a new iTerm2 tab in a specified window. Optionally run a command or apply a profile.
Instructions
Create a new tab in a window.
:param window_id: Target window ID. Defaults to the current window. :param command: Optional shell command to run in the new tab's session. :param profile: Name of the iTerm2 profile to use.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| window_id | No | ||
| command | No | ||
| profile | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/iterm2_mcp/server.py:296-321 (handler)The create_tab tool handler: decorated with @mcp.tool(), accepts optional window_id, command, and profile parameters. Looks up the target window (or uses the current terminal window), then calls win.async_create_tab() to create the tab, and returns the new tab ID and session ID.
@mcp.tool() async def create_tab( window_id: str | None = None, command: str | None = None, profile: str | None = None, ) -> str: """Create a new tab in a window. :param window_id: Target window ID. Defaults to the current window. :param command: Optional shell command to run in the new tab's session. :param profile: Name of the iTerm2 profile to use. """ app = await _app() if window_id: win = next((w for w in app.terminal_windows if w.window_id == window_id), None) if win is None: return f"Error: no window with ID {window_id!r}" else: win = app.current_terminal_window if win is None: return "Error: no active iTerm2 window." tab = await win.async_create_tab(profile=profile, command=command) if tab is None: return "Error: failed to create tab." sess = tab.current_session return f"Created tab {tab.tab_id}, session {sess.session_id if sess else '?'}" - src/iterm2_mcp/server.py:296-296 (registration)The tool is registered via the @mcp.tool() decorator on the FastMCP instance named 'mcp' (instantiated on line 21).
@mcp.tool() - src/iterm2_mcp/server.py:298-301 (schema)Input schema/parameters for create_tab: window_id (optional str), command (optional str), profile (optional str). Returns a string.
window_id: str | None = None, command: str | None = None, profile: str | None = None, ) -> str: