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);

Tool Definition Quality

Score is being calculated. Check back soon.

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