Skip to main content
Glama

List Drafts

discourse_list_drafts

Retrieve all drafts for the current user to find existing content before making updates. Shows draft keys, sequences, and preview content.

Instructions

List all drafts for the current user. Returns draft keys, sequences, and preview content. Use this to find existing drafts before updating them.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
offsetNoPagination offset (default: 0)

Implementation Reference

  • The handler function that lists all drafts for the current user by calling the Discourse /drafts.json API, formats a markdown summary with previews, and includes a JSON dump of the drafts.
    async (input: unknown, _extra: unknown) => {
      const { offset } = schema.parse(input);
    
      try {
        const { base, client } = ctx.siteState.ensureSelectedSite();
        const params = new URLSearchParams();
        if (typeof offset === "number") params.set("offset", String(offset));
    
        const url = `/drafts.json${params.toString() ? `?${params}` : ""}`;
        const data = (await client.get(url)) as {
          drafts?: Array<{
            draft_key: string;
            sequence: number;
            data?: string;
            title?: string;
            category_id?: number;
            created_at?: string;
          }>;
        };
    
        const drafts = data?.drafts || [];
    
        if (drafts.length === 0) {
          return { content: [{ type: "text", text: "No drafts found." }] };
        }
    
        const lines = ["# Drafts\n"];
        for (const draft of drafts) {
          lines.push(`## Draft: \`${draft.draft_key}\` (sequence: ${draft.sequence})`);
          if (draft.title) lines.push(`**Title:** ${draft.title}`);
          if (draft.category_id) lines.push(`**Category ID:** ${draft.category_id}`);
          if (draft.created_at) lines.push(`**Created:** ${draft.created_at}`);
    
          // Parse and show preview of reply content
          if (draft.data) {
            try {
              const parsed = JSON.parse(draft.data);
              if (parsed.reply) {
                const preview = parsed.reply.length > 200 ? parsed.reply.slice(0, 200) + "..." : parsed.reply;
                lines.push(`**Preview:**\n> ${preview.replace(/\n/g, "\n> ")}`);
              }
            } catch {
              // Ignore parse errors
            }
          }
          lines.push("");
        }
    
        lines.push("\n```json");
        lines.push(JSON.stringify(drafts, 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 list drafts: ${msg}` }], isError: true };
      }
    }
  • Zod input schema defining optional 'offset' parameter for pagination.
    const schema = z.object({
      offset: z.number().int().min(0).optional().describe("Pagination offset (default: 0)"),
    });
  • Registration of the 'discourse_list_drafts' tool using server.registerTool, specifying title, description, inputSchema, and handler.
    server.registerTool(
      "discourse_list_drafts",
      {
        title: "List Drafts",
        description:
          "List all drafts for the current user. Returns draft keys, sequences, and preview content. Use this to find existing drafts before updating them.",
        inputSchema: schema.shape,
      },
      async (input: unknown, _extra: unknown) => {
        const { offset } = schema.parse(input);
    
        try {
          const { base, client } = ctx.siteState.ensureSelectedSite();
          const params = new URLSearchParams();
          if (typeof offset === "number") params.set("offset", String(offset));
    
          const url = `/drafts.json${params.toString() ? `?${params}` : ""}`;
          const data = (await client.get(url)) as {
            drafts?: Array<{
              draft_key: string;
              sequence: number;
              data?: string;
              title?: string;
              category_id?: number;
              created_at?: string;
            }>;
          };
    
          const drafts = data?.drafts || [];
    
          if (drafts.length === 0) {
            return { content: [{ type: "text", text: "No drafts found." }] };
          }
    
          const lines = ["# Drafts\n"];
          for (const draft of drafts) {
            lines.push(`## Draft: \`${draft.draft_key}\` (sequence: ${draft.sequence})`);
            if (draft.title) lines.push(`**Title:** ${draft.title}`);
            if (draft.category_id) lines.push(`**Category ID:** ${draft.category_id}`);
            if (draft.created_at) lines.push(`**Created:** ${draft.created_at}`);
    
            // Parse and show preview of reply content
            if (draft.data) {
              try {
                const parsed = JSON.parse(draft.data);
                if (parsed.reply) {
                  const preview = parsed.reply.length > 200 ? parsed.reply.slice(0, 200) + "..." : parsed.reply;
                  lines.push(`**Preview:**\n> ${preview.replace(/\n/g, "\n> ")}`);
                }
              } catch {
                // Ignore parse errors
              }
            }
            lines.push("");
          }
    
          lines.push("\n```json");
          lines.push(JSON.stringify(drafts, 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 list drafts: ${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 discloses that it lists drafts for the current user and returns specific data, which is good. However, it doesn't mention behavioral traits like pagination details (implied by the 'offset' parameter but not explained), rate limits, or authentication needs, leaving gaps 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 usage guidance. Every sentence adds value without redundancy, making it efficient and well-structured for quick understanding by an agent.

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, no output schema, and a simple input schema, the description is adequate but incomplete. It covers the purpose and usage context, but lacks details on return format (beyond a high-level mention), pagination behavior, or error handling. For a list tool with minimal structured data, it's minimally viable but could be more comprehensive.

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?

The input schema has 1 parameter with 100% description coverage, so the schema already documents 'offset' fully. The description doesn't add any parameter-specific information beyond what's in the schema, such as default behavior or usage tips. This meets the baseline for high schema coverage, but doesn't compensate with extra insights.

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 tool's purpose with a specific verb ('List') and resource ('all drafts for the current user'), and mentions what it returns ('draft keys, sequences, and preview content'). However, it doesn't explicitly differentiate from sibling tools like 'discourse_get_draft' or 'discourse_list_user_posts', which might also involve user content retrieval, so it doesn't reach the highest score.

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 usage ('Use this to find existing drafts before updating them'), which implies when to use it. It doesn't explicitly state when not to use it or name alternatives, but the guidance is practical and helpful for an agent, so it's above the baseline of implied usage.

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