Skip to main content
Glama

Search Problem Patterns

search_problem_patterns

Search for pre-defined problem patterns to get recommended transformations and top mental models for solving your specific problem.

Instructions

Find pre-defined problem patterns with recommended transformations and top models based on a search query.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (minimum 2 characters)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
patternCountYes
patternsYes

Implementation Reference

  • The handler function that executes the search_problem_patterns tool logic. It uses PATTERN_BM25_INDEX.score(query) to perform BM25-ranked search over PROBLEM_PATTERNS, filters for scores > 0, and returns the matching patterns with their transformations, top models, and relevance score.
    async ({ query }) => {
      // BM25-ranked search: patterns are ordered by relevance score.
      // Only patterns with score > 0 are returned.
      const ranked = PATTERN_BM25_INDEX.score(query);
      const matchingPatterns = ranked
        .filter((r) => r.score > 0)
        .map((r) => ({
          ...PROBLEM_PATTERNS[r.index]!,
          score: Math.round(r.score * 1000) / 1000,
        }));
    
      const payload = {
        query,
        patternCount: matchingPatterns.length,
        patterns: matchingPatterns,
      };
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(payload, null, 2),
          },
        ],
        structuredContent: payload,
      } as const;
    }
  • Input/output schema for search_problem_patterns. Input: query (string, min 2 chars). Output: query, patternCount, and an array of patterns each with pattern name, transformations, topModels, and score.
    {
      title: "Search Problem Patterns",
      description:
        "Find pre-defined problem patterns with recommended transformations and top models based on a search query.",
      inputSchema: z.object({
        query: z.string().min(2).describe("Search query (minimum 2 characters)"),
      }),
      outputSchema: z.object({
        query: z.string(),
        patternCount: z.number(),
        patterns: z.array(
          z.object({
            pattern: z.string(),
            transformations: z.array(z.string()),
            topModels: z.array(z.string()),
            score: z.number(),
          })
        ),
      }),
  • Registration of the 'search_problem_patterns' tool with the MCP server via server.registerTool(), including title and description metadata.
    // Tool: Search problem patterns
    server.registerTool(
      "search_problem_patterns",
      {
  • PATTERN_BM25_INDEX is a pre-built BM25Index created from PROBLEM_PATTERNS. Each pattern's searchable document includes the pattern text, transformation names, and top model names for richer matching.
    // ---------- BM25 pattern index ----------
    
    import { BM25Index } from "./bm25.js";
    
    /**
     * Pre-built BM25 index over PROBLEM_PATTERNS. Each pattern's searchable
     * "document" is the pattern text + its transformation name(s) + top-model
     * names, giving BM25 a richer term set to match against.
     */
    export const PATTERN_BM25_INDEX = new BM25Index(
      PROBLEM_PATTERNS.map((p) => {
        const transNames = p.transformations.map((t) => TRANSFORMATIONS[t]?.name ?? t).join(" ");
        const modelNames = p.topModels
          .map((code) => {
            const model = getAllModels().find((m) => m.code === code);
            return model ? model.name : code;
          })
          .join(" ");
        return `${p.pattern} ${transNames} ${modelNames}`;
      })
    );
  • The BM25Index class implementation with tokenization, IDF computation, and the score() method that ranks documents by relevance using the BM25 ranking formula.
    export class BM25Index {
      /** k1: term-frequency saturation. Standard default. */
      private readonly k1 = 1.5;
      /** b: document-length normalisation weight. Standard default. */
      private readonly b = 0.75;
    
      private readonly docs: string[][];
      private readonly avgDl: number;
      private readonly idf: Map<string, number>;
    
      constructor(documents: string[]) {
        this.docs = documents.map(tokenize);
        const totalLen = this.docs.reduce((sum, d) => sum + d.length, 0);
        this.avgDl = this.docs.length > 0 ? totalLen / this.docs.length : 1;
        this.idf = this.computeIdf();
      }
    
      private computeIdf(): Map<string, number> {
        const n = this.docs.length;
        const df = new Map<string, number>();
        for (const doc of this.docs) {
          const seen = new Set<string>();
          for (const term of doc) {
            if (!seen.has(term)) {
              df.set(term, (df.get(term) ?? 0) + 1);
              seen.add(term);
            }
          }
        }
        const idf = new Map<string, number>();
        for (const [term, freq] of df) {
          // Standard BM25 IDF with +0.5 smoothing to avoid negatives.
          idf.set(term, Math.log((n - freq + 0.5) / (freq + 0.5) + 1));
        }
        return idf;
      }
    
      /**
       * Score a query against every document in the index.
       * Returns an array of `{ index, score }` sorted by score descending.
       * Scores are always ≥ 0; a score of 0 means no query terms matched.
       */
      score(query: string): Array<{ index: number; score: number }> {
        const queryTerms = tokenize(query);
        const results: Array<{ index: number; score: number }> = [];
    
        for (let i = 0; i < this.docs.length; i++) {
          const doc = this.docs[i]!;
          const dl = doc.length;
          let score = 0;
    
          // Term-frequency map for this document.
          const tf = new Map<string, number>();
          for (const term of doc) {
            tf.set(term, (tf.get(term) ?? 0) + 1);
          }
    
          for (const term of queryTerms) {
            const termFreq = tf.get(term) ?? 0;
            if (termFreq === 0) continue;
            const idfVal = this.idf.get(term) ?? 0;
            const numerator = termFreq * (this.k1 + 1);
            const denominator = termFreq + this.k1 * (1 - this.b + this.b * (dl / this.avgDl));
            score += idfVal * (numerator / denominator);
          }
    
          results.push({ index: i, score });
        }
    
        results.sort((a, b) => b.score - a.score);
        return results;
      }
    }
Behavior2/5

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

No annotations provided. The description only states it finds patterns and recommendations, without disclosing whether the operation is read-only, requires authentication, or any pagination or sorting 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?

Single clear sentence with no extraneous words. Front-loaded with the action and resource.

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

Completeness4/5

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

The tool has an output schema, so return values are documented elsewhere. For a simple search with one parameter, the description sufficiently explains what is returned. Minor gaps exist but overall adequate given low complexity.

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 coverage is 100% with adequate description of the 'query' parameter. The tool description adds context about the nature of results (pre-defined patterns, recommended transformations, top models), but does not add further semantic detail to parameters.

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 it finds pre-defined problem patterns with associated transformations and models. It distinguishes from sibling tools like 'search_models' and 'recommend_models' by focusing on patterns rather than directly on models or workflows.

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 like 'search_models' or 'find_workflow_for_problem'. The description implies use for problem pattern search, but does not specify when not to use it or provide explicit 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/hummbl-dev/mcp-server'

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