Skip to main content
Glama

ssh_disconnect

Close active SSH connections in the SSH MCP server by specifying the connection ID to terminate remote sessions.

Instructions

Close an SSH connection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionIdYesID of an active SSH connection

Implementation Reference

  • The main handler function that executes the ssh_disconnect tool. It validates the connectionId, closes the SSH connection with conn.end(), removes it from the connections map, and returns a success or error message.
    private async handleSSHDisconnect(params: any) { const { connectionId } = params; // Check if the connection exists if (!this.connections.has(connectionId)) { return { content: [{ type: "text", text: `No active SSH connection with ID: ${connectionId}` }], isError: true }; } const { conn, config } = this.connections.get(connectionId)!; try { // Close the connection conn.end(); this.connections.delete(connectionId); return { content: [{ type: "text", text: `Disconnected from ${config.username}@${config.host}:${config.port}` }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to disconnect: ${error.message}` }], isError: true }; } }
  • The input schema definition for the ssh_disconnect tool, declared in the server's capabilities during initialization.
    ssh_disconnect: { description: "Close an SSH connection", inputSchema: { type: "object", properties: { connectionId: { type: "string", description: "ID of an active SSH connection" } }, required: ["connectionId"] } }
  • src/index.ts:286-287 (registration)
    Registration of the ssh_disconnect tool handler in the switch statement within the CallToolRequestSchema handler.
    case 'ssh_disconnect': return this.handleSSHDisconnect(request.params.arguments);
  • The tool schema returned by the ListToolsRequestSchema handler, including name, description, and inputSchema.
    { name: 'ssh_disconnect', description: 'Close an SSH connection', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' } }, required: ['connectionId'] }
  • src/index.ts:184-267 (registration)
    The ListToolsRequestSchema handler registration which includes ssh_disconnect in the list of available tools.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'ssh_connect', description: 'Connect to a remote server via SSH', inputSchema: { type: 'object', properties: { host: { type: 'string', description: 'Hostname or IP address of the remote server' }, port: { type: 'number', description: 'SSH port (default: 22)' }, username: { type: 'string', description: 'SSH username' }, password: { type: 'string', description: 'SSH password (if not using key-based authentication)' }, privateKeyPath: { type: 'string', description: 'Path to private key file (if using key-based authentication)' }, passphrase: { type: 'string', description: 'Passphrase for private key (if needed)' }, connectionId: { type: 'string', description: 'Unique identifier for this connection' } }, required: ['host', 'username'] } }, { name: 'ssh_exec', description: 'Execute a command on the remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, command: { type: 'string', description: 'Command to execute' }, cwd: { type: 'string', description: 'Working directory for the command' }, timeout: { type: 'number', description: 'Command timeout in milliseconds' } }, required: ['connectionId', 'command'] } }, { name: 'ssh_upload_file', description: 'Upload a file to the remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, localPath: { type: 'string', description: 'Path to the local file' }, remotePath: { type: 'string', description: 'Path where the file should be saved on the remote server' } }, required: ['connectionId', 'localPath', 'remotePath'] } }, { name: 'ssh_download_file', description: 'Download a file from the remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, remotePath: { type: 'string', description: 'Path to the file on the remote server' }, localPath: { type: 'string', description: 'Path where the file should be saved locally' } }, required: ['connectionId', 'remotePath', 'localPath'] } }, { name: 'ssh_list_files', description: 'List files in a directory on the remote server', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' }, remotePath: { type: 'string', description: 'Path to the directory on the remote server' } }, required: ['connectionId', 'remotePath'] } }, { name: 'ssh_disconnect', description: 'Close an SSH connection', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'ID of an active SSH connection' } }, required: ['connectionId'] } } ] }));

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mixelpixx/SSH-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server