ssh_file_info
Retrieve file metadata like size and permissions from SSH-connected systems to verify file properties and manage remote file systems.
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 via SSH execCommand('stat'). Returns formatted file information including size, type, timestamps, and permissions.
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 ssh_file_info: connectionId and filePath. 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)Registration of the ssh_file_info tool in the ListTools response, including name, description, and JSON 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 case in the CallToolRequestSchema handler switch statement that routes to the ssh_file_info handler function.
case 'ssh_file_info': return await this.handleSSHFileInfo(args);