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
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code snippet | |
| language | Yes | Programming language | |
| tags | No | Snippet tags | |
| title | Yes | Snippet title |
Implementation Reference
- src/index.ts:123-145 (handler)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) }] }; }
- src/index.ts:54-67 (schema)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);