fs_read
Read files from remote servers over SSH to access content for automation, analysis, or management tasks.
Instructions
Reads a file from the remote system
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | SSH session ID | |
| path | Yes | File path to read | |
| encoding | No | File encoding (default: utf8) |
Implementation Reference
- src/fs-tools.ts:10-35 (handler)The handler function 'readFile' that implements the 'fs_read' tool logic.
export async function readFile( sessionId: string, path: string, encoding: string = 'utf8' ): Promise<string> { logger.debug('Reading file', { sessionId, path, encoding }); const session = sessionManager.getSession(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found or expired`); } try { const data = await session.sftp.get(path); const result = Buffer.isBuffer(data) ? data.toString(encoding as any) : String(data); logger.debug('File read successfully', { sessionId, path, size: result.length }); return result; } catch (error) { logger.error('Failed to read file', { sessionId, path, error }); throw wrapError( error, ErrorCode.EFS, `Failed to read file ${path}. Check if the file exists and is readable.` ); } } - src/types.ts:245-249 (schema)Zod schema for input validation for the 'fs_read' tool.
export const FSReadSchema = z.object({ sessionId: z.string().min(1), path: z.string().min(1), encoding: z.string().optional().default('utf8') }); - src/mcp.ts:179-190 (registration)Registration of the 'fs_read' tool in the MCP server setup.
name: 'fs_read', description: 'Reads a file from the remote system', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'SSH session ID' }, path: { type: 'string', description: 'File path to read' }, encoding: { type: 'string', description: 'File encoding (default: utf8)' } }, required: ['sessionId', 'path'] } }, - src/mcp.ts:426-431 (handler)The case block in 'setupToolHandlers' that routes the 'fs_read' request to the 'readFile' handler.
case 'fs_read': { const params = FSReadSchema.parse(args); const result = await readFile(params.sessionId, params.path, params.encoding); logger.info('File read', { sessionId: params.sessionId, path: params.path }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }