ssh_file_info
Retrieve critical file details such as size and permissions on local or remote systems using SSH. Supports multiple SSH connections for efficient file management.
Instructions
Get file information (size, permissions, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connectionId | Yes | SSH connection ID (use "local" for local files) | |
| filePath | Yes | File path to get info for |
Input Schema (JSON Schema)
{
"properties": {
"connectionId": {
"description": "SSH connection ID (use \"local\" for local files)",
"type": "string"
},
"filePath": {
"description": "File path to get info for",
"type": "string"
}
},
"required": [
"connectionId",
"filePath"
],
"type": "object"
}
Implementation Reference
- src/index.ts:835-891 (handler)The handler function that implements the core logic of the 'ssh_file_info' tool. It parses input using FileInfoSchema, handles local files with fs.stat and remote files by executing the 'stat' command over SSH, and returns formatted file information.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 and filePath.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 listTools response, defining name, description, and input schema matching 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 registration in the CallToolRequest handler switch statement, routing 'ssh_file_info' calls to the handleSSHFileInfo method.case 'ssh_file_info': return await this.handleSSHFileInfo(args);