Skip to main content
Glama
brave

Brave Search MCP Server

Official

brave_image_search

Search for images using the Brave Search API to find pictures of people, places, things, graphic design ideas, and art inspiration.

Instructions

Performs an image search using the Brave Search API. Helpful for when you need pictures of people, places, things, graphic design ideas, art inspiration, and more. When relaying results in a markdown environment, it may be helpful to include images in the results (e.g., ![image.title](image.properties.url)).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of results (1-200, default 50). Combine this parameter with `offset` to paginate search results.
countryNoSearch query country, where the results come from. The country string is limited to 2 character country codes of supported countries.US
queryYesThe user's search query. Query cannot be empty. Limited to 400 characters and 50 words.
safesearchNoFilters search results for adult content. The following values are supported: 'off' - No filtering. 'strict' - Drops all adult content from search results.strict
search_langNoSearch language preference. The 2 or more character language code for which the search results are provided.en
spellcheckNoWhether to spellcheck provided query.

Implementation Reference

  • The main handler function that executes the Brave image search: issues API request, simplifies results, validates output, and returns structured content or error.
    export const execute = async (params: QueryParams) => { const response = await API.issueRequest<'images'>('images', params); const items = response.results.map(simplifySchemaForLLM).filter((o) => o !== null); const structuredContent = OutputSchema.safeParse({ type: 'object', items, count: items.length, might_be_offensive: response.extra.might_be_offensive, }); const payload = structuredContent.success ? structuredContent.data : structuredContent.error.flatten(); return { content: [{ type: 'text', text: JSON.stringify(payload) } as TextContent], isError: !structuredContent.success, structuredContent: payload, }; };
  • Registers the 'brave_image_search' tool with the MCP server, including schema, description, and annotations.
    export const register = (mcpServer: McpServer) => { mcpServer.registerTool( name, { title: name, description: description, inputSchema: params.shape, outputSchema: OutputSchema.shape, annotations: annotations, }, execute ); };
  • Zod input schema defining parameters for the brave_image_search tool (query, country, lang, count, safesearch, spellcheck).
    export const params = z.object({ query: z .string() .min(1) .max(400) .refine((str) => str.split(/\s+/).length <= 50, 'Query cannot exceed 50 words') .describe( "The user's search query. Query cannot be empty. Limited to 400 characters and 50 words." ), country: z .string() .default('US') .describe( 'Search query country, where the results come from. The country string is limited to 2 character country codes of supported countries.' ) .optional(), search_lang: z .string() .default('en') .describe( 'Search language preference. The 2 or more character language code for which the search results are provided.' ) .optional(), count: z .number() .int() .min(1) .max(200) .default(50) .describe( 'Number of results (1-200, default 50). Combine this parameter with `offset` to paginate search results.' ) .optional(), safesearch: z .union([z.literal('off'), z.literal('strict')]) .default('strict') .describe( "Filters search results for adult content. The following values are supported: 'off' - No filtering. 'strict' - Drops all adult content from search results." ) .optional(), spellcheck: z .boolean() .default(true) .describe('Whether to spellcheck provided query.') .optional(), });
  • Zod output schemas: SimplifiedImageResultSchema and OutputSchema for validated image search results.
    export const SimplifiedImageResultSchema = z.object({ title: z.string(), url: z.string().url(), page_fetched: z.string().datetime(), confidence: ConfidenceSchema, properties: z.object({ url: z.string().url(), width: z.number().int().positive(), height: z.number().int().positive(), }), }); const OutputSchema = z.object({ type: z.literal('object'), items: z.array(SimplifiedImageResultSchema), count: z.number().int().nonnegative(), might_be_offensive: ExtraSchema.shape.might_be_offensive, }); export default OutputSchema;
  • Helper function to simplify and validate image results for LLM consumption using SimplifiedImageResultSchema.
    function simplifySchemaForLLM( result: ImageResult ): z.infer<typeof SimplifiedImageResultSchema> | null { const parsed = SimplifiedImageResultSchema.safeParse({ title: result.title, url: result.url, page_fetched: result.page_fetched, confidence: result.confidence, properties: { url: result.properties?.url, width: result.properties?.width, height: result.properties?.height, }, }); return parsed.success ? parsed.data : null; }

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

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