Skip to main content
Glama

write_note

Write content to a markdown note at a specified path, with optional YAML frontmatter and choice of overwrite, append, or prepend mode. Automatically creates missing parent directories.

Instructions

Writes content to a note. Pass { path, content } and optionally frontmatter (object) and mode (overwrite|append|prepend, default overwrite). Returns { root, path, message }. Creates parent directories automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for the write_note tool. Constructs the tool object with name, description, input schema, and async handler that validates args, calls fileService.writeNote(), and returns a success/error response.
    function makeWriteNoteTool(container: ServiceContainer): ToolHandler {
      return {
        name: "write_note",
        description:
          "Writes content to a note. Pass `{ path, content }` and optionally `frontmatter` (object) and `mode` (`overwrite`|`append`|`prepend`, default `overwrite`). Returns `{ root, path, message }`. Creates parent directories automatically.",
        inputSchema: WriteNoteSchema,
        async handler(args): Promise<ToolResponse> {
          const services = requireServices(container);
          const { path, content, frontmatter, mode } = WriteNoteSchema.parse(args);
          log.info({ path, mode }, "write_note called");
          try {
            await services.file.writeNote(path, content, frontmatter, mode);
            log.info({ path, mode }, "write_note complete");
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({
                    root: getRoot(container),
                    path,
                    message: `Note ${mode === "overwrite" ? "written" : mode + "ed"} successfully.`,
                  }),
                },
              ],
            };
          } catch (err) {
            log.error({ err, path }, "write_note failed");
            return {
              content: [{ type: "text", text: JSON.stringify({
                root: getRoot(container),
                error: err instanceof Error ? err.message : String(err),
                possibleSolutions: ["Check the path is root-relative", "Ensure the path is not blocked (.obsidian, .git)", "Use read_note to confirm an existing note's path"],
              }) }],
              isError: true,
            };
          }
        },
      };
    }
  • Zod schemas for write_note input validation: WriteNoteSchema defines path (string), content (string), frontmatter (optional record), and mode (enum: overwrite/append/prepend, default 'overwrite').
    const WriteModeSchema = z.enum(["overwrite", "append", "prepend"]);
    
    const WriteNoteSchema = z.object({
      path: z.string().min(1, "path is required"),
      content: z.string(),
      frontmatter: z.record(z.string(), z.unknown()).optional(),
      mode: WriteModeSchema.optional().default("overwrite"),
    });
  • Registration function registerNoteTools that adds makeWriteNoteTool result to the global tool registry map.
    export function registerNoteTools(
      registry: Map<string, ToolHandler>,
      container: ServiceContainer,
    ): void {
      const tools = [
        makeReadNoteTool(container),
        makeWriteNoteTool(container),
        makePatchNoteTool(container),
        makeDeleteNoteTool(container),
        makeMoveNoteTool(container),
        makeReadMultipleNotesTool(container),
      ];
    
      for (const tool of tools) {
        registry.set(tool.name, tool);
      }
  • FileService.writeNote implementation. Handles atomic overwrite, append (concatenates new content after existing), and prepend (concatenates new content before existing), with frontmatter support via gray-matter.
    async writeNote(
      relativePath: string,
      content: string,
      frontmatter?: Record<string, unknown>,
      mode: WriteMode = "overwrite",
    ): Promise<void> {
      log.info({ path: relativePath, mode }, "writeNote");
    
      const newRaw = frontmatter
        ? matter.stringify(content, frontmatter as matter.GrayMatterFile<string>["data"])
        : content;
    
      if (mode === "overwrite") {
        const fullPath = this.resolvePath(relativePath);
        await this.atomicWrite(fullPath, newRaw);
        return;
      }
    
      // For append/prepend, read existing content first (file may not exist yet)
      let existingRaw = "";
      try {
        const fullPath = this.resolvePath(relativePath);
        existingRaw = await fs.readFile(fullPath, "utf-8");
      } catch (err) {
        if ((err as NodeJS.ErrnoException).code !== "ENOENT") {
          throw err;
        }
      }
    
      const combined =
        mode === "append"
          ? existingRaw
            ? existingRaw + "\n" + newRaw
            : newRaw
          : existingRaw
            ? newRaw + "\n" + existingRaw
            : newRaw;
    
      const fullPath = this.resolvePath(relativePath);
      await this.atomicWrite(fullPath, combined);
    }
  • TypeScript interface declaration for writeNote method on the FileService interface.
    /** Create or overwrite/append/prepend to a note */
    writeNote(
      path: string,
      content: string,
      frontmatter?: Record<string, unknown>,
      mode?: WriteMode,
    ): Promise<void>;
Behavior3/5

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

No annotations are provided, so the description must carry the full burden. It discloses modes, frontmatter handling, and automatic directory creation, but does not specify whether the note file is created if missing or the destructive nature of overwrite.

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 concise and front-loaded, with a clear first sentence stating purpose. Each sentence adds necessary detail without redundancy.

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?

Given no annotations or output schema, the description covers return structure and directory creation. However, it omits whether the note file is created if missing, error scenarios, or permissions needed.

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

Parameters4/5

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

Schema coverage is 100%, so the schema already defines types. The description adds value by specifying mode enum values, default, frontmatter as object, return shape, and implying required parameters beyond schema's required count.

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 'Writes content to a note' and lists parameters, making the purpose evident. However, it does not distinguish when to use this tool over siblings like create_note or patch_note.

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

Usage Guidelines3/5

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

The description explains parameters and default behavior but gives no explicit guidance on when to use or when not to use this tool compared to alternatives like create_note.

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/Erodenn/markscribe'

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