Skip to main content
Glama

add_code_examples

Extend existing coding patterns by adding new language-specific examples to enhance code generation and refactoring capabilities.

Instructions

Add new code examples to existing patterns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
additionsYes

Implementation Reference

  • The addCodeExamples method in PatternsManager class - the core handler logic that loads the database, finds patterns by name, adds/updates code examples, saves the database, and returns results.
    async addCodeExamples(additions: { patternName: string; examples: { [language: string]: string } }[]): Promise<{ patternName: string; addedExamples: { [language: string]: string } }[]> {
      const database = await this.loadDatabase();
      const results = additions.map(a => {
        const pattern = database.patterns.find(p => p.name === a.patternName);
        if (!pattern) {
          throw new Error(`Pattern with name ${a.patternName} not found`);
        }
        const addedExamples: { [language: string]: string } = {};
        for (const [language, code] of Object.entries(a.examples)) {
          if (!pattern.code_examples[language] || pattern.code_examples[language] !== code) {
            pattern.code_examples[language] = code;
            addedExamples[language] = code;
          }
        }
        return { patternName: a.patternName, addedExamples };
      });
      await this.saveDatabase(database);
      return results;
    }
  • Input schema definition for add_code_examples tool, specifying the 'additions' array with patternName and examples properties.
    inputSchema: {
      type: "object",
      properties: {
        additions: {
          type: "array",
          items: {
            type: "object",
            properties: {
              patternName: { type: "string", description: "The name of the pattern to add examples to" },
              examples: {
                type: "object",
                additionalProperties: { type: "string" },
                description: "Code examples keyed by programming language"
              },
            },
            required: ["patternName", "examples"],
          },
        },
      },
      required: ["additions"],
    },
  • src/index.ts:196-220 (registration)
    Tool registration in ListToolsRequestSchema handler, defining the tool name 'add_code_examples', description, and input schema.
    {
      name: "add_code_examples",
      description: "Add new code examples to existing patterns",
      inputSchema: {
        type: "object",
        properties: {
          additions: {
            type: "array",
            items: {
              type: "object",
              properties: {
                patternName: { type: "string", description: "The name of the pattern to add examples to" },
                examples: {
                  type: "object",
                  additionalProperties: { type: "string" },
                  description: "Code examples keyed by programming language"
                },
              },
              required: ["patternName", "examples"],
            },
          },
        },
        required: ["additions"],
      },
    },
  • Switch case that dispatches 'add_code_examples' tool calls to patternsManager.addCodeExamples method with proper type casting.
    case "add_code_examples":
      return { content: [{ type: "text", text: JSON.stringify(await patternsManager.addCodeExamples(args.additions as { patternName: string; examples: { [language: string]: string } }[]), null, 2) }] };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'Add new code examples' which implies a write/mutation operation, but doesn't cover permissions, side effects, error handling, or response format. For a tool that modifies data without annotation coverage, this leaves significant behavioral gaps unaddressed.

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 with no wasted words. It's front-loaded with the core action and resource, making it immediately understandable. Every word earns its place in conveying the essential purpose.

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 (modifying existing patterns with structured inputs), lack of annotations, no output schema, and 0% schema description coverage, the description is insufficient. It doesn't explain what happens on success/failure, how examples are merged, or provide any context about the system's patterns and examples model.

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 0%, so the description must compensate. It mentions 'code examples' and 'patterns' which aligns with the 'additions' parameter structure, but doesn't explain the semantics of 'patternName' or how 'examples' should be structured (e.g., language-keyed strings). The description adds minimal context beyond the schema's property names.

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 action ('Add new code examples') and target resource ('to existing patterns'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'create_patterns' or 'delete_code_examples', which would require more precise language about scope and relationship to those operations.

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 'create_patterns' (for new patterns) or 'delete_code_examples'. It mentions 'existing patterns' which implies a prerequisite but doesn't state it explicitly, and offers no context about appropriate scenarios or exclusions.

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/nicholasrubright/MCPatterns'

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