ssh_file_info
Retrieve file metadata like size and permissions from remote SSH servers or local systems using connection IDs and file paths.
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 handler function that executes the ssh_file_info tool. It parses input using FileInfoSchema, handles local files with fs.stat, and remote files by executing 'stat' command via SSH.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 input schema for the ssh_file_info tool defining connectionId and filePath parameters.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:308-318 (registration)Registration of the ssh_file_info tool in the ListTools response, providing name, description, and input schema.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 to the ssh_file_info handler in the CallToolRequest switch statement.case 'ssh_file_info': return await this.handleSSHFileInfo(args);