introduces support for place search endpoint (#288)

This commit is contained in:
Sampson authored and GitHub committed 2026-04-29 08:16:23 -05:00
1 parent c099abe0f0
commit cb52cbb03b
9 files changed
+616 -6

No files matched your search

+25 -1
View File
@@ -1,6 +1,6 @@
# Brave Search MCP Server
An MCP server implementation that integrates the Brave Search API, providing comprehensive search capabilities including web search, local business search, image search, video search, news search, LLM context, and AI-powered summarization. This project supports both STDIO and HTTP transports, with STDIO as the default mode.
An MCP server implementation that integrates the Brave Search API, providing comprehensive search capabilities including web search, local business search, place search, image search, video search, news search, LLM context, and AI-powered summarization. This project supports both STDIO and HTTP transports, with STDIO as the default mode.
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/brave/brave-search-mcp-server)
@@ -98,6 +98,30 @@ Generates AI-powered summaries from web search results using Brave's summarizati
**Usage:** First perform a web search with `summary: true`, then use the returned summary key with this tool.
### Place Search (`brave_place_search`)
Searches for points of interest (POIs) in a specified geographic area using Brave's Place Search API. Returns rich, structured place data including name, address, opening hours, contact info, ratings, photos, categories, and timezone.
**Parameters:**
- `query` (string, optional): Query string used to refine the POI search (max 400 chars, 50 words). When omitted, returns general points of interest in the supplied area.
- `latitude` (number, optional): Latitude of the search center (-90 to 90). Typically paired with `longitude`.
- `longitude` (number, optional): Longitude of the search center (-180 to 180). Typically paired with `latitude`.
- `location` (string, optional): Location string used as an alternative to `latitude`/`longitude`. For US locations prefer the form `<city> <state> <country name>` (e.g., `san francisco ca united states`); for non-US locations use `<city> <country name>` (e.g., `tokyo japan`).
- `radius` (number, optional): Search radius around the supplied coordinates, in meters. If omitted, the search is performed globally.
- `count` (number, optional): Number of results to return (1-50, default 20).
- `country` (string, optional): Two-letter country code (default `US`).
- `search_lang` (string, optional): Search language (default `en`).
- `ui_lang` (string, optional): UI language (default `en-US`).
- `units` (string, optional): Distance units (`metric` or `imperial`, default `metric`).
- `safesearch` (string, optional): Safe search level (`off`, `moderate`, `strict`, default `strict`).
- `spellcheck` (boolean, optional): Whether to spellcheck the query (default `true`).
- `geoloc` (string, optional): Optional geolocation token used to refine results.
**Optional request headers:**
- `api-version` (string, optional): Brave API version (`YYYY-MM-DD`)
- `accept` (string, optional): Response media type (`application/json` or `*/*`)
- `cache-control` (string, optional): Use `no-cache` to request fresh content
- `user-agent` (string, optional): User agent originating the request
### LLM Context (`brave_llm_context`)
Retrieves pre-extracted web content optimized for AI agents, LLM grounding, and RAG pipelines.
+1 -1
View File
@@ -11,6 +11,7 @@ const typeToPathMap: Record<keyof Endpoints, string> = {
web: '/res/v1/web/search',
summarizer: '/res/v1/summarizer/search',
llmContext: '/res/v1/llm/context',
placeSearch: '/res/v1/local/place_search',
};
const getDefaultRequestHeaders = (): Record<string, string> => {
@@ -43,7 +44,6 @@ const normalizeGoggle = (value: unknown): string | null => {
async function issueRequest<T extends keyof Endpoints>(
endpoint: T,
parameters: Endpoints[T]['params'],
// TODO (Sampson): Implement support for custom request headers (helpful for POIs, etc.)
requestHeaders: Endpoints[T]['requestHeaders'] = {} as Endpoints[T]['requestHeaders']
): Promise<Endpoints[T]['response']> {
// TODO (Sampson): Improve rate-limit logic to support self-throttling and n-keys
+10
View File
@@ -15,6 +15,11 @@ import type {
} from '../tools/local/types.js';
import type { LlmQueryParams, LlmRequestHeaders } from '../tools/llm_context/schemas/input.js';
import type { LlmContextSearchApiResponse } from '../tools/llm_context/schemas/output.js';
import type {
PlaceSearchQueryParams,
PlaceSearchRequestHeaders,
} from '../tools/place_search/schemas/input.js';
import type { PlaceSearchApiResponse } from '../tools/place_search/schemas/output.js';
export interface RateLimitErrorResponse {
type: 'ErrorResponse';
@@ -76,4 +81,9 @@ export type Endpoints = {
response: LlmContextSearchApiResponse;
requestHeaders: LlmRequestHeaders;
};
placeSearch: {
params: PlaceSearchQueryParams;
response: PlaceSearchApiResponse;
requestHeaders: PlaceSearchRequestHeaders;
};
};
+2
View File
@@ -5,6 +5,7 @@ import ImageSearchTool from './images/index.js';
import NewsSearchTool from './news/index.js';
import SummarizerTool from './summarizer/index.js';
import LlmContextTool from './llm_context/index.js';
import PlaceSearchTool from './place_search/index.js';
export default {
WebSearchTool,
@@ -14,4 +15,5 @@ export default {
NewsSearchTool,
SummarizerTool,
LlmContextTool,
PlaceSearchTool,
};
+2 -2
View File
@@ -96,8 +96,8 @@ export interface LocationResult extends Result {
results?: LocationWebResult;
/** IANA timezone identifier. */
timezone?: string;
/** The utc offset of the timezone. */
timezone_offset?: string;
/** The UTC offset of the timezone, in minutes. */
timezone_offset?: number;
}
interface Thumbnail {
+75
View File
@@ -0,0 +1,75 @@
import type { TextContent, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
import { z } from 'zod';
import API from '../../BraveAPI/index.js';
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import {
RequestParamsSchema,
RequestHeadersSchema,
PlaceSearchInputSchema,
type PlaceSearchInput as QueryParams,
} from './schemas/input.js';
import { PlaceSearchApiResponseSchema } from './schemas/output.js';
export const name = 'brave_place_search';
export const annotations: ToolAnnotations = {
title: 'Brave Place Search',
openWorldHint: true,
};
export const description = `
Searches for points of interest (POIs) in a specified geographic area using Brave's Place Search API. Each result includes rich, structured data such as the place's name, URL, postal address, opening hours, contact info, ratings, photos, categories, and timezone.
When to use:
- Finding places near a set of coordinates or a named location (e.g. "coffee shops near me", "bookstores in Paris")
- Browsing general points of interest in an area when no query is supplied
- Building a place-finding experience that needs structured business data (hours, ratings, etc.)
- Augmenting an answer with the location's address, phone number, or rating
Provide a search area via 'latitude' + 'longitude' or a 'location' string (or both). When neither is provided, a 'query' is expected. Use 'count' to keep responses small (max 50, default 20).
For US locations the recommended 'location' format is '<city> <state> <country name>' (e.g. 'san francisco ca united states'); for non-US locations use '<city> <country name>' (e.g. 'tokyo japan').
`.trim();
export const execute = async (params: QueryParams) => {
const parsedParams = RequestParamsSchema.parse(params);
const parsedHeaders = RequestHeadersSchema.parse(params);
const response = await API.issueRequest<'placeSearch'>(
'placeSearch',
parsedParams,
parsedHeaders
);
const parsed = PlaceSearchApiResponseSchema.safeParse(response);
const payload = parsed.success ? parsed.data : response;
return {
content: [{ type: 'text', text: JSON.stringify(payload) } as TextContent],
isError: false,
structuredContent: payload,
};
};
export const register = (mcpServer: McpServer) => {
mcpServer.registerTool(
name,
{
title: name,
description: description,
inputSchema: PlaceSearchInputSchema.shape,
outputSchema: PlaceSearchApiResponseSchema.shape,
annotations: annotations,
},
execute
);
};
export default {
name,
description,
annotations,
inputSchema: PlaceSearchInputSchema.shape,
outputSchema: PlaceSearchApiResponseSchema.shape,
execute,
register,
};
+254
View File
@@ -0,0 +1,254 @@
import { z } from 'zod';
/**
* Keep up-to-date with documentation:
* https://api-dashboard.search.brave.com/api-reference/web/place_search
*/
const CountryCodesSchema = z.enum([
'AR',
'AU',
'AT',
'BE',
'BR',
'CA',
'CL',
'DK',
'FI',
'FR',
'DE',
'GR',
'HK',
'IN',
'ID',
'IT',
'JP',
'KR',
'MY',
'MX',
'NL',
'NZ',
'NO',
'CN',
'PL',
'PT',
'PH',
'RU',
'SA',
'ZA',
'ES',
'SE',
'CH',
'TW',
'TR',
'GB',
'US',
]);
const SearchLangCodesSchema = z.enum([
'ar',
'eu',
'bn',
'bg',
'ca',
'zh-hans',
'zh-hant',
'hr',
'cs',
'da',
'nl',
'en',
'en-gb',
'et',
'fi',
'fr',
'gl',
'de',
'el',
'gu',
'he',
'hi',
'hu',
'is',
'it',
'jp',
'kn',
'ko',
'lv',
'lt',
'ms',
'ml',
'mr',
'nb',
'pl',
'pt-br',
'pt-pt',
'pa',
'ro',
'ru',
'sr',
'sk',
'sl',
'es',
'sv',
'ta',
'te',
'th',
'tr',
'uk',
'vi',
]);
const UiLangCodesSchema = z.enum([
'es-AR',
'en-AU',
'de-AT',
'nl-BE',
'fr-BE',
'pt-BR',
'en-CA',
'fr-CA',
'es-CL',
'da-DK',
'fi-FI',
'fr-FR',
'de-DE',
'zh-HK',
'en-IN',
'en-ID',
'it-IT',
'ja-JP',
'ko-KR',
'en-MY',
'es-MX',
'nl-NL',
'en-NZ',
'no-NO',
'zh-CN',
'pl-PL',
'en-PH',
'ru-RU',
'en-ZA',
'es-ES',
'sv-SE',
'fr-CH',
'de-CH',
'zh-TW',
'tr-TR',
'en-GB',
'en-US',
'es-US',
]);
export const RequestParamsSchema = z.object({
query: z
.string()
.trim()
.max(400)
.refine(
(str) => str.length === 0 || str.split(/\s+/).length <= 50,
'Query cannot exceed 50 words'
)
.transform((str) => (str.length === 0 ? undefined : str))
.describe(
'Query string to search for points of interest in an area. If no query is provided, the endpoint will return general points of interest in the given area.'
)
.optional(),
radius: z
.number()
.min(0)
.describe(
'Search radius around the supplied coordinates, in meters. If omitted, the search is performed globally.'
)
.optional(),
count: z
.number()
.int()
.min(1)
.max(50)
.describe('Number of results to return. Maximum is 50. Default is 20.')
.optional(),
latitude: z
.number()
.min(-90)
.max(90)
.describe(
'Latitude of the geographical coordinates around which to search, in degrees (-90 to 90). Typically paired with `longitude`.'
)
.optional(),
longitude: z
.number()
.min(-180)
.max(180)
.describe(
'Longitude of the geographical coordinates around which to search, in degrees (-180 to 180). Typically paired with `latitude`.'
)
.optional(),
location: z
.string()
.trim()
.min(1)
.describe(
"Location string to search around, used as an alternative to `latitude` and `longitude`. For US locations prefer the form '<city> <state> <country name>' (e.g. 'san francisco ca united states'); for non-US locations use '<city> <country name>' (e.g. 'tokyo japan'). No commas or special characters needed; capitalization does not matter."
)
.optional(),
country: CountryCodesSchema.describe(
"Two-letter country code (ISO 3166-1 alpha-2) used to scope the search. Defaults to 'US'."
).optional(),
search_lang: SearchLangCodesSchema.describe(
"Language for the search results. Defaults to 'en'."
).optional(),
ui_lang: UiLangCodesSchema.describe(
"User interface language for the response, usually of the form '<language>-<region>'. Defaults to 'en-US'."
).optional(),
units: z
.enum(['metric', 'imperial'])
.describe("Units of measurement for distance values. Defaults to 'metric'.")
.optional(),
safesearch: z
.enum(['off', 'moderate', 'strict'])
.describe(
"Safe search level for the query results. 'off' - No filtering. 'moderate' - Filter out explicit content. 'strict' - Filter out explicit and suggestive content. Defaults to 'strict'."
)
.optional(),
spellcheck: z
.boolean()
.describe('Whether to apply spellcheck before executing the search. Defaults to true.')
.optional(),
geoloc: z.string().describe('Optional geolocation token used to refine results.').optional(),
});
export const RequestHeadersSchema = z.object({
'api-version': z
.string()
.regex(/^\d{4}-\d{2}-\d{2}$/)
.describe(
'The API version to use. This is denoted by the format YYYY-MM-DD. Default is the latest that is available. Read more about API versioning at https://api-dashboard.search.brave.com/documentation/guides/versioning.'
)
.optional(),
accept: z
.enum(['application/json', '*/*'])
.describe('The default supported media type is application/json.')
.optional(),
'cache-control': z
.literal('no-cache')
.describe(
'Brave Search will return cached content by default. To prevent caching set the Cache-Control header to no-cache. This is currently done as best effort.'
)
.optional(),
'user-agent': z
.string()
.describe(
'The user agent originating the request. Brave Search can utilize the user agent to provide a different experience depending on the device as described by the string. The user agent should follow the commonly used browser agent strings on each platform. For more information on curating user agents, see RFC 9110.'
)
.optional(),
});
export const PlaceSearchInputSchema = z.object({
...RequestParamsSchema.shape,
...RequestHeadersSchema.shape,
});
export type PlaceSearchInput = z.input<typeof PlaceSearchInputSchema>;
export type PlaceSearchQueryParams = z.infer<typeof RequestParamsSchema>;
export type PlaceSearchRequestHeaders = z.infer<typeof RequestHeadersSchema>;
+245
View File
@@ -0,0 +1,245 @@
import { z } from 'zod';
/**
* Keep up to date with documentation:
* https://api-dashboard.search.brave.com/api-reference/web/place_search#responses
*/
const ThumbnailSchema = z.looseObject({
src: z.string().describe('The served URL of the picture thumbnail.').optional(),
original: z.string().describe('The original URL of the image.').optional(),
});
const PostalAddressSchema = z.looseObject({
type: z.literal('PostalAddress').optional(),
country: z.string().describe('The country associated with the location.').optional(),
postalCode: z.string().describe('The postal code associated with the location.').optional(),
streetAddress: z.string().describe('The street address associated with the location.').optional(),
addressRegion: z
.string()
.describe('The region associated with the location. Usually a state.')
.optional(),
addressLocality: z
.string()
.describe('The address locality or subregion associated with the location.')
.optional(),
displayAddress: z.string().describe('The displayed address string.').optional(),
});
const DayOpeningHoursSchema = z.looseObject({
abbr_name: z.string().describe('Short name of the day of the week (e.g. "Mon").').optional(),
full_name: z.string().describe('Full name of the day of the week (e.g. "Monday").').optional(),
opens: z.string().describe('Opening time in 24h format (e.g. "09:00").').optional(),
closes: z.string().describe('Closing time in 24h format (e.g. "17:00").').optional(),
});
const OpeningHoursSchema = z.looseObject({
current_day: z
.array(DayOpeningHoursSchema)
.describe(
'Opening hours for the current day. May contain multiple entries when the location closes and reopens during the day.'
)
.optional(),
days: z
.array(z.union([DayOpeningHoursSchema, z.array(DayOpeningHoursSchema)]))
.describe(
'Opening hours for the rest of the week. Each entry may itself be either a single day-hours object or an array of day-hours objects (when a day has multiple open/close intervals).'
)
.optional(),
});
const ContactSchema = z.looseObject({
email: z.string().describe('Contact email for the business.').optional(),
telephone: z.string().describe('Contact telephone number for the business.').optional(),
});
const DistanceSchema = z.looseObject({
value: z.number().describe('The quantity of the unit.'),
units: z.string().describe('The name of the unit associated with the quantity.'),
});
const ProfileSchema = z.looseObject({
type: z.string().optional(),
name: z.string().optional(),
long_name: z.string().optional(),
url: z.string().optional(),
img: z.string().optional(),
});
const RatingSchema = z.looseObject({
ratingValue: z.number().describe('The current value of the rating.').optional(),
bestRating: z.number().describe('Highest possible rating value.').optional(),
reviewCount: z.number().describe('Number of reviews backing the rating.').optional(),
profile: ProfileSchema.optional(),
is_tripadvisor: z
.boolean()
.describe('Whether the rating originates from Tripadvisor.')
.optional(),
});
const ReviewSchema = z.looseObject({
title: z.string().describe('The title of the review.'),
description: z.string().describe('A description seen in the review.'),
date: z.string().describe('The date when the review was published.'),
rating: RatingSchema.optional(),
author: ProfileSchema.optional(),
});
const ReviewsSchema = z.looseObject({
results: z
.array(ReviewSchema)
.describe('A list of trip advisor reviews for the entity.')
.optional(),
viewMoreUrl: z
.string()
.describe('A URL to a web page where more information on the result can be seen.')
.optional(),
reviews_in_foreign_language: z
.boolean()
.describe('Any reviews available in a foreign language.')
.optional(),
});
const PicturesSchema = z.looseObject({
viewMoreUrl: z.string().describe('URL where additional pictures can be viewed.').optional(),
results: z.array(ThumbnailSchema).describe('Thumbnail entries for the location.').optional(),
});
const ActionSchema = z.looseObject({
type: z.string().describe('The type representing the action.'),
url: z.string().describe('A URL representing the action to be taken.'),
});
const MetaUrlSchema = z.looseObject({
scheme: z.string().describe('The protocol scheme extracted from the URL.'),
netloc: z.string().describe('The network location part extracted from the URL.'),
hostname: z.string().describe('The lowercased domain name extracted from the URL.').optional(),
favicon: z.string().describe('The favicon used for the URL.').optional(),
path: z
.string()
.describe('The hierarchical path of the URL useful as a display string.')
.optional(),
});
const ResultsSchema = z.looseObject({
title: z.string().describe('The display title of the location.'),
url: z.string().describe('Primary URL associated with the location.'),
is_source_local: z.boolean().optional(),
is_source_both: z.boolean().optional(),
description: z
.string()
.describe('Short description of the location (e.g. "Plaza", "Theater").')
.optional(),
page_age: z.string().describe('The age of the page as a date string.').optional(),
page_fetched: z
.string()
.describe('The date the page was last fetched as a date string.')
.optional(),
fetched_content_timestamp: z
.number()
.describe('The timestamp of the content when it was fetched.')
.optional(),
profile: ProfileSchema.optional(),
language: z.string().describe('The language of the page.').optional(),
family_friendly: z.boolean().optional(),
meta_url: MetaUrlSchema.optional(),
});
const ResultSchema = z.looseObject({
title: z.string().describe('The display title of the location.'),
url: z.string().describe('Primary URL associated with the location.'),
is_source_local: z.boolean().optional(),
is_source_both: z.boolean().optional(),
description: z
.string()
.describe('Short description of the location (e.g. "Plaza", "Theater").')
.optional(),
page_age: z.string().describe('The age of the page as a date string.').optional(),
page_fetched: z
.string()
.describe('The date the page was last fetched as a date string.')
.optional(),
fetched_content_timestamp: z
.number()
.describe('The timestamp of the content when it was fetched.')
.optional(),
profile: ProfileSchema.optional(),
language: z.string().describe('The language of the page.').optional(),
family_friendly: z.boolean().optional(),
type: z.literal('location_result').describe('Result type identifier.').optional(),
provider_url: z
.string()
.describe('URL of the upstream provider for this result. May be an empty string.')
.optional(),
coordinates: z
.array(z.number())
.describe('Latitude/longitude pair for the location, when available.')
.optional(),
zoom_level: z.number().describe('Suggested zoom level when displaying on a map.').optional(),
thumbnail: ThumbnailSchema.optional(),
postal_address: PostalAddressSchema.optional(),
opening_hours: OpeningHoursSchema.optional(),
contact: ContactSchema.optional(),
price_range: z
.string()
.describe('Price classification string for the business (e.g. "$", "$$").')
.optional(),
rating: RatingSchema.optional(),
distance: DistanceSchema.optional(),
profiles: z
.array(ProfileSchema)
.describe('External profiles (e.g. data providers) associated with the result.')
.optional(),
reviews: ReviewsSchema.optional(),
pictures: PicturesSchema.optional(),
action: ActionSchema.optional(),
serves_cuisine: z.array(z.string()).describe('List of cuisine categories served.').optional(),
categories: z.array(z.string()).describe('List of category labels.').optional(),
icon_category: z.string().describe('Suggested icon category (e.g. "cafe").').optional(),
timezone: z.string().describe('IANA timezone identifier for the location.').optional(),
timezone_offset: z
.number()
.describe("UTC offset of the location's timezone, in minutes.")
.optional(),
id: z
.string()
.describe(
'Temporary identifier for the location, valid for ~8 hours. Can be used with brave_local_search-style endpoints to fetch additional information.'
)
.optional(),
results: z.array(ResultsSchema).describe('Web results related to this location.').optional(),
});
const QuerySchema = z.looseObject({
original: z
.string()
.describe('The original query string as supplied by the caller (may be empty).'),
altered: z
.string()
.describe('The altered query string as supplied by the caller (may be empty).')
.optional(),
spellcheck_off: z.boolean().optional(),
show_strict_warning: z.boolean().optional(),
});
const LocationSchema = z.looseObject({
coordinates: z.array(z.number()).describe('Latitude/longitude of the resolved search area.'),
name: z.string().describe('Human-readable name of the resolved search area.').optional(),
country: z.string().describe('ISO country code for the resolved search area.').optional(),
});
export const PlaceSearchApiResponseSchema = z.looseObject({
type: z
.literal('locations')
.describe('Top-level response discriminator. Always "locations" for Place Search.'),
query: QuerySchema.optional(),
results: z
.array(ResultSchema)
.describe('Array of points-of-interest matching the search.')
.optional(),
location: LocationSchema.describe(
'The resolved search-area metadata, when available.'
).optional(),
});
export type PlaceSearchApiResponse = z.infer<typeof PlaceSearchApiResponseSchema>;
+2 -2
View File
@@ -445,8 +445,8 @@ interface LocationResult extends Result {
results?: LocationWebResult;
/** IANA timezone identifier. */
timezone?: string;
/** The utc offset of the timezone. */
timezone_offset?: string;
/** The UTC offset of the timezone, in minutes from UTC. */
timezone_offset?: number;
}
interface LocationDescription {