Skip to main content
Glama
discourse

Discourse MCP

Official
by discourse

Discourse Search

discourse_search

Search content across Discourse forums to find relevant topics, posts, and discussions using specific queries.

Instructions

Search site content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
with_privateNo
max_resultsNo

Implementation Reference

  • Handler function that executes the discourse_search tool: parses args, calls the site's search API, formats results as numbered list with URLs and JSON summary.
    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 input schema for the tool defining parameters: 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(),
    });
  • Registers the 'discourse_search' tool with server.registerTool, providing name, metadata (title, description, schema), and 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 };
        }
      }
    );
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 only states the action ('search') without disclosing behavioral traits such as authentication requirements, rate limits, whether results are paginated, or what the output format looks like. For a search tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

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 with just three words, front-loaded and zero waste. It efficiently conveys the core purpose without unnecessary elaboration, making it easy to scan and understand quickly.

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 tool's complexity (search functionality with 3 parameters), no annotations, no output schema, and low schema description coverage, the description is incomplete. It doesn't cover key aspects like result format, error handling, or behavioral constraints, leaving the agent with insufficient information to use the tool effectively.

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 33% (only 'query' has a description), with 3 parameters total. The description adds no meaning beyond the schema—it doesn't explain what 'with_private' does (e.g., include private content) or how 'max_results' affects pagination. It fails to compensate for the low coverage, leaving most parameters undocumented in both schema and description.

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' clearly indicates the verb 'search' and resource 'site content', but it's vague about what 'site content' encompasses (topics, posts, users, etc.) and doesn't distinguish from siblings like discourse_filter_topics or discourse_select_site. It states what the tool does but lacks specificity.

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?

No guidance on when to use this tool versus alternatives is provided. It doesn't mention when to prefer this over siblings like discourse_filter_topics for filtering or discourse_select_site for site selection, nor does it specify any prerequisites or exclusions. The description offers no usage context.

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

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