Skip to main content
Glama

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
NameRequiredDescriptionDefault
languageNoFilter by specific language
tagNoFilter by specific tag

Implementation Reference

  • Primary MCP tool handler for list_snippets: wraps engine.ListSnippets and returns JSON-formatted response
    private async listSnippets(args: any): Promise<GenericMCPResponse> { return { content: [{ type: 'text', text: JSON.stringify(await this.engine.ListSnippets(args), null, 2) }] }; }
  • Core implementation of snippet listing with filtering by language, tag, and title
    async 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 response
    name: '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") } } } },
  • Input schema for list_snippets tool defining optional language and tag parameters
    inputSchema: { type: 'object', properties: { language: { type: 'string', description: this.getLocalizedString("snippet_schema_language_filter") }, tag: { type: 'string', description: this.getLocalizedString("snippet_schema_tag_filter") } } }
  • Type definition for SnippetQuery used in ListSnippets method, matching tool input schema
    export type SnippetQuery = { tag?: string, title?: string, language?: string };

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