close_connection
Terminate an active SSH session and remove it from the global state to ensure secure and efficient resource management on the SSH MCP Server.
Instructions
Terminate an SSH session and remove it from global state.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection_id | Yes |
Implementation Reference
- src/index.ts:443-460 (handler)Handler for close_connection tool: validates connection_id, ends the SSH client session, removes the connection from the global connections Map, and returns a JSON response indicating success.// close_connection if (name === "close_connection") { const { connection_id } = args as { connection_id: string }; const conn = connections.get(connection_id); if (!conn) throw new Error(`connection_id '${connection_id}' not found.`); conn.client.end(); connections.delete(connection_id); return { content: [ { type: "text", text: JSON.stringify({ closed: true }, null, 2), }, ], }; }
- src/index.ts:196-205 (schema)Schema definition for the close_connection tool, including name, description, and input schema requiring a connection_id string.{ name: "close_connection", description: "Terminate an SSH session and remove it from global state.", inputSchema: { type: "object", required: ["connection_id"], properties: { connection_id: { type: "string" } }, additionalProperties: false, }, },
- src/index.ts:140-207 (registration)Registration of all tools including close_connection in the ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: "get_available_connections", description: "List every SSH-capable machine this server knows about (but is NOT yet connected).", inputSchema: { type: "object", properties: {}, additionalProperties: false }, }, { name: "create_connection", description: "Open an SSH session to the given machine and track it in global state so subsequent tool calls can reuse it.", inputSchema: { type: "object", required: ["machine_id", "title"], properties: { machine_id: { type: "string", description: "ID from get_available_connections" }, title: { type: "string", description: "Purpose of this session (displayed in UIs)" }, }, additionalProperties: false, }, }, { name: "get_connections", description: "Return every STILL-OPEN SSH session in global state.", inputSchema: { type: "object", properties: {}, additionalProperties: false }, }, { name: "execute_command", description: "Run a shell command in an existing SSH session and return stdout/stderr/exitCode.", inputSchema: { type: "object", required: ["connection_id", "command"], properties: { connection_id: { type: "string" }, command: { type: "string", description: "Shell command to execute" }, }, additionalProperties: false, }, }, { name: "secure_execute_command", description: "Run a **read‑only** shell command (i.e., one that does not mutate state) in an existing SSH session and return stdout/stderr/exitCode.", inputSchema: { type: "object", required: ["connection_id", "command"], properties: { connection_id: { type: "string" }, command: { type: "string", description: "Read‑only shell command to execute (e.g., ls, cat)." }, }, additionalProperties: false, }, }, { name: "close_connection", description: "Terminate an SSH session and remove it from global state.", inputSchema: { type: "object", required: ["connection_id"], properties: { connection_id: { type: "string" } }, additionalProperties: false, }, }, ], }));