Skip to main content
Glama

Discourse Search

discourse_search

Search content on Discourse forums to find topics, posts, and discussions using specific queries and filters.

Instructions

Search site content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
with_privateNo
max_resultsNo

Implementation Reference

  • The handler function that executes the discourse_search tool. It queries the Discourse search API with the provided query (optionally prefixed), extracts topics, formats a numbered list of results with URLs, appends a JSON summary, and handles errors.
    async (args, _extra: any) => {
      const { query, with_private = false, max_results = 10 } = args;
      const { base, client } = ctx.siteState.ensureSelectedSite();
      const q = new URLSearchParams();
      q.set("expanded", "true");
      const fullQuery = ctx.defaultSearchPrefix ? `${ctx.defaultSearchPrefix} ${query}` : query;
      q.set("q", fullQuery);
      try {
        const data = (await client.get(`/search.json?${q.toString()}`)) as any;
        const topics: any[] = data?.topics || [];
        const posts: any[] = data?.posts || [];
    
        const items = (topics.map((t) => ({
          type: "topic" as const,
          id: t.id,
          title: t.title,
          slug: t.slug,
        })) as Array<{ type: "topic"; id: number; title: string; slug: string }>).slice(0, max_results);
    
        const lines: string[] = [];
        lines.push(`Top results for "${query}":`);
        let idx = 1;
        for (const it of items) {
          const url = `${base}/t/${it.slug}/${it.id}`;
          lines.push(`${idx}. ${it.title} – ${url}`);
          idx++;
        }
    
        const jsonFooter = {
          results: items.map((it) => ({ id: it.id, url: `${base}/t/${it.slug}/${it.id}`, title: it.title })),
        };
        const text = lines.join("\n") + "\n\n```json\n" + JSON.stringify(jsonFooter) + "\n```\n";
        return { content: [{ type: "text", text }] };
      } catch (e: any) {
        return { content: [{ type: "text", text: `Search failed: ${e?.message || String(e)}` }], isError: true };
      }
    }
  • Zod schema defining the input parameters for the discourse_search tool: query (required string), with_private (optional boolean), max_results (optional int 1-50).
    const schema = z.object({
      query: z.string().min(1).describe("Search query"),
      with_private: z.boolean().optional(),
      max_results: z.number().int().min(1).max(50).optional(),
    });
  • Registration of the discourse_search tool using server.registerTool, including name, metadata (title, description, inputSchema), and the handler function.
    server.registerTool(
      "discourse_search",
      {
        title: "Discourse Search",
        description: "Search site content.",
        inputSchema: schema.shape,
      },
      async (args, _extra: any) => {
        const { query, with_private = false, max_results = 10 } = args;
        const { base, client } = ctx.siteState.ensureSelectedSite();
        const q = new URLSearchParams();
        q.set("expanded", "true");
        const fullQuery = ctx.defaultSearchPrefix ? `${ctx.defaultSearchPrefix} ${query}` : query;
        q.set("q", fullQuery);
        try {
          const data = (await client.get(`/search.json?${q.toString()}`)) as any;
          const topics: any[] = data?.topics || [];
          const posts: any[] = data?.posts || [];
    
          const items = (topics.map((t) => ({
            type: "topic" as const,
            id: t.id,
            title: t.title,
            slug: t.slug,
          })) as Array<{ type: "topic"; id: number; title: string; slug: string }>).slice(0, max_results);
    
          const lines: string[] = [];
          lines.push(`Top results for "${query}":`);
          let idx = 1;
          for (const it of items) {
            const url = `${base}/t/${it.slug}/${it.id}`;
            lines.push(`${idx}. ${it.title} – ${url}`);
            idx++;
          }
    
          const jsonFooter = {
            results: items.map((it) => ({ id: it.id, url: `${base}/t/${it.slug}/${it.id}`, title: it.title })),
          };
          const text = lines.join("\n") + "\n\n```json\n" + JSON.stringify(jsonFooter) + "\n```\n";
          return { content: [{ type: "text", text }] };
        } catch (e: any) {
          return { content: [{ type: "text", text: `Search failed: ${e?.message || String(e)}` }], isError: true };
        }
      }
    );
  • Invocation of registerSearch function within the registerAllTools, which internally registers the discourse_search tool.
    registerSearch(server, ctx, { allowWrites: false });
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 of behavioral disclosure. 'Search site content' implies a read-only operation, but it doesn't specify aspects like authentication requirements, rate limits, pagination behavior, or what happens with the 'with_private' parameter (e.g., if it requires special permissions). For a search tool with 3 parameters and no output schema, this is a significant gap in transparency.

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 extremely concise at three words, with no wasted sentences. It's front-loaded and to the point, making it easy to parse quickly. However, this conciseness comes at the cost of detail, which is reflected in lower scores for other dimensions.

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 (3 parameters, 33% schema coverage, no annotations, no output schema), the description is incomplete. It doesn't explain the tool's behavior, output format, or how parameters interact, leaving the agent with insufficient information to use the tool effectively. For a search function with siblings that might overlap, more context is needed to ensure proper invocation.

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 33% (only 'query' has a description), so the description must compensate but doesn't add any parameter details. It mentions 'site content' which loosely relates to the 'query' parameter but provides no specifics on syntax, how 'with_private' affects results, or the meaning of 'max_results' beyond the schema's numeric constraints. This results in minimal added value over the schema, aligning with the baseline for moderate coverage gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Search site content' states the verb (search) and resource (site content), providing a basic purpose. However, it's vague about what 'site content' specifically includes (e.g., posts, topics, users) and doesn't distinguish from siblings like 'discourse_filter_topics' or 'discourse_select_site', which might also involve searching or filtering content. This leaves the agent uncertain about the tool's exact scope.

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

Usage Guidelines2/5

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

The description offers no guidance on when to use this tool versus alternatives. With siblings like 'discourse_filter_topics' and 'discourse_select_site' that might overlap in functionality, there's no indication of when this search tool is preferred, such as for broad content queries versus specific filtering. This lack of context could lead to incorrect tool selection by the agent.

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