Skip to main content
Glama
ahnmichael

GitLab Forum MCP

by ahnmichael

Discourse Search

discourse_search

Search GitLab community forum content to find discussions and solutions for troubleshooting CI/CD issues and GitLab features.

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 performs an API search on the Discourse site using the provided query, processes the results (topics and posts), formats a text response with links, and includes a JSON summary of results.
    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);
    
      // Debug logging
      ctx.logger?.debug(`Search query: "${query}"`);
      ctx.logger?.debug(`Full query with prefix: "${fullQuery}"`);
      ctx.logger?.debug(`Search URL: ${base}/search.json?${q.toString()}`);
    
      try {
        const data = (await client.get(`/search.json?${q.toString()}`)) as any;
    
        // Debug the response structure
        ctx.logger?.debug(`Search response keys: ${Object.keys(data || {}).join(', ')}`);
        ctx.logger?.debug(`Topics found: ${data?.topics?.length || 0}`);
        ctx.logger?.debug(`Posts found: ${data?.posts?.length || 0}`);
    
        const topics: any[] = data?.topics || [];
        const posts: any[] = data?.posts || [];
    
        // If no topics but we have posts, we can extract topic info from posts
        let items = topics.map((t) => ({
          type: "topic" as const,
          id: t.id,
          title: t.title || t.fancy_title || `Topic ${t.id}`,
          slug: t.slug || String(t.id),
        })) as Array<{ type: "topic"; id: number; title: string; slug: string }>;
    
        // If we don't have enough topics, supplement with unique topics from posts
        if (items.length < max_results && posts.length > 0) {
          const existingTopicIds = new Set(items.map(t => t.id));
          const postTopics = posts
            .filter(p => p.topic_id && !existingTopicIds.has(p.topic_id))
            .map(p => ({
              type: "topic" as const,
              id: p.topic_id,
              title: `Post topic ${p.topic_id}`, // We don't have the topic title from post
              slug: String(p.topic_id),
            }));
    
          // Add unique post topics up to our limit
          const seenIds = new Set();
          for (const pt of postTopics) {
            if (items.length >= max_results) break;
            if (!seenIds.has(pt.id)) {
              seenIds.add(pt.id);
              items.push(pt);
            }
          }
        }
    
        items = items.slice(0, max_results);
    
        const lines: string[] = [];
        if (items.length === 0) {
          lines.push(`No results found for "${query}"`);
          // Add some debug info about what we got
          if (posts.length > 0) {
            lines.push(`Found ${posts.length} posts but no direct topics`);
          }
        } else {
          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) {
        ctx.logger?.error(`Search failed: ${e?.message || String(e)}`);
        return { content: [{ type: "text", text: `Search failed: ${e?.message || String(e)}` }], isError: true };
      }
    }
  • Input schema for the discourse_search tool using Zod, validating query (required string), optional with_private boolean, and optional max_results (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 the MCP server inside the registerSearch function, specifying title, description, input schema, and handler.
    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);
    
        // Debug logging
        ctx.logger?.debug(`Search query: "${query}"`);
        ctx.logger?.debug(`Full query with prefix: "${fullQuery}"`);
        ctx.logger?.debug(`Search URL: ${base}/search.json?${q.toString()}`);
    
        try {
          const data = (await client.get(`/search.json?${q.toString()}`)) as any;
    
          // Debug the response structure
          ctx.logger?.debug(`Search response keys: ${Object.keys(data || {}).join(', ')}`);
          ctx.logger?.debug(`Topics found: ${data?.topics?.length || 0}`);
          ctx.logger?.debug(`Posts found: ${data?.posts?.length || 0}`);
    
          const topics: any[] = data?.topics || [];
          const posts: any[] = data?.posts || [];
    
          // If no topics but we have posts, we can extract topic info from posts
          let items = topics.map((t) => ({
            type: "topic" as const,
            id: t.id,
            title: t.title || t.fancy_title || `Topic ${t.id}`,
            slug: t.slug || String(t.id),
          })) as Array<{ type: "topic"; id: number; title: string; slug: string }>;
    
          // If we don't have enough topics, supplement with unique topics from posts
          if (items.length < max_results && posts.length > 0) {
            const existingTopicIds = new Set(items.map(t => t.id));
            const postTopics = posts
              .filter(p => p.topic_id && !existingTopicIds.has(p.topic_id))
              .map(p => ({
                type: "topic" as const,
                id: p.topic_id,
                title: `Post topic ${p.topic_id}`, // We don't have the topic title from post
                slug: String(p.topic_id),
              }));
    
            // Add unique post topics up to our limit
            const seenIds = new Set();
            for (const pt of postTopics) {
              if (items.length >= max_results) break;
              if (!seenIds.has(pt.id)) {
                seenIds.add(pt.id);
                items.push(pt);
              }
            }
          }
    
          items = items.slice(0, max_results);
    
          const lines: string[] = [];
          if (items.length === 0) {
            lines.push(`No results found for "${query}"`);
            // Add some debug info about what we got
            if (posts.length > 0) {
              lines.push(`Found ${posts.length} posts but no direct topics`);
            }
          } else {
            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) {
          ctx.logger?.error(`Search failed: ${e?.message || String(e)}`);
          return { content: [{ type: "text", text: `Search failed: ${e?.message || String(e)}` }], isError: true };
        }
      }
    );
  • Top-level call to registerSearch during the registration of all tools, effectively registering 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 permissions needed, rate limits, pagination behavior, or what 'with_private' entails (e.g., access to private content). For a search tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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: 'Search site content.' It's front-loaded and wastes no space, making it easy to parse. Every word contributes directly to the purpose, earning its place without unnecessary elaboration.

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 (a search tool with 3 parameters), no annotations, no output schema, and low schema coverage (33%), the description is incomplete. It doesn't explain return values, error conditions, or how results are structured. For a tool that likely returns search results, more context is needed to use it effectively, making it inadequate for the given context.

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. It mentions no parameters, leaving 'with_private' and 'max_results' undocumented. Since schema coverage is low (<50%), the baseline isn't met, but the description adds no value beyond the schema. However, with 3 parameters and minimal schema info, it's not entirely inadequate, warranting a middle score.

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 states the verb (search) and resource (site content), but it's vague about what 'site content' specifically refers to. It doesn't distinguish this tool from potential siblings like 'discourse_filter_topics' or 'discourse_read_post', which might also involve content retrieval. The purpose is understandable 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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'discourse_filter_topics' and 'discourse_read_post' available, there's no indication of whether this is for general searches, filtered searches, or specific content types. No exclusions, prerequisites, or context for usage are mentioned.

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/ahnmichael/gitlab-forum-mcp'

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