Skip to main content
Glama
apolosan

Design Patterns MCP Server

by apolosan

search_patterns

Find design patterns by keyword or semantic similarity to solve programming problems. Search across 200+ patterns using natural language queries.

Instructions

Search patterns by keyword or semantic similarity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
searchTypeNohybrid
limitNo

Implementation Reference

  • Registration of the 'search_patterns' tool in the MCP server's tool list, including description and input schema
      name: 'search_patterns',
      description: 'Search patterns by keyword or semantic similarity',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query',
          },
          searchType: {
            type: 'string',
            enum: ['keyword', 'semantic', 'hybrid'],
            default: 'hybrid',
          },
          limit: {
            type: 'number',
            default: 10,
          },
        },
        required: ['query'],
      },
    },
  • Handler function for executing the search_patterns tool: validates input, performs semantic search via SemanticSearchService, and formats results as text response
    private async handleSearchPatterns(args: unknown): Promise<CallToolResult> {
      const validatedArgs = InputValidator.validateSearchPatternsArgs(args);
      const query = {
        text: validatedArgs.query,
        filters: {},
        options: {
          limit: validatedArgs.limit,
          includeMetadata: true,
        },
      };
    
      const results = await this.semanticSearch.search(query);
    
      return {
        content: [
          {
            type: 'text',
            text:
              `Search results for "${validatedArgs.query}":\n\n` +
              results
                .map(
                  (result, index) =>
                    `${index + 1}. **${result.pattern.name}** (${result.pattern.category})\n` +
                    `   Score: ${(result.score * 100).toFixed(1)}%\n` +
                    `   Description: ${result.pattern.description}\n`
                )
                .join('\n'),
          },
        ],
      };
    }
  • TypeScript interface definition and type guard for SearchPatternsArgs used in tool input validation
    export interface SearchPatternsArgs {
      query: string;
      search_type?: 'keyword' | 'semantic' | 'hybrid';
      category_filter?: string[];
      limit?: number;
    }
    
    export function isSearchPatternsArgs(args: unknown): args is SearchPatternsArgs {
      if (typeof args !== 'object' || args === null) return false;
      const a = args as Record<string, unknown>;
      return typeof a.query === 'string' &&
        (a.search_type === undefined || ['keyword', 'semantic', 'hybrid'].includes(a.search_type as string)) &&
        (a.category_filter === undefined || Array.isArray(a.category_filter)) &&
        (a.limit === undefined || typeof a.limit === 'number');
    }
  • Tool dispatch case in MCPToolsHandler.handleToolCall that routes to handler
    case 'search_patterns':
      if (!isSearchPatternsArgs(args)) {
        throw new Error('Invalid arguments for search_patterns tool');
      }
      return await this.handleSearchPatterns(args);
  • Comprehensive hybrid search handler supporting keyword, semantic, and hybrid search modes with result merging (alternative implementation in lib)
    private async handleSearchPatterns(args: SearchPatternsArgs): Promise<Record<string, unknown>> {
      // Validate input
      if (!args.query || typeof args.query !== 'string' || args.query.length < 2) {
        throw new Error('Query must be at least 2 characters long');
      }
    
      const searchType = args.search_type ?? 'hybrid';
      const limit = Math.min(args.limit ?? 10, 50);
    
      try {
        let results: SearchResult[];
    
        if (searchType === 'semantic') {
          // Use semantic search
          results = await this.config.semanticSearch.search(args.query, {
            limit,
            filters: args.category_filter ? { categories: args.category_filter } : undefined,
          });
        } else if (searchType === 'keyword') {
          // Use keyword search
          results = await this.config.databaseManager.searchPatterns(args.query, {
            limit,
            filters: args.category_filter ? { categories: args.category_filter } : undefined,
          });
        } else {
          // Hybrid search
          const semanticResults = await this.config.semanticSearch.search(args.query, {
            limit: Math.ceil(limit / 2),
            filters: args.category_filter ? { categories: args.category_filter } : undefined,
          });
    
          const keywordResults = await this.config.databaseManager.searchPatterns(args.query, {
            limit: Math.ceil(limit / 2),
            filters: args.category_filter ? { categories: args.category_filter } : undefined,
          });
    
          // Merge and deduplicate results
          results = this.mergeSearchResults(semanticResults, keywordResults, limit);
        }
    
        return {
          patterns: results,
          total_results: results.length,
          search_type: searchType,
          limit,
          timestamp: new Date().toISOString(),
        };
      } catch (error) {
        throw new Error(
          `Pattern search failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
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 search functionality but fails to describe critical behaviors such as pagination, rate limits, authentication needs, or what happens on no matches. For a search tool with zero annotation coverage, 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 one sentence with zero waste, front-loading the core functionality. Every word earns its place, making it easy for an agent to parse quickly 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 tool's complexity as a search function with 3 parameters, no annotations, and no output schema, the description is incomplete. It lacks information on return values, error handling, and behavioral traits, leaving the agent with insufficient context to use the tool effectively beyond basic 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 low at 33%, with only the 'query' parameter documented. The description adds value by explaining that searches can be by keyword or semantic similarity, which helps interpret the 'searchType' enum, but it doesn't clarify the 'limit' parameter or provide details beyond what the schema implies. This partial compensation justifies a baseline score.

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 as searching patterns using keyword or semantic similarity, which is specific and actionable. However, it doesn't explicitly distinguish this from sibling tools like 'find_patterns' or 'count_patterns', leaving some ambiguity about when to choose one over another.

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 like 'find_patterns' or 'count_patterns'. It mentions search methods but doesn't specify scenarios, prerequisites, or exclusions, leaving the agent to guess based on tool names alone.

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/apolosan/design_patterns_mcp'

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