Skip to main content
Glama

update_draft

Modify unpublished draft posts on Substack by updating title, subtitle, body content, and audience settings using markdown formatting.

Instructions

Update an existing draft post. Only works on unpublished drafts. Accepts markdown body.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
draft_idYesThe draft ID to update
titleNoNew title
subtitleNoNew subtitle
bodyNoNew body in markdown format
audienceNoWho can see this post

Implementation Reference

  • The handler function that executes the update_draft tool logic. It accepts draft_id and optional fields (title, subtitle, body, audience), builds an updates object (converting markdown body to ProseMirror format), calls client.updateDraft(), and returns the updated draft information.
    async ({ draft_id, title, subtitle, body, audience }) => {
      const updates: Record<string, unknown> = {};
      if (title !== undefined) updates.draft_title = title;
      if (subtitle !== undefined) updates.draft_subtitle = subtitle;
      if (body !== undefined) updates.draft_body = markdownToProseMirror(body);
      if (audience !== undefined) updates.audience = audience;
    
      const draft = await client.updateDraft(draft_id, updates);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                id: draft.id,
                title: draft.draft_title,
                message: "Draft updated successfully.",
              },
              null,
              2,
            ),
          },
        ],
      };
    },
  • src/server.ts:207-245 (registration)
    Registration of the update_draft tool with the MCP server. Includes the tool name, description, and Zod schema defining input parameters (draft_id, title, subtitle, body, audience) with their types and descriptions.
    server.tool(
      "update_draft",
      "Update an existing draft post. Only works on unpublished drafts. Accepts markdown body.",
      {
        draft_id: z.number().describe("The draft ID to update"),
        title: z.string().optional().describe("New title"),
        subtitle: z.string().optional().describe("New subtitle"),
        body: z.string().optional().describe("New body in markdown format"),
        audience: z
          .enum(["everyone", "only_paid", "founding", "only_free"])
          .optional()
          .describe("Who can see this post"),
      },
      async ({ draft_id, title, subtitle, body, audience }) => {
        const updates: Record<string, unknown> = {};
        if (title !== undefined) updates.draft_title = title;
        if (subtitle !== undefined) updates.draft_subtitle = subtitle;
        if (body !== undefined) updates.draft_body = markdownToProseMirror(body);
        if (audience !== undefined) updates.audience = audience;
    
        const draft = await client.updateDraft(draft_id, updates);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  id: draft.id,
                  title: draft.draft_title,
                  message: "Draft updated successfully.",
                },
                null,
                2,
              ),
            },
          ],
        };
      },
    );
  • The updateDraft method in SubstackClient that makes the actual PUT request to the Substack API endpoint /api/v1/drafts/{id} with the update payload.
    async updateDraft(
      id: number,
      updates: DraftUpdatePayload,
    ): Promise<SubstackDraft> {
      return this.request<SubstackDraft>(
        `${this.publicationUrl}/api/v1/drafts/${id}`,
        {
          method: "PUT",
          body: JSON.stringify(updates),
        },
      );
    }
  • TypeScript interface defining the DraftUpdatePayload structure with optional fields: draft_title, draft_subtitle, draft_body, audience, section_id, and cover_image.
    export interface DraftUpdatePayload {
      draft_title?: string;
      draft_subtitle?: string;
      draft_body?: string;
      audience?: "everyone" | "only_paid" | "founding" | "only_free";
      section_id?: number | null;
      cover_image?: string | null;
    }
  • The markdownToProseMirror helper function that converts markdown text to ProseMirror JSON format. Used by the handler to convert the body parameter before sending to the API.
    export function markdownToProseMirror(markdown: string): string {
      const lines = markdown.split("\n");
      const nodes: PMNode[] = [];
      let i = 0;
    
      while (i < lines.length) {
        const line = lines[i];
    
        // Blank line — skip
        if (line.trim() === "") {
          i++;
          continue;
        }
    
        // Fenced code block
        if (line.trimStart().startsWith("```")) {
          const lang = line.trim().slice(3).trim();
          const codeLines: string[] = [];
          i++;
          while (i < lines.length && !lines[i].trimStart().startsWith("```")) {
            codeLines.push(lines[i]);
            i++;
          }
          i++; // skip closing ```
          nodes.push({
            type: "code_block",
            ...(lang ? { attrs: { lang } } : {}),
            content: [{ type: "text", text: codeLines.join("\n") }],
          });
          continue;
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. It mentions the constraint 'Only works on unpublished drafts', which adds useful behavioral context beyond the schema. However, it lacks details on permissions, error handling, or what happens to unspecified fields (e.g., if only body is updated, do title/subtitle remain unchanged?), leaving gaps for a mutation tool.

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 very concise with two sentences that are front-loaded and waste no words. It efficiently conveys the core purpose and key constraint without unnecessary elaboration.

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 mutation tool with no annotations and no output schema, the description is moderately complete. It covers the basic action and a key constraint, but lacks details on behavioral aspects like side effects, response format, or error conditions, which are important given the tool's complexity.

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 parameters thoroughly. The description adds minimal value by mentioning 'Accepts markdown body', which aligns with the schema's description for 'body', but doesn't provide additional semantics beyond what's in the structured fields.

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 ('Update'), resource ('existing draft post'), and constraint ('Only works on unpublished drafts'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'create_draft' or 'get_draft', though the focus on 'existing' drafts provides some implicit distinction.

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 provides some usage context by stating 'Only works on unpublished drafts', which implies when to use it (for drafts) and when not (for published posts). However, it doesn't mention alternatives like 'create_draft' for new drafts or 'get_draft' for viewing, nor does it cover prerequisites like needing the draft ID.

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/conorbronsdon/substack-mcp'

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