Skip to main content
Glama

write_document

Create or replace markdown documents in the MCP Documentation Service, automatically generating directories as needed for structured documentation management.

Instructions

Create a new markdown document or completely overwrite an existing document with new content. Use with caution as it will overwrite existing documents without warning. Can create parent directories if they don't exist.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
contentYes
createDirectoriesNo

Implementation Reference

  • The main handler function implementing the write_document tool logic. Validates the path, creates directories if needed, writes the file content, and returns success/error response.
     */
    async writeDocument(
      docPath: string,
      content: string,
      createDirectories = true
    ): Promise<ToolResponse> {
      try {
        const validPath = await this.validatePath(docPath);
    
        // Create parent directories if needed
        if (createDirectories) {
          const dirPath = path.dirname(validPath);
          await fs.mkdir(dirPath, { recursive: true });
        }
    
        await fs.writeFile(validPath, content, "utf-8");
    
        return {
          content: [{ type: "text", text: `Successfully wrote to ${docPath}` }],
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            { type: "text", text: `Error writing document: ${errorMessage}` },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining the input parameters for the write_document tool: path, content, and optional createDirectories flag.
    export const WriteDocumentSchema = ToolInputSchema.extend({
      path: z.string(),
      content: z.string(),
      createDirectories: z.boolean().default(true),
    });
  • src/index.ts:207-213 (registration)
    Tool registration in the ListToolsRequest handler, defining name, description, and input schema for write_document.
      name: "write_document",
      description:
        "Create a new markdown document or completely overwrite an existing document with new content. " +
        "Use with caution as it will overwrite existing documents without warning. " +
        "Can create parent directories if they don't exist.",
      inputSchema: zodToJsonSchema(WriteDocumentSchema) as any,
    },
  • src/index.ts:321-333 (registration)
    Dispatch case in the CallToolRequest handler that validates input using the schema and invokes the documentHandler.writeDocument method.
    case "write_document": {
      const parsed = WriteDocumentSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for write_document: ${parsed.error}`
        );
      }
      return await documentHandler.writeDocument(
        parsed.data.path,
        parsed.data.content,
        parsed.data.createDirectories
      );
    }
Behavior4/5

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

With no annotations provided, the description carries full burden and does well: it discloses destructive behavior ('overwrite without warning'), creation capability, and directory handling ('create parent directories'). It doesn't mention permissions, rate limits, or response format, but for a tool with no annotations, this is strong coverage.

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?

Three sentences, each earning its place: first states purpose, second warns about destructive behavior, third adds directory creation. It's front-loaded with core functionality and wastes no words.

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

Completeness3/5

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

For a destructive mutation tool with 3 parameters, 0% schema coverage, and no output schema, the description is adequate but incomplete. It covers key behaviors (overwrite, directory creation) but lacks details on parameters, error cases, or return values, which are needed for full 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?

Schema description coverage is 0%, so the description must compensate. It explains 'path' and 'content' implicitly through context (document creation/overwrite) and mentions 'createDirectories' functionality. However, it doesn't detail parameter formats (e.g., path syntax, content constraints), leaving gaps despite some added meaning.

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

Purpose5/5

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

The description clearly states the verb ('create' or 'overwrite') and resource ('markdown document'), specifying it can create new documents or completely overwrite existing ones. It distinguishes from siblings like 'edit_document' (partial edits) and 'create_documentation_section' (section-specific creation).

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

Usage Guidelines4/5

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

The description provides clear context with 'Use with caution as it will overwrite existing documents without warning,' indicating when to be careful. However, it doesn't explicitly name alternatives like 'edit_document' for partial updates or 'create_folder' for directory-only operations, which would make it a 5.

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/alekspetrov/mcp-docs-service'

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