Skip to main content
Glama

search_gallery

Read-only

Search AI image prompts using semantic understanding to find visually and conceptually similar results, including image URLs for easy browsing and style picking.

Instructions

Search AI image prompts with semantic understanding — finds visually and conceptually similar results, not just keyword matches. Results include image URLs — render them as markdown images () so users can visually browse and pick styles. Use when users need inspiration, want to explore styles, or say "generate an image" without a specific idea.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoSearch keywords (e.g., "cyberpunk", "product photo", "portrait"). Supports semantic search — natural language descriptions work well. Leave empty to browse by category or get random picks.
categoryNoFilter by category. Available: Photography, Illustration & 3D, Product & Brand, Food & Drink, Poster Design, UI & Graphic
limitNoNumber of results (1-20, default 5)
offsetNoPagination offset
sortByNoSort order when browsing without search query (default: rank)rank

Implementation Reference

  • Main handler function that registers the 'search_gallery' tool on the MCP server. Contains the core logic: 1) If no query/category → return random prompts from local library with stats. 2) If query without category → try semantic search via external API (apiSearchPosts). 3) Falls through to local keyword-based search via searchPrompts (supports category filter). Returns formatted results with markdown image previews.
    export function registerSearchGallery(server: McpServer, config: MeiGenConfig) {
      server.tool(
        'search_gallery',
        'Search AI image prompts with semantic understanding — finds visually and conceptually similar results, not just keyword matches. Results include image URLs — render them as markdown images (![](url)) so users can visually browse and pick styles. Use when users need inspiration, want to explore styles, or say "generate an image" without a specific idea.',
        searchGallerySchema,
        { readOnlyHint: true },
        async ({ query, category, limit, offset, sortBy }) => {
          // No search criteria — return random picks from local library
          if (!query && !category && offset === 0) {
            const random = getRandomPrompts(limit)
            const stats = getLibraryStats()
            const header = `Curated Prompt Library: ${stats.total} trending prompts\nCategories: ${Object.entries(stats.categories).map(([k, v]) => `${k} (${v})`).join(', ')}\n\nHere are ${limit} random picks — show the preview images to the user:\n`
            return {
              content: [{
                type: 'text' as const,
                text: header + formatLocalResults(random),
              }],
            }
          }
    
          // Has query and no category filter → try semantic search via API
          if (query && query.trim() && !category) {
            const apiResults = await apiSearchPosts(config.meigenBaseUrl, query, limit, offset)
            if (apiResults && apiResults.length > 0) {
              const text = `Found ${apiResults.length} results for "${query}" (semantic search):\n\n${formatApiResults(apiResults)}\n\nShow the preview images above to the user so they can visually browse. Use get_inspiration(imageId) to get the full prompt and all images for any entry the user likes.`
              return {
                content: [{
                  type: 'text' as const,
                  text,
                }],
              }
            }
            // API failed or no results — fall through to local search
          }
    
          // Local search (keyword-based): with category filter, or as API fallback
          const results = searchPrompts({ query, category, limit, offset, sortBy })
    
          if (results.length === 0) {
            const suggestion = category
              ? `No results for "${query || ''}" in category "${category}". Try a different keyword or remove the category filter.`
              : `No results for "${query}". Try broader keywords like "portrait", "landscape", "product", "anime".`
            return {
              content: [{
                type: 'text' as const,
                text: suggestion,
              }],
            }
          }
    
          const searchDesc = [
            query ? `"${query}"` : null,
            category ? `category: ${category}` : null,
          ].filter(Boolean).join(', ')
    
          const text = `Found ${results.length} results${searchDesc ? ` for ${searchDesc}` : ''}:\n\n${formatLocalResults(results)}\n\nShow the preview images above to the user so they can visually browse. Use get_inspiration(imageId) to get the full prompt and all images for any entry the user likes.`
    
          return {
            content: [{
              type: 'text' as const,
              text,
            }],
          }
        }
      )
    }
  • Zod schema for the search_gallery tool parameters: query (optional string), category (enum of 6 categories), limit (1-20, default 5), offset (default 0), sortBy (rank/likes/views/date, default rank).
    export const searchGallerySchema = {
      query: z.string().optional()
        .describe('Search keywords (e.g., "cyberpunk", "product photo", "portrait"). Supports semantic search — natural language descriptions work well. Leave empty to browse by category or get random picks.'),
      category: z.enum(['Photography', 'Illustration & 3D', 'Product & Brand', 'Food & Drink', 'Poster Design', 'UI & Graphic']).optional()
        .describe('Filter by category. Available: Photography, Illustration & 3D, Product & Brand, Food & Drink, Poster Design, UI & Graphic'),
      limit: z.number().min(1).max(20).optional().default(5)
        .describe('Number of results (1-20, default 5)'),
      offset: z.number().min(0).optional().default(0)
        .describe('Pagination offset'),
      sortBy: z.enum(['rank', 'likes', 'views', 'date']).optional().default('rank')
        .describe('Sort order when browsing without search query (default: rank)'),
    }
  • src/server.ts:255-270 (registration)
    The tool is registered in createServer() by calling registerSearchGallery(server, config) — part of free features that require no authentication.
    export function createServer() {
      const config = loadConfig()
      const apiClient = new MeiGenApiClient(config)
    
      const server = new McpServer(
        { name: 'meigen', version: '1.3.2' },
        { instructions: SERVER_INSTRUCTIONS },
      )
    
      // Free features (no configuration required)
      registerEnhancePrompt(server)
      registerSearchGallery(server, config)
      registerListModels(server, apiClient, config)
      registerGetInspiration(server, apiClient)
      registerManagePreferences(server)
  • src/server.ts:10-10 (registration)
    Import statement for the registerSearchGallery function from the search-gallery.ts tool module.
    import { registerSearchGallery } from './tools/search-gallery.js'
  • Helper functions formatApiResults and formatLocalResults that format API and local search results into user-facing text with markdown image previews, prompt snippets, stats, and IDs.
    function formatApiResults(results: ApiSearchResult[]): string {
      return results.map((item, i) => {
        // Use text field as prompt, truncate for preview
        const promptText = item.text || ''
        const promptPreview = promptText.length > 150
          ? promptText.slice(0, 150).replace(/\n/g, ' ') + '...'
          : promptText.replace(/\n/g, ' ')
    
        const imageUrl = item.thumbnail_url || (item.media_urls?.[0])
        const author = item.author_display_name || item.author_username || 'Unknown'
        const model = item.model || 'unknown'
    
        const parts = [
          `${i + 1}. by ${author} — ${model}`,
          imageUrl ? `   ![Preview](${imageUrl})` : null,
          `   Prompt: ${promptPreview}`,
          `   Stats: ${item.likes} likes, ${item.views.toLocaleString()} views`,
          `   ID: ${item.id}`,
        ].filter(Boolean)
        return parts.join('\n')
      }).join('\n\n')
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations provide readOnlyHint: true, and the description adds value by explaining results include image URLs, suggests rendering as markdown, and describes behavior with empty query (browse) and semantic search. No contradiction, and it enriches the understanding beyond annotations.

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

Conciseness5/5

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

The description is concise: three sentences front-load the purpose and usage. Every sentence adds value, and there is no redundancy or verbosity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema, the description covers return value (image URLs) and how to present them. It explains semantic search, browsing use case, and provides context for using the tool alongside siblings like generate_image. Complete for an agent to use correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds context for the 'query' parameter (supports natural language, leave empty for browse), which goes beyond the schema's description. This justifies a 4.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description specifies "search" as the verb, "AI image prompts" as the resource, and highlights semantic understanding as the key differentiator from keyword search. It clearly states what the tool does and distinguishes it effectively.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says when to use: when users need inspiration, explore styles, or say 'generate an image' without a specific idea. It implies alternatives like generate_image but does not name them directly, slightly lowering the score.

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

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/jau123/MeiGen-AI-Design-MCP'

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