Skip to main content
Glama
apolosan

Design Patterns MCP Server

by apolosan

get_pattern_details

Retrieve comprehensive information about specific design patterns to understand implementation details and use cases for solving programming problems.

Instructions

Get detailed information about a specific pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternIdYesPattern ID to get details for

Implementation Reference

  • The main execution logic for the get_pattern_details tool. Validates input, queries the database for pattern details and related implementations, handles cases where the pattern is not found by suggesting similar patterns via semantic search, parses JSON examples, and constructs a formatted markdown response with all details.
    private async handleGetPatternDetails(args: unknown): Promise<CallToolResult> {
      const validatedArgs = InputValidator.validateGetPatternDetailsArgs(args);
      const pattern = this.db.queryOne(
        `
        SELECT id, name, category, description, when_to_use, benefits,
               drawbacks, use_cases, complexity, tags, examples, created_at
        FROM patterns WHERE id = ?
      `,
        [validatedArgs.patternId]
      );
    
      if (!pattern) {
        // Try to find similar patterns using semantic search
        const similarPatterns = await this.semanticSearch.search({
          text: validatedArgs.patternId,
          options: {
            limit: 3,
            includeMetadata: true,
          },
        });
    
        if (similarPatterns.length > 0) {
          return {
            content: [
              {
                type: 'text',
                text: `Pattern "${validatedArgs.patternId}" not found. Here are similar patterns:\n\n${similarPatterns
                  .map(
                    (p, i) =>
                      `${i + 1}. **${p.pattern.name}** (${p.pattern.category})\n   ${p.pattern.description}\n   Score: ${(p.score * 100).toFixed(1)}%`
                  )
                  .join('\n\n')}`,
              },
            ],
          };
        } else {
          return {
            content: [
              {
                type: 'text',
                text: `Pattern "${validatedArgs.patternId}" not found and no similar patterns were found.`,
              },
            ],
          };
        }
      }
    
      const implementations = this.db.query(
        `
        SELECT language, code, explanation FROM pattern_implementations
        WHERE pattern_id = ? LIMIT 3
      `,
        [validatedArgs.patternId]
      );
    
      // Parse code examples if available
      let examplesText = '';
      if (pattern.examples) {
        try {
          const examples = JSON.parse(pattern.examples);
          const exampleKeys = Object.keys(examples);
    
          if (exampleKeys.length > 0) {
            examplesText = '\n\n**Code Examples:**\n';
            exampleKeys.forEach(lang => {
              const example = examples[lang];
              examplesText += `\n### ${lang.charAt(0).toUpperCase() + lang.slice(1)}\n`;
              if (example.description) {
                examplesText += `${example.description}\n\n`;
              }
              examplesText += `\`\`\`${lang}\n${example.code}\n\`\`\`\n`;
            });
          }
        } catch (e) {
          // If parsing fails, skip examples
        }
      }
    
      return {
        content: [
          {
            type: 'text',
            text:
              `# ${pattern.name} (${pattern.category})\n\n` +
              `**Description:** ${pattern.description}\n\n` +
              `**When to Use:** ${parseArrayProperty(pattern.when_to_use).join(', ')}\n\n` +
              `**Benefits:** ${parseArrayProperty(pattern.benefits).join(', ')}\n\n` +
              `**Drawbacks:** ${parseArrayProperty(pattern.drawbacks).join(', ')}\n\n` +
              `**Use Cases:** ${parseArrayProperty(pattern.use_cases).join(', ')}\n\n` +
              `**Complexity:** ${pattern.complexity}\n\n` +
              `**Tags:** ${parseTags(pattern.tags).join(', ')}\n` +
              examplesText +
              (implementations.length > 0
                ? `\n\n**Implementations:**\n` +
                  implementations
                    .map(
                      impl =>
                        `\n### ${impl.language}\n\`\`\`${impl.language.toLowerCase()}\n${impl.code}\n\`\`\`\n${impl.explanation}`
                    )
                    .join('\n')
                : ''),
          },
        ],
      };
    }
  • Tool registration in the ListToolsRequest handler, defining the tool name, description, and input schema (requiring a patternId string).
    {
      name: 'get_pattern_details',
      description: 'Get detailed information about a specific pattern',
      inputSchema: {
        type: 'object',
        properties: {
          patternId: {
            type: 'string',
            description: 'Pattern ID to get details for',
          },
        },
        required: ['patternId'],
      },
    },
  • Input validation schema enforcement for get_pattern_details tool arguments, using patternId validator to ensure valid string format and throw MCP errors on invalid input.
    static validateGetPatternDetailsArgs(args: unknown): {
      patternId: string;
    } {
      if (typeof args !== 'object' || args === null) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments: expected object');
      }
      const obj = args as Record<string, unknown>;
      const patternIdResult = this.validatePatternId(obj.patternId);
      this.throwIfInvalid(patternIdResult);
    
      return {
        patternId: patternIdResult.sanitized as string,
      };
    }
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 states it 'gets' information, implying a read-only operation, but doesn't disclose any behavioral traits such as error handling, permissions needed, rate limits, or what 'detailed information' includes. This is a significant gap for a tool with no annotation coverage.

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 wasted words. It is appropriately sized and front-loaded, making it easy to 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 lack of annotations and output schema, the description is incomplete. It doesn't explain what 'detailed information' entails, potential return values, or any behavioral context. For a tool with no structured data beyond the input schema, this leaves significant gaps in understanding its full functionality.

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 'patternId' clearly documented. The description adds no additional meaning beyond what the schema provides, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate.

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 verb 'Get' and the resource 'detailed information about a specific pattern', which is specific and understandable. However, it doesn't differentiate from sibling tools like 'find_patterns' or 'search_patterns' that 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' or 'search_patterns'. It lacks context about whether this is for retrieving details of a known pattern ID versus searching for patterns, leaving usage unclear.

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