Skip to main content
Glama

List messages

list_messages

Retrieve and display message board posts from a Basecamp project with pagination options and customizable content formats.

Instructions

Resolves the project's message board from the dock, then lists messages with pagination. Optionally include full content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
pageNo
limitNo
formatNo
include_bodyNo
renderNo

Implementation Reference

  • The main execution logic for the 'list_messages' tool. Resolves project message board, fetches paginated messages, optionally includes rendered bodies, and formats output as table (default), JSON, or Markdown.
    async ({ project_id, page, limit, format, include_body, render }) => {
      const fmt = format ?? "table";
      const board = await getMessageBoardFromDock(project_id);
      if (!board) {
        return {
          content: [
            {
              type: "text",
              text: "No message board found in the project's dock.",
            },
          ],
        };
      }
    
      const { data, headers } = await bcRequestWithHeaders<any[]>(
        "GET",
        `/buckets/${project_id}/message_boards/${board.id}/messages.json`,
        undefined,
        page ? { page } : undefined
      );
    
      let messages = Array.isArray(data) ? data : [];
      if (limit) messages = messages.slice(0, limit);
    
      // If we want bodies, fetch each full message
      let bodies: Record<number, string> = {};
      if (include_body) {
        const fulls = await Promise.all(
          messages.map((m) =>
            bcRequest<any>(
              "GET",
              `/buckets/${project_id}/messages/${m.id}.json`
            ).then((msg) => ({ id: m.id, html: msg.content || msg.body || "" }))
          )
        );
        for (const { id, html } of fulls) {
          bodies[id] = renderBody(html, render ?? "markdown");
        }
      }
    
      const rows = messages.map((m) => ({
        id: m.id,
        subject: m.subject ?? m.title ?? "",
        status: m.status,
        created_at: m.created_at,
        updated_at: m.updated_at,
        comments_count: m.comments_count ?? m.comments?.count ?? 0,
        url: m.url || m.app_url || m.web_url || m.html_url || "",
        body: include_body ? bodies[m.id] : undefined,
      }));
    
      const nextPage = parseNextPage(headers.get("Link"));
    
      if (fmt === "json") {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  page: page ?? 1,
                  nextPage,
                  count: rows.length,
                  messages: rows,
                },
                null,
                2
              ),
            },
          ],
        };
      }
    
      if (fmt === "markdown") {
        // Full readable output with bodies
        const md = [
          `# Messages (page ${page ?? 1}${
            nextPage ? ` → next ${nextPage}` : ""
          })`,
          "",
          ...rows.map((r) => {
            const header = `## ${r.subject || "(no subject)"}  _(ID: ${r.id})_`;
            const meta =
              `- Comments: ${r.comments_count ?? 0}\n` +
              `- Created: ${(r.created_at ?? "").slice(0, 10)}  |  Updated: ${(
                r.updated_at ?? ""
              ).slice(0, 10)}\n` +
              (r.url ? `- Link: ${r.url}\n` : "");
            const body = include_body && r.body ? `\n${r.body}\n` : "";
            return [header, meta, body].join("\n");
          }),
        ].join("\n");
        return { content: [{ type: "text", text: md }] };
      }
    
      // Default table (no full bodies to avoid huge output)
      const trunc = (s: string, n: number) =>
        s && s.length > n ? s.slice(0, n - 1) + "…" : s || "";
      const header = [
        "ID".padEnd(12),
        "SUBJECT".padEnd(40),
        "CMTS".padEnd(4),
        "CREATED".padEnd(10),
        "UPDATED".padEnd(10),
        "URL",
      ].join("  ");
    
      const lines = [
        `Page: ${page ?? 1}${nextPage ? `  |  Next page: ${nextPage}` : ""}`,
        "",
        header,
        "-".repeat(120),
        ...rows.map((r) =>
          [
            String(r.id).padEnd(12),
            trunc(r.subject, 40).padEnd(40),
            String(r.comments_count ?? 0).padEnd(4),
            (r.created_at ?? "").slice(0, 10).padEnd(10),
            (r.updated_at ?? "").slice(0, 10).padEnd(10),
            trunc(r.url ?? "", 40),
          ].join("  ")
        ),
        include_body
          ? '\n(Use format: "markdown" to see full message content.)'
          : "",
      ].join("\n");
    
      return { content: [{ type: "text", text: lines }] };
    }
  • Zod input schema defining parameters: project_id (required), optional page, limit, format (table/json/markdown), include_body, render (markdown/html/text).
    inputSchema: {
      project_id: z.number().int(),
      page: z.number().int().positive().optional(),
      limit: z.number().int().positive().max(50).optional(), // keep modest for rate limits
      format: z.enum(["table", "json", "markdown"]).optional(), // default: table
      include_body: z.boolean().optional(), // include full message content
      render: z.enum(["markdown", "html", "text"]).optional(), // how to render body (default markdown)
    },
  • Tool registration via server.registerTool in registerMessageTools function, including name, metadata, schema, and handler reference. This function is called from the main MCP server setup.
    server.registerTool(
      "list_messages",
      {
        title: "List messages",
        description:
          "Resolves the project's message board from the dock, then lists messages with pagination. Optionally include full content.",
        inputSchema: {
          project_id: z.number().int(),
          page: z.number().int().positive().optional(),
          limit: z.number().int().positive().max(50).optional(), // keep modest for rate limits
          format: z.enum(["table", "json", "markdown"]).optional(), // default: table
          include_body: z.boolean().optional(), // include full message content
          render: z.enum(["markdown", "html", "text"]).optional(), // how to render body (default markdown)
        },
      },
      async ({ project_id, page, limit, format, include_body, render }) => {
        const fmt = format ?? "table";
        const board = await getMessageBoardFromDock(project_id);
        if (!board) {
          return {
            content: [
              {
                type: "text",
                text: "No message board found in the project's dock.",
              },
            ],
          };
        }
    
        const { data, headers } = await bcRequestWithHeaders<any[]>(
          "GET",
          `/buckets/${project_id}/message_boards/${board.id}/messages.json`,
          undefined,
          page ? { page } : undefined
        );
    
        let messages = Array.isArray(data) ? data : [];
        if (limit) messages = messages.slice(0, limit);
    
        // If we want bodies, fetch each full message
        let bodies: Record<number, string> = {};
        if (include_body) {
          const fulls = await Promise.all(
            messages.map((m) =>
              bcRequest<any>(
                "GET",
                `/buckets/${project_id}/messages/${m.id}.json`
              ).then((msg) => ({ id: m.id, html: msg.content || msg.body || "" }))
            )
          );
          for (const { id, html } of fulls) {
            bodies[id] = renderBody(html, render ?? "markdown");
          }
        }
    
        const rows = messages.map((m) => ({
          id: m.id,
          subject: m.subject ?? m.title ?? "",
          status: m.status,
          created_at: m.created_at,
          updated_at: m.updated_at,
          comments_count: m.comments_count ?? m.comments?.count ?? 0,
          url: m.url || m.app_url || m.web_url || m.html_url || "",
          body: include_body ? bodies[m.id] : undefined,
        }));
    
        const nextPage = parseNextPage(headers.get("Link"));
    
        if (fmt === "json") {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  {
                    page: page ?? 1,
                    nextPage,
                    count: rows.length,
                    messages: rows,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        }
    
        if (fmt === "markdown") {
          // Full readable output with bodies
          const md = [
            `# Messages (page ${page ?? 1}${
              nextPage ? ` → next ${nextPage}` : ""
            })`,
            "",
            ...rows.map((r) => {
              const header = `## ${r.subject || "(no subject)"}  _(ID: ${r.id})_`;
              const meta =
                `- Comments: ${r.comments_count ?? 0}\n` +
                `- Created: ${(r.created_at ?? "").slice(0, 10)}  |  Updated: ${(
                  r.updated_at ?? ""
                ).slice(0, 10)}\n` +
                (r.url ? `- Link: ${r.url}\n` : "");
              const body = include_body && r.body ? `\n${r.body}\n` : "";
              return [header, meta, body].join("\n");
            }),
          ].join("\n");
          return { content: [{ type: "text", text: md }] };
        }
    
        // Default table (no full bodies to avoid huge output)
        const trunc = (s: string, n: number) =>
          s && s.length > n ? s.slice(0, n - 1) + "…" : s || "";
        const header = [
          "ID".padEnd(12),
          "SUBJECT".padEnd(40),
          "CMTS".padEnd(4),
          "CREATED".padEnd(10),
          "UPDATED".padEnd(10),
          "URL",
        ].join("  ");
    
        const lines = [
          `Page: ${page ?? 1}${nextPage ? `  |  Next page: ${nextPage}` : ""}`,
          "",
          header,
          "-".repeat(120),
          ...rows.map((r) =>
            [
              String(r.id).padEnd(12),
              trunc(r.subject, 40).padEnd(40),
              String(r.comments_count ?? 0).padEnd(4),
              (r.created_at ?? "").slice(0, 10).padEnd(10),
              (r.updated_at ?? "").slice(0, 10).padEnd(10),
              trunc(r.url ?? "", 40),
            ].join("  ")
          ),
          include_body
            ? '\n(Use format: "markdown" to see full message content.)'
            : "",
        ].join("\n");
    
        return { content: [{ type: "text", text: lines }] };
      }
    );
  • Helper function to resolve the message board ID and URL from the project's dock array.
    async function getMessageBoardFromDock(
      project_id: number
    ): Promise<{ id: number; url: string } | null> {
      const project = await bcRequest<any>("GET", `/projects/${project_id}.json`);
      const dock = Array.isArray(project?.dock) ? project.dock : [];
    
      const board = dock.find((d: any) => {
        const n = (d?.name || d?.app_name || "").toLowerCase();
        return (
          n === "message_board" || n === "message-board" || n === "messageboard"
        );
      });
      if (!board) return null;
    
      const href: string =
        board.url || board.href || board.api_url || board.app_url || "";
      const m = href.match(/\/message_boards\/(\d+)/);
      return m ? { id: Number(m[1]), url: href } : null;
    }
  • Helper function to convert HTML message bodies to Markdown (using Turndown), HTML, or plain text.
    function renderBody(
      html: string,
      render: "markdown" | "html" | "text" = "markdown"
    ): string {
      const markdown = td.turndown(html || "");
      if (render === "markdown") return markdown;
      if (render === "html") return html || "";
      // crude Markdown → plain-text
      return markdown
        .replace(/```[\s\S]*?```/g, "") // drop code blocks
        .replace(/`([^`]+)`/g, "$1") // inline code
        .replace(/!\[([^\]]*)]\([^)]*\)/g, "$1") // images
        .replace(/\[([^\]]+)]\([^)]*\)/g, "$1") // links
        .replace(/^[#>\-\*\d\.\s]+/gm, "") // headings/quotes/lists
        .replace(/[*_~`]/g, "") // emphasis
        .trim();
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions pagination and optional full content inclusion, which adds some context. However, it lacks critical details such as whether this is a read-only operation (implied by 'list' but not stated), permission requirements, rate limits, error handling, or what 'resolves the project's message board from the dock' entails operationally. For a tool with 6 parameters and no annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences that front-load the core functionality. Each sentence adds value: the first defines the action and scope, the second adds key features. There is no redundant or wasted language, making it efficient, though it could be slightly more structured for clarity.

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

Completeness2/5

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

Given the complexity (6 parameters, no annotations, no output schema), the description is incomplete. It covers basic purpose and hints at some behaviors but omits details on parameter meanings, return values, error conditions, and operational constraints. For a tool that likely returns a list of messages, more context is needed to guide effective use by an AI agent.

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

Parameters2/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 for undocumented parameters. It only mentions 'pagination' (hinting at page/limit) and 'optionally include full content' (hinting at include_body), but fails to explain the purpose of project_id, format, render, or the specifics of pagination and content inclusion. With 6 parameters, this leaves most semantics unclear, falling short of adequately supplementing the schema.

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: 'Resolves the project's message board from the dock, then lists messages with pagination.' It specifies the verb ('list'), resource ('messages'), and scope ('project's message board'), distinguishing it from siblings like get_message (singular) or list_projects (different resource). However, it doesn't explicitly contrast with siblings like list_todolists, keeping it from a perfect score.

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 implies usage context by mentioning 'project's message board' and pagination, suggesting it's for browsing multiple messages within a project. However, it provides no explicit guidance on when to use this tool versus alternatives like get_message (for single messages) or other list_* tools, nor does it mention prerequisites or exclusions. The usage is inferred but not clearly articulated.

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/craigashields/basecamp-mcp'

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