Skip to main content
Glama

Get Draft

discourse_get_draft

Retrieve saved draft content from Discourse forums using specific keys like 'new_topic' for new topics or 'topic_' for replies. Access incomplete posts to continue editing or review.

Instructions

Retrieve a specific draft by its key. Common keys: "new_topic" for new topic drafts, "topic_" for reply drafts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
draft_keyYesDraft key (e.g., "new_topic", "topic_123", "new_private_message")
sequenceNoExpected sequence number (optional)

Implementation Reference

  • Handler function for discourse_get_draft tool: parses input, fetches draft from /drafts/{key}.json, parses JSON data, formats output with preview and full JSON.
    async (input: unknown, _extra: unknown) => {
      const { draft_key, sequence } = schema.parse(input);
    
      try {
        const { client } = ctx.siteState.ensureSelectedSite();
        const params = new URLSearchParams();
        if (typeof sequence === "number") params.set("sequence", String(sequence));
    
        const url = `/drafts/${encodeURIComponent(draft_key)}.json${params.toString() ? `?${params}` : ""}`;
        const data = (await client.get(url)) as {
          draft?: string;
          draft_sequence?: number;
        };
    
        if (!data?.draft) {
          return { content: [{ type: "text", text: `No draft found for key "${draft_key}".` }] };
        }
    
        let parsedDraft: Record<string, unknown> = {};
        try {
          parsedDraft = JSON.parse(data.draft);
        } catch {
          parsedDraft = { raw: data.draft };
        }
    
        const lines = [`# Draft: \`${draft_key}\`\n`];
        lines.push(`**Sequence:** ${data.draft_sequence ?? "unknown"}`);
    
        if (parsedDraft.title) lines.push(`**Title:** ${parsedDraft.title}`);
        if (parsedDraft.categoryId) lines.push(`**Category ID:** ${parsedDraft.categoryId}`);
        if (parsedDraft.tags && Array.isArray(parsedDraft.tags)) {
          lines.push(`**Tags:** ${(parsedDraft.tags as string[]).join(", ")}`);
        }
        if (parsedDraft.action) lines.push(`**Action:** ${parsedDraft.action}`);
    
        if (parsedDraft.reply) {
          lines.push(`\n**Content:**\n${parsedDraft.reply}`);
        }
    
        lines.push("\n```json");
        lines.push(
          JSON.stringify(
            {
              draft_key,
              draft_sequence: data.draft_sequence,
              data: parsedDraft,
            },
            null,
            2
          )
        );
        lines.push("```");
    
        return { content: [{ type: "text", text: lines.join("\n") }] };
      } catch (e: unknown) {
        const msg = e instanceof Error ? e.message : String(e);
        return { content: [{ type: "text", text: `Failed to get draft: ${msg}` }], isError: true };
      }
    }
  • Zod input schema for discourse_get_draft: requires draft_key string, optional sequence number.
    const schema = z.object({
      draft_key: z
        .string()
        .min(1)
        .max(40)
        .describe('Draft key (e.g., "new_topic", "topic_123", "new_private_message")'),
      sequence: z.number().int().min(0).optional().describe("Expected sequence number (optional)"),
    });
  • Registration function registerGetDraft that calls server.registerTool for 'discourse_get_draft', defining title, description, schema, and handler.
    export const registerGetDraft: RegisterFn = (server, ctx, _opts) => {
      const schema = z.object({
        draft_key: z
          .string()
          .min(1)
          .max(40)
          .describe('Draft key (e.g., "new_topic", "topic_123", "new_private_message")'),
        sequence: z.number().int().min(0).optional().describe("Expected sequence number (optional)"),
      });
    
      server.registerTool(
        "discourse_get_draft",
        {
          title: "Get Draft",
          description:
            'Retrieve a specific draft by its key. Common keys: "new_topic" for new topic drafts, "topic_<id>" for reply drafts.',
          inputSchema: schema.shape,
        },
        async (input: unknown, _extra: unknown) => {
          const { draft_key, sequence } = schema.parse(input);
    
          try {
            const { client } = ctx.siteState.ensureSelectedSite();
            const params = new URLSearchParams();
            if (typeof sequence === "number") params.set("sequence", String(sequence));
    
            const url = `/drafts/${encodeURIComponent(draft_key)}.json${params.toString() ? `?${params}` : ""}`;
            const data = (await client.get(url)) as {
              draft?: string;
              draft_sequence?: number;
            };
    
            if (!data?.draft) {
              return { content: [{ type: "text", text: `No draft found for key "${draft_key}".` }] };
            }
    
            let parsedDraft: Record<string, unknown> = {};
            try {
              parsedDraft = JSON.parse(data.draft);
            } catch {
              parsedDraft = { raw: data.draft };
            }
    
            const lines = [`# Draft: \`${draft_key}\`\n`];
            lines.push(`**Sequence:** ${data.draft_sequence ?? "unknown"}`);
    
            if (parsedDraft.title) lines.push(`**Title:** ${parsedDraft.title}`);
            if (parsedDraft.categoryId) lines.push(`**Category ID:** ${parsedDraft.categoryId}`);
            if (parsedDraft.tags && Array.isArray(parsedDraft.tags)) {
              lines.push(`**Tags:** ${(parsedDraft.tags as string[]).join(", ")}`);
            }
            if (parsedDraft.action) lines.push(`**Action:** ${parsedDraft.action}`);
    
            if (parsedDraft.reply) {
              lines.push(`\n**Content:**\n${parsedDraft.reply}`);
            }
    
            lines.push("\n```json");
            lines.push(
              JSON.stringify(
                {
                  draft_key,
                  draft_sequence: data.draft_sequence,
                  data: parsedDraft,
                },
                null,
                2
              )
            );
            lines.push("```");
    
            return { content: [{ type: "text", text: lines.join("\n") }] };
          } catch (e: unknown) {
            const msg = e instanceof Error ? e.message : String(e);
            return { content: [{ type: "text", text: `Failed to get draft: ${msg}` }], isError: true };
          }
        }
      );
    };
Behavior3/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 describes the retrieval action and key examples but does not disclose behavioral traits like authentication requirements, rate limits, error conditions, or what happens if the draft doesn't exist. The description is accurate but lacks depth for a tool with no annotation 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?

The description is two sentences, front-loaded with the core purpose and followed by helpful examples. Every sentence earns its place by adding clarity without redundancy. It is appropriately sized for a simple retrieval tool with two parameters.

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 and no output schema, the description is adequate for a simple read operation but lacks completeness. It covers the purpose and parameters well but does not address behavioral aspects like error handling or return format. For a tool with 2 parameters and 100% schema coverage, it meets minimum viability but could be more informative about the tool's behavior.

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 both parameters thoroughly. The description adds value by providing common key examples ('new_topic', 'topic_<id>') which give semantic context beyond the schema's generic examples. However, it does not explain parameter interactions or optionality beyond what the schema provides, meeting the baseline for high coverage.

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 ('Retrieve') and resource ('a specific draft by its key'), making the purpose explicit. It distinguishes from sibling tools like 'discourse_list_drafts' by focusing on retrieval of a single draft rather than listing multiple drafts. The mention of common key examples ('new_topic', 'topic_<id>') further clarifies the scope.

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 for when to use this tool: to retrieve a specific draft by its key, with examples of common keys. It implicitly distinguishes from 'discourse_list_drafts' (which lists drafts) but does not explicitly state when NOT to use it or mention all possible alternatives among siblings. The guidance is helpful but lacks explicit exclusions.

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/SamSaffron/discourse-mcp'

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