ssh_close_interactive_shell
Close an interactive SSH shell session to terminate remote terminal connections and free server resources. Specify the session ID to end the connection.
Instructions
Close an interactive shell session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Interactive session ID to close |
Implementation Reference
- src/index.ts:1055-1085 (handler)The main handler function that validates input using CloseInteractiveShellSchema, retrieves the shell session, closes the shell channel, marks it inactive, removes it from the shellSessions map, and returns a success message or throws an error if the session is not found or closing fails.private async handleCloseInteractiveShell(args: unknown) { const params = CloseInteractiveShellSchema.parse(args); const session = shellSessions.get(params.sessionId); if (!session) { throw new McpError( ErrorCode.InvalidParams, `Session ID '${params.sessionId}' not found` ); } try { session.shell.close(); session.isActive = false; shellSessions.delete(params.sessionId); return { content: [ { type: 'text', text: `Interactive shell session '${params.sessionId}' closed successfully`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to close session: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:119-121 (schema)Zod schema defining the input parameters for the tool, requiring a sessionId string.const CloseInteractiveShellSchema = z.object({ sessionId: z.string().describe('Interactive session ID to close') });
- src/index.ts:360-370 (registration)Tool registration in the ListTools response, defining name, description, and inputSchema matching the handler.{ name: 'ssh_close_interactive_shell', description: 'Close an interactive shell session', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Interactive session ID to close' } }, required: ['sessionId'] }, },
- src/index.ts:503-504 (registration)Dispatch case in the CallToolRequest handler that routes to the specific handler function.case 'ssh_close_interactive_shell': return await this.handleCloseInteractiveShell(args);