Skip to main content
Glama
apolosan

Design Patterns MCP Server

by apolosan

count_patterns

Count design patterns in the database to assess available solutions for programming problems, with optional category breakdown.

Instructions

Get the total number of design patterns in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeDetailsNoInclude breakdown by category

Implementation Reference

  • Primary handler function for 'count_patterns' tool. Validates args using InputValidator, executes efficient SQL COUNT(*) query for total patterns, and optional GROUP BY category for breakdown. Returns formatted markdown content with results.
    private handleCountPatterns(args: unknown): CallToolResult {
      try {
        const validatedArgs = InputValidator.validateCountPatternsArgs(args);
        // OPTIMIZATION: Use COUNT instead of loading all rows
        const totalResult = this.db.queryOne<{ total: number }>(
          'SELECT COUNT(*) as total FROM patterns'
        );
        const total = totalResult?.total || 0;
    
        if (validatedArgs.includeDetails) {
          // Get category breakdown efficiently
          const breakdown = this.db.query<{ category: string; count: number }>(
            'SELECT category, COUNT(*) as count FROM patterns GROUP BY category ORDER BY count DESC'
          );
    
          return {
            content: [
              {
                type: 'text',
                text:
                  `## Total Design Patterns: ${total}\n\n` +
                  `### Breakdown by Category:\n` +
                  breakdown.map(item => `- **${item.category}**: ${item.count} patterns`).join('\n') +
                  '\n\n' +
                  `*Total patterns from all sources: ${total}*`,
              },
            ],
          };
        } else {
          return {
            content: [
              {
                type: 'text',
                text: `Total design patterns in database: **${total}**`,
              },
            ],
          };
        }
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Pattern count failed: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • Tool registration in ListToolsRequestSchema handler. Defines name, description, and inputSchema for the count_patterns tool.
      name: 'count_patterns',
      description: 'Get the total number of design patterns in the database',
      inputSchema: {
        type: 'object',
        properties: {
          includeDetails: {
            type: 'boolean',
            description: 'Include breakdown by category',
            default: false,
          },
        },
      },
    },
  • TypeScript interface and type guard for CountPatternsArgs, defining the expected input structure for the tool.
    export interface CountPatternsArgs {
      includeDetails?: boolean;
    }
    
    export function isCountPatternsArgs(args: unknown): args is CountPatternsArgs {
      if (typeof args !== 'object' || args === null) return false;
      const a = args as Record<string, unknown>;
      return a.includeDetails === undefined || typeof a.includeDetails === 'boolean';
    }
  • Input validation helper specifically for count_patterns tool arguments. Throws McpError on invalid input, sanitizes includeDetails boolean.
    /**
     * Validates all inputs for count_patterns tool
     */
    static validateCountPatternsArgs(args: unknown): {
      includeDetails: boolean;
    } {
      if (typeof args !== 'object' || args === null) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments: expected object');
      }
      const obj = args as Record<string, unknown>;
      const includeDetailsResult = this.validateIncludeDetails(obj.includeDetails);
      this.throwIfInvalid(includeDetailsResult);
    
      return {
        includeDetails: (includeDetailsResult.sanitized as boolean) ?? 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. It states the tool 'Get[s] the total number', implying a read-only operation, but doesn't mention any behavioral traits such as performance considerations, error handling, or whether it's a simple count versus an aggregated query. For a 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 a single, efficient sentence that directly states the tool's purpose without any unnecessary words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly. Every part of the sentence earns its place by conveying essential information.

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

Completeness3/5

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

Given the tool's low complexity (one optional parameter) and high schema coverage, the description is adequate but has clear gaps. It lacks output schema information, usage guidelines, and behavioral context, which could help an agent use it correctly. However, for a simple counting tool, it meets the minimum viable threshold without being fully comprehensive.

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?

The input schema has 100% description coverage, with the parameter 'includeDetails' clearly documented in the schema. The description adds no additional meaning beyond what the schema provides, as it doesn't mention parameters at all. According to the rules, when schema_description_coverage is high (>80%), the baseline score is 3, which is appropriate here.

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 with a specific verb ('Get') and resource ('total number of design patterns in the database'), making it easy to understand what it does. However, it doesn't explicitly differentiate from sibling tools like 'find_patterns' or 'search_patterns', which might also retrieve pattern information, so it doesn't reach the highest score.

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', 'get_pattern_details', or 'search_patterns'. It lacks any context about use cases, prerequisites, or exclusions, leaving the agent to infer usage based on the name 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