Skip to main content
Glama

get-similar-images-by-description

Find visually similar images by entering a text description. This tool searches Inspire's image database to return matching results based on your descriptive input.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYesimage description
limitNopagination: limit. set at least 5
offsetYespagination: offset

Implementation Reference

  • The handler function executes the tool logic: searches for posts by text description, fetches post details, downloads images as base64, interleaves them with size limits, and returns content.
    handler: async ({
      description,
      limit,
      offset,
    }: {
      description: string;
      limit: number;
      offset: number;
    }) => {
      const results = (await searchClient.searchPosts({
        searchBy: { case: "textQuery", value: description },
        offset,
        limit,
      })) as SearchImagesResponse;
    
      if (!results) {
        return {
          content: [
            { type: "text" as const, text: "Failed to retrieve similar images" },
          ],
        };
      }
    
      const posts = (await postsClient.getPosts({
        postIds: results.results.map((res) => res.postId),
      })) as GetPostsResponse;
    
      if (!posts) {
        return {
          content: [
            {
              type: "text" as const,
              text: "Failed to retrieve posts for images",
            },
          ],
        };
      }
    
      const postsImages = await Promise.all(
        posts.posts.map(downloadImageAsBase64),
      );
    
      const interleavedContent: (
        | { type: "text"; text: string }
        | { type: "image"; mimeType: string; data: string }
      )[] = [];
    
      const MAX_RESPONSE_SIZE = 1_048_576;
      let currentSize = 0;
    
      for (const imageData of postsImages) {
        const estimatedSize = Buffer.byteLength(imageData.base64, "base64");
    
        if (currentSize + estimatedSize > MAX_RESPONSE_SIZE) break;
    
        interleavedContent.push({
          type: "image" as const,
          data: imageData.base64,
          mimeType: imageData.mimeType,
        });
    
        currentSize += estimatedSize;
      }
    
      return { content: interleavedContent };
    },
  • Zod schema defining input parameters: description (string), limit (number 1-10 default 10), offset (number).
    inputSchema: {
      description: z.string().describe("image description"),
      limit: z
        .number()
        .min(1)
        .max(10)
        .default(10)
        .describe("pagination: limit. set at least 5"),
      offset: z.number().describe("pagination: offset"),
    },
  • Registers the tool with the MCP server using its name, inputSchema, metadata, and handler.
    server.tool(
      getSimilarImagesTool.name,
      getSimilarImagesTool.inputSchema,
      getSimilarImagesTool.metadata,
      getSimilarImagesTool.handler,
    );
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/tech-inspire/mcp-server'

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