Skip to main content
Glama
ngeojiajun

Code Snippet Server

by ngeojiajun

create_snippet

Generate and store code snippets by specifying title, language, code, and optional tags, enabling efficient organization and retrieval of programming examples.

Instructions

Create a snippet (specify title, language, and code)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesCode snippet
languageYesProgramming language
tagsNoSnippet tags
titleYesSnippet title

Implementation Reference

  • The main handler function for the 'create_snippet' tool. It validates input arguments, creates a new CodeSnippet object with an ID, title, language, code, optional tags, and creation timestamp, inserts it into the storage engine, and returns a success message.
    private async createSnippet(args: any): Promise<GenericMCPResponse> {
      if (!args || typeof args.title !== 'string' || typeof args.language !== 'string' || typeof args.code !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid snippet parameters');
      }
    
      const newSnippet: CodeSnippet = {
        id: Date.now().toString(),
        title: args.title,
        language: args.language,
        code: args.code,
        tags: args.tags || [],
        createdAt: new Date().toISOString()
      };
    
      await this.engine.InsertSnippet(newSnippet);
    
      return {
        content: [{
          type: 'text',
          text: this.getLocalizedString("snippet_created", newSnippet.title, newSnippet.id)
        }]
      };
    }
  • The input schema for the 'create_snippet' tool, defining properties for title (string), language (string), code (string), and optional tags (array of strings), with title, language, and code required.
    inputSchema: {
      type: 'object',
      properties: {
        title: { type: 'string', description: this.getLocalizedString("snippet_schema_title") },
        language: { type: 'string', description: this.getLocalizedString("snippet_schema_language") },
        code: { type: 'string', description: this.getLocalizedString("snippet_schema_code") },
        tags: {
          type: 'array',
          items: { type: 'string' },
          description: this.getLocalizedString("snippet_schema_tags")
        }
      },
      required: ['title', 'language', 'code']
    }
  • src/index.ts:51-68 (registration)
    The registration of the 'create_snippet' tool in the ListTools response, including name, localized description, and input schema.
    {
      name: 'create_snippet',
      description: this.getLocalizedString("tool_create_snippet"),
      inputSchema: {
        type: 'object',
        properties: {
          title: { type: 'string', description: this.getLocalizedString("snippet_schema_title") },
          language: { type: 'string', description: this.getLocalizedString("snippet_schema_language") },
          code: { type: 'string', description: this.getLocalizedString("snippet_schema_code") },
          tags: {
            type: 'array',
            items: { type: 'string' },
            description: this.getLocalizedString("snippet_schema_tags")
          }
        },
        required: ['title', 'language', 'code']
      }
    },
  • src/index.ts:105-106 (registration)
    The dispatch case in the CallToolRequest handler that routes 'create_snippet' calls to the createSnippet method.
    case 'create_snippet':
      return await this.createSnippet(request.params.arguments);
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 states the tool creates a snippet but doesn't explain what happens after creation (e.g., where the snippet is stored, if it's private or public, or any side effects like notifications). This leaves significant gaps in understanding the tool's behavior beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the main action ('Create a snippet') and specifies key parameters. It avoids unnecessary words, but could be slightly more structured by explicitly noting optional parameters or usage context.

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 complexity of a creation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like permissions, error handling, or what the tool returns upon success. For a mutation operation, more context is needed to guide effective use by an AI agent.

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 schema description coverage is 100%, so the input schema already documents all parameters (title, language, code, tags) with descriptions. The description adds minimal value by listing required parameters but doesn't provide additional context like format examples or constraints beyond what the schema offers, aligning with the 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 action ('Create a snippet') and specifies the required components ('specify title, language, and code'), which distinguishes it from sibling tools like 'delete_snippet' and 'list_snippets'. However, it doesn't explicitly mention the optional 'tags' parameter, making it slightly less specific than a perfect 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 'list_snippets' or 'delete_snippet'. It lacks context about prerequisites, such as authentication or workspace setup, and doesn't indicate when this tool is appropriate compared to other operations.

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

Related 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/ngeojiajun/mcp-code-snippets'

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