Skip to main content
Glama

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
NameRequiredDescriptionDefault
connectionIdYesSSH connection ID (use "local" for local files)
filePathYesFile path to get info for

Implementation Reference

  • 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)}` ); } }
  • 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);

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/widjis/mcp-ssh'

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