Skip to main content
Glama

search_media

Find similar media in your indexed library by providing a URL or base64 content. Choose search depth from exact matches to comprehensive visual similarity analysis.

Instructions

Search for similar or matching media across the indexed library. Provide a media_url or base64 media to find matches. Tiers: exact (hash match), quick (perceptual hash), perceptual (visual similarity), compositional (scene structure), full (all tiers). Returns results immediately.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
media_urlNoPublic URL of the media to search for
mediaNoBase64-encoded media content to search for
typeNoSearch tier — controls depth vs speed tradeoff. Default: perceptual
tagsNoRestrict search to media with these tags
limitNoMaximum results to return (1-100, default: 20)

Implementation Reference

  • The async handler function that executes the search_media tool. It builds the request body from params (media_url, media, type, tags, limit), constructs the API path with query parameters, makes a POST request to /api/v1/search, and returns the formatted JSON result or error message.
    async (params) => {
      try {
        const body: Record<string, unknown> = {};
        if (params.media_url) body.media_url = params.media_url;
        if (params.media) body.media = params.media;
        if (params.type) body.type = params.type;
        if (params.tags) body.scope = { tags: params.tags };
    
        const queryParams: Record<string, string | undefined> = {};
        if (params.limit) queryParams.limit = String(params.limit);
    
        const path =
          "/api/v1/search" +
          (Object.keys(queryParams).length
            ? "?" +
              new URLSearchParams(
                Object.fromEntries(
                  Object.entries(queryParams).filter(
                    (e): e is [string, string] => e[1] !== undefined,
                  ),
                ),
              ).toString()
            : "");
    
        const result = await api.post(path, body);
        return {
          content: [
            { type: "text" as const, text: JSON.stringify(result, null, 2) },
          ],
        };
      } catch (err) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error: ${err instanceof Error ? err.message : String(err)}`,
            },
          ],
          isError: true as const,
        };
      }
    },
  • Zod schema defining the input validation for search_media tool parameters: media_url (optional URL), media (optional base64), type (enum with 5 search tiers), tags (optional string array), and limit (optional int 1-100).
      media_url: z
        .string()
        .url()
        .optional()
        .describe("Public URL of the media to search for"),
      media: z
        .string()
        .optional()
        .describe("Base64-encoded media content to search for"),
      type: z
        .enum(["exact", "quick", "perceptual", "compositional", "full"])
        .optional()
        .describe("Search tier — controls depth vs speed tradeoff. Default: perceptual"),
      tags: z
        .array(z.string())
        .optional()
        .describe("Restrict search to media with these tags"),
      limit: z
        .number()
        .int()
        .min(1)
        .max(100)
        .optional()
        .describe("Maximum results to return (1-100, default: 20)"),
    },
  • The register function that registers the search_media tool with the MCP server, including the tool name, description, input schema, and handler callback.
    export function register(server: McpServer, api: ApiClient): void {
      server.tool(
        "search_media",
        "Search for similar or matching media across the indexed library. " +
          "Provide a media_url or base64 media to find matches. " +
          "Tiers: exact (hash match), quick (perceptual hash), perceptual (visual similarity), " +
          "compositional (scene structure), full (all tiers). Returns results immediately.",
        {
          media_url: z
            .string()
            .url()
            .optional()
            .describe("Public URL of the media to search for"),
          media: z
            .string()
            .optional()
            .describe("Base64-encoded media content to search for"),
          type: z
            .enum(["exact", "quick", "perceptual", "compositional", "full"])
            .optional()
            .describe("Search tier — controls depth vs speed tradeoff. Default: perceptual"),
          tags: z
            .array(z.string())
            .optional()
            .describe("Restrict search to media with these tags"),
          limit: z
            .number()
            .int()
            .min(1)
            .max(100)
            .optional()
            .describe("Maximum results to return (1-100, default: 20)"),
        },
        async (params) => {
          try {
            const body: Record<string, unknown> = {};
            if (params.media_url) body.media_url = params.media_url;
            if (params.media) body.media = params.media;
            if (params.type) body.type = params.type;
            if (params.tags) body.scope = { tags: params.tags };
    
            const queryParams: Record<string, string | undefined> = {};
            if (params.limit) queryParams.limit = String(params.limit);
    
            const path =
              "/api/v1/search" +
              (Object.keys(queryParams).length
                ? "?" +
                  new URLSearchParams(
                    Object.fromEntries(
                      Object.entries(queryParams).filter(
                        (e): e is [string, string] => e[1] !== undefined,
                      ),
                    ),
                  ).toString()
                : "");
    
            const result = await api.post(path, body);
            return {
              content: [
                { type: "text" as const, text: JSON.stringify(result, null, 2) },
              ],
            };
          } catch (err) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error: ${err instanceof Error ? err.message : String(err)}`,
                },
              ],
              isError: true as const,
            };
          }
        },
      );
    }
  • src/index.ts:10-10 (registration)
    Import statement for the search_media register function from tools/search-media.js.
    import { register as searchMedia } from "./tools/search-media.js";
  • src/index.ts:50-50 (registration)
    Registration call that invokes searchMedia(server, api) to register the search_media tool with the MCP server.
    searchMedia(server, api);
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds value by explaining the search tiers (e.g., 'exact (hash match), quick (perceptual hash)') and noting 'Returns results immediately,' which hints at real-time behavior. However, it lacks details on permissions, rate limits, error handling, or what the results look like, leaving gaps for a mutation-free but complex search tool.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded, starting with the core purpose. Sentences are efficient, with no wasted words, though the list of tiers could be slightly condensed. Overall, it's well-structured and concise for the tool's complexity.

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

Completeness3/5

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

Given no annotations and no output schema, the description provides adequate context for a search tool but has gaps. It covers the purpose and tiers well, but lacks details on result format, error cases, or integration with siblings. For a 5-parameter tool with rich schema but no output info, it's minimally complete but could benefit from more behavioral or output guidance.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal semantics by mentioning 'media_url or base64 media' and listing the search tiers, but this largely repeats schema info. No additional syntax or format details are provided beyond what the schema covers, meeting the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('Search for similar or matching media') and resource ('across the indexed library'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'list_media' or 'get_media' beyond mentioning search tiers, which could help with sibling distinction.

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

Usage Guidelines3/5

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

The description implies when to use this tool by stating 'Provide a media_url or base64 media to find matches,' suggesting it's for finding similar media rather than listing or retrieving specific media. However, it doesn't explicitly contrast with alternatives like 'list_media' or 'get_media,' nor does it provide exclusions or prerequisites, leaving usage context somewhat implied rather than explicit.

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/sidearmDRM/mcp-server'

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