Skip to main content
Glama

file_write

Write content to files for storing notes, documents, or operational data within the AI Ops Hub environment.

Instructions

Записать содержимое в файл

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesПуть к файлу
contentYesСодержимое для записи

Implementation Reference

  • Core handler function for the file_write tool. Sanitizes the path, creates directories as needed, writes content using fs.writeFile, with logging and error handling.
    async writeFile(filePath: string, content: string): Promise<void> {
      try {
        // Проверяем безопасность пути
        const safePath = this.sanitizePath(filePath);
        
        console.log(`✏️ Запись в файл: ${safePath}`);
        
        // Создаем директорию если её нет
        const dir = path.dirname(safePath);
        await fs.mkdir(dir, { recursive: true });
        
        await fs.writeFile(safePath, content, 'utf-8');
        
        console.log(`✅ Файл записан: ${safePath} (${content.length} символов)`);
      } catch (error) {
        console.error('Ошибка записи файла:', error);
        throw new Error(`Ошибка записи файла: ${error}`);
      }
    }
  • src/server.ts:99-116 (registration)
    Tool registration in the main MCP server's ListToolsRequestSchema handler, defining name, description, and input schema.
    {
      name: 'file_write',
      description: 'Записать содержимое в файл',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Путь к файлу',
          },
          content: {
            type: 'string',
            description: 'Содержимое для записи',
          },
        },
        required: ['path', 'content'],
      },
    },
  • Dispatch case in main server's CallToolRequestSchema handler delegating to FileService.writeFile.
    case 'file_write':
      await this.fileService.writeFile(args.path as string, args.content as string);
      return { content: 'Файл записан' };
  • Dispatch case in HTTP transport's /call endpoint handler delegating to FileService.writeFile.
    case 'file_write':
      await this.fileService.writeFile(args.path, args.content);
      result = { message: 'Файл записан' };
  • Security helper to sanitize file paths, preventing path traversal attacks by restricting access to the notes directory.
    private sanitizePath(filePath: string): string {
      // Убираем потенциально опасные символы
      const cleanPath = filePath.replace(/[<>:"|?*]/g, '');
      
      // Разрешаем только относительные пути
      if (path.isAbsolute(cleanPath)) {
        throw new Error('Абсолютные пути не разрешены');
      }
      
      // Разрешаем только файлы в notes директории
      const resolvedPath = path.resolve(this.notesDir, cleanPath);
      const notesDirResolved = path.resolve(this.notesDir);
      
      if (!resolvedPath.startsWith(notesDirResolved)) {
        throw new Error('Доступ к файлу вне notes директории запрещен');
      }
      
      return resolvedPath;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('write content to a file') but does not disclose critical traits such as whether it overwrites existing files, requires specific permissions, handles errors, or has rate limits. This leaves significant gaps in understanding the tool's behavior for a mutation 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, concise sentence in Russian that directly states the tool's purpose without any unnecessary words. It is front-loaded and efficiently communicates the core function, making it easy to understand at a glance.

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?

Given the complexity of a file write operation (a mutation with potential side effects), no annotations, and no output schema, the description is incomplete. It lacks details on behavior, error handling, and return values, which are crucial for safe and effective use. The description does not compensate for these gaps, making it inadequate for the tool's context.

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?

The input schema has 100% description coverage, with clear descriptions for 'path' and 'content' parameters in Russian. The description does not add any additional meaning beyond what the schema provides, such as format examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate, as the schema adequately documents the parameters.

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 (write) and resource (file) in Russian, which translates to 'Write content to a file.' This is specific and unambiguous about the tool's function. However, it does not differentiate from sibling tools like 'file_read' or 'rag_add_document,' which might involve file operations, so it lacks explicit sibling 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 does not mention scenarios like overwriting existing files, creating new files, or when to choose 'file_write' over 'rag_add_document' for document storage. Without such context, users must infer usage from the tool name alone.

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/Galiusbro/MCP'

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