list_snippets
Filter and retrieve code snippets by language or tags from a centralized server, streamlining access to reusable code for efficient development.
Instructions
List snippets (can filter by language or tags)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | Filter by specific language | |
| tag | No | Filter by specific tag |
Implementation Reference
- src/index.ts:147-154 (handler)Primary MCP tool handler for list_snippets: wraps engine.ListSnippets and returns JSON-formatted responseprivate async listSnippets(args: any): Promise<GenericMCPResponse> { return { content: [{ type: 'text', text: JSON.stringify(await this.engine.ListSnippets(args), null, 2) }] }; }
- src/engine/local_storage.ts:28-46 (handler)Core implementation of snippet listing with filtering by language, tag, and titleasync ListSnippets(query?: SnippetQuery): Promise<CodeSnippet[]> { // 単一のfilter関数で全フィルタリング条件を処理 return this.snippets.filter(s => { if (query) { if (query.language && s.language.toLowerCase() !== query.language.toLowerCase()) { return false; } if (query.tag && !s.tags.some(t => t.toLowerCase() === query.tag!.toLowerCase())) { return false; } if (query.title && !s.title.toLowerCase().includes(query.title.toLowerCase() || '')) { return false; } } return true; }); }
- src/index.ts:70-85 (registration)Registration of the list_snippets tool in the ListTools responsename: 'list_snippets', description: this.getLocalizedString("tool_list_snippets"), inputSchema: { type: 'object', properties: { language: { type: 'string', description: this.getLocalizedString("snippet_schema_language_filter") }, tag: { type: 'string', description: this.getLocalizedString("snippet_schema_tag_filter") } } } },
- src/index.ts:72-84 (schema)Input schema for list_snippets tool defining optional language and tag parametersinputSchema: { type: 'object', properties: { language: { type: 'string', description: this.getLocalizedString("snippet_schema_language_filter") }, tag: { type: 'string', description: this.getLocalizedString("snippet_schema_tag_filter") } } }
- src/engine/storage_base.ts:3-7 (schema)Type definition for SnippetQuery used in ListSnippets method, matching tool input schemaexport type SnippetQuery = { tag?: string, title?: string, language?: string };