Skip to main content
Glama
Amana03

Universal MCP Server

by Amana03

write_file

Save text content to a file by specifying a filename and content, enabling file creation and updates within the Universal MCP Server environment.

Instructions

Write content to a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesThe file key/name
contentYesThe content to write

Implementation Reference

  • Input schema for the 'write_file' tool defining required 'key' and 'content' string parameters.
    {
      name: 'write_file',
      description: 'Write content to a file',
      inputSchema: {
        type: 'object',
        properties: {
          key: {
            type: 'string',
            description: 'The file key/name',
          },
          content: {
            type: 'string',
            description: 'The content to write',
          },
        },
        required: ['key', 'content'],
      },
    },
  • Handler for 'write_file' tool: extracts arguments, logs request, invokes storage.write(), and returns JSON success response.
    case 'write_file': {
      const { key, content } = args as { key: string; content: string };
      
      logger.info('Tool request received', { 
        operation: 'tool:write',
        toolName: 'write_file',
        key,
        requestId 
      });
    
      await storage.write(key, content, requestId);
    
      return {
        content: [{
          type: 'text',
          text: JSON.stringify({
            success: true,
            message: `File '${key}' written successfully`,
            key
          }, null, 2)
        }]
      };
    }
  • FileStorage.write() method: acquires lock, handles versioning and metadata, performs fs.writeFile to persist data as JSON.
    async write(key: string, content: string, requestId: string): Promise<void> {
      const releaseLock = await this.acquireLock(key);
      const filePath = this.getFilePath(key);
    
      try {
        logger.debug('Writing file', { operation: 'write', key, filePath, requestId });
    
        let currentVersion = 0;
        let createdAt = new Date().toISOString();
        
        try {
          const existing = await fs.readFile(filePath, 'utf-8');
          const existingItem: StorageItem = JSON.parse(existing);
          currentVersion = existingItem.metadata.version;
          createdAt = existingItem.metadata.createdAt;
        } catch {
          // ファイルが存在しない場合は新規作成
        }
    
        const item: StorageItem = {
          content,
          metadata: {
            createdAt,
            updatedAt: new Date().toISOString(),
            version: currentVersion + 1
          }
        };
    
        await fs.writeFile(filePath, JSON.stringify(item, null, 2), 'utf-8');
        
        logger.info('File written successfully', { 
          operation: 'write', 
          key, 
          version: item.metadata.version,
          requestId 
        });
      } catch (error) {
        logger.error('Failed to write file', error as Error, { operation: 'write', key, requestId });
        throw error;
      } finally {
        releaseLock();
      }
    }
  • Identical input schema for 'write_file' tool in the multi-mode server entry point.
    {
      name: 'write_file',
      description: 'Write content to a file',
      inputSchema: {
        type: 'object',
        properties: {
          key: {
            type: 'string',
            description: 'The file key/name',
          },
          content: {
            type: 'string',
            description: 'The content to write',
          },
        },
        required: ['key', 'content'],
      },
    },
  • Handler for 'write_file' tool in multi-mode server: identical to src/index.ts implementation.
    case 'write_file': {
      const { key, content } = args as { key: string; content: string };
      
      logger.info('Tool request received', { 
        operation: 'tool:write',
        toolName: 'write_file',
        key,
        requestId 
      });
    
      await storage.write(key, content, requestId);
    
      return {
        content: [{
          type: 'text',
          text: JSON.stringify({
            success: true,
            message: `File '${key}' written successfully`,
            key
          }, null, 2)
        }]
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action. It lacks critical behavioral details: whether this overwrites existing files, requires permissions, has side effects, or handles errors. For a mutation tool, this is a significant gap in transparency.

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 extremely concise with a single sentence ('Write content to a file') that directly states the core function without any fluff. It's front-loaded and wastes no words, making it efficient for quick understanding.

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 mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what happens on success/failure, return values, or behavioral nuances like overwriting. Given the complexity and lack of structured data, more context is needed for effective use.

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 parameters 'key' and 'content' are fully documented in the schema. The description adds no additional meaning beyond implying 'content' is written to 'key', which the schema already covers. Baseline 3 is appropriate as the schema does the heavy lifting.

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 'Write content to a file' clearly states the action (write) and resource (file), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'delete_file' or 'search_files' beyond the obvious verb difference, missing explicit scope or resource distinctions.

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 prerequisites (e.g., file existence), exclusions, or comparisons to siblings like 'delete_file' or 'search_files', leaving usage context entirely implicit.

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/Amana03/universal-mcp-server'

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