Skip to main content
Glama

fs_write

Write data to files on remote servers via SSH to automate file management tasks.

Instructions

Writes data to a file on the remote system

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID
pathYesFile path to write
dataYesData to write to file
modeNoFile permissions mode

Implementation Reference

  • The handler function that performs the file write operation, using an atomic write approach (temp file then rename).
    export async function writeFile(
      sessionId: string,
      path: string,
      data: string,
      mode?: number
    ): Promise<boolean> {
      logger.debug('Writing file', { sessionId, path, size: data.length, mode });
      
      const session = sessionManager.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
      
      try {
        // Use atomic write: write to temp file, then rename
        const tempPath = `${path}.tmp.${Date.now()}`;
        
        try {
          // Write to temporary file
          await session.sftp.put(Buffer.from(data, 'utf8'), tempPath);
          
          // Set permissions if specified
          if (mode !== undefined) {
            await session.sftp.chmod(tempPath, mode);
          }
          
          // Atomic rename
          await session.sftp.rename(tempPath, path);
          
          logger.debug('File written successfully', { sessionId, path });
          return true;
        } catch (writeError) {
          // Clean up temp file on failure
          try {
            await session.sftp.delete(tempPath);
            logger.debug('Cleaned up temp file after error', { tempPath });
          } catch (cleanupError) {
            logger.warn('Failed to clean up temp file', { tempPath, cleanupError });
          }
          throw writeError;
        }
      } catch (error) {
        logger.error('Failed to write file', { sessionId, path, error });
        throw wrapError(
          error,
          ErrorCode.EFS,
          `Failed to write file ${path}. Check directory permissions and disk space.`
        );
      }
    }
  • The Zod schema used to validate inputs for the 'fs_write' tool.
    export const FSWriteSchema = z.object({
      sessionId: z.string().min(1),
      path: z.string().min(1),
      data: z.string(),
      mode: z.number().optional()
    });
  • src/mcp.ts:433-438 (registration)
    The tool handler case that processes 'fs_write' requests and calls the implementation.
    case 'fs_write': {
      const params = FSWriteSchema.parse(args);
      const result = await writeFile(params.sessionId, params.path, params.data, params.mode);
      logger.info('File written', { sessionId: params.sessionId, path: params.path });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'writes data' implies a mutation, it doesn't specify critical behaviors like whether it overwrites or appends, error handling for non-existent paths, permission requirements, or potential destructive effects. This leaves significant gaps for a file-writing operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized and front-loaded, directly stating the core functionality without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a file-writing tool with no annotations and no output schema, the description is insufficient. It doesn't explain what happens on success/failure, return values, or important behavioral aspects like overwrite behavior. Given the complexity of file operations and lack of structured context, more completeness is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters thoroughly. The description doesn't add any meaningful parameter semantics beyond what's in the schema, maintaining the baseline score for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('writes data') and target ('to a file on the remote system'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this from sibling tools like 'ensure_lines_in_file' which also modifies files, missing full differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose 'fs_write' over 'ensure_lines_in_file' or 'patch_apply', nor does it discuss prerequisites like needing an active SSH session or appropriate permissions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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