ssh_file_info
Retrieve file details like size and permissions from remote servers via SSH connections, enabling quick file system inspection without direct server access.
Instructions
Get file information (size, permissions, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionId | Yes | SSH connection ID (use "local" for local files) | |
| filePath | Yes | File path to get info for |
Implementation Reference
- src/index.ts:835-891 (handler)The main handler function for the 'ssh_file_info' tool. It parses input using FileInfoSchema, handles local files with fs.stat() providing detailed stats (size, type, timestamps, permissions), and remote files by executing 'stat' command via SSH, returning formatted text output.private async handleSSHFileInfo(args: unknown) { const params = FileInfoSchema.parse(args); try { if (params.connectionId === 'local') { // Get local file info const stats = await fs.stat(params.filePath); const fileInfo = { path: params.filePath, size: stats.size, isDirectory: stats.isDirectory(), isFile: stats.isFile(), modified: stats.mtime.toISOString(), created: stats.birthtime.toISOString(), permissions: '0' + (stats.mode & parseInt('777', 8)).toString(8) }; return { content: [ { type: 'text', text: `File info for ${params.filePath}:\n${JSON.stringify(fileInfo, null, 2)}`, }, ], }; } else { // Get remote file info const ssh = connectionPool.get(params.connectionId); if (!ssh) { throw new McpError( ErrorCode.InvalidParams, `Connection ID '${params.connectionId}' not found` ); } const result = await ssh.execCommand(`stat "${params.filePath}"`); if (result.code !== 0) { throw new Error(`stat command failed: ${result.stderr}`); } return { content: [ { type: 'text', text: `File info for ${params.connectionId}:${params.filePath}:\n${result.stdout}`, }, ], }; } } catch (error) { throw new McpError( ErrorCode.InternalError, `Get file info failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:94-97 (schema)Zod schema defining the input parameters for the 'ssh_file_info' tool: connectionId (string) and filePath (string). Used for validation in the handler.const FileInfoSchema = z.object({ connectionId: z.string().describe('SSH connection ID (use "local" for local files)'), filePath: z.string().describe('File path to get info for') });
- src/index.ts:307-318 (registration)Tool registration in the ListToolsRequestSchema handler. Defines the tool name 'ssh_file_info', description, and inputSchema matching the FileInfoSchema.{ name: 'ssh_file_info', description: 'Get file information (size, permissions, etc.)', inputSchema: { type: 'object', properties: { connectionId: { type: 'string', description: 'SSH connection ID (use "local" for local files)' }, filePath: { type: 'string', description: 'File path to get info for' } }, required: ['connectionId', 'filePath'] }, },
- src/index.ts:495-496 (registration)Dispatch case in the main CallToolRequestSchema handler that routes 'ssh_file_info' calls to the handleSSHFileInfo method.case 'ssh_file_info': return await this.handleSSHFileInfo(args);