get_species_observations
Retrieve recent bird sightings for a specific species in any region using eBird data, with options to filter by date range, location type, and observation status.
Instructions
Get recent observations of a specific species in a region.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region_code | Yes | Country, subnational1, subnational2, or location code | |
| species_code | Yes | eBird species code (e.g., 'cangoo' for Canada Goose, 'barswa' for Barn Swallow) | |
| back | No | Number of days back to fetch | |
| hotspot | No | Only fetch from hotspots | |
| include_provisional | No | Include unreviewed observations | |
| max_results | No | Maximum observations to return | |
| spp_locale | No | Language for common names | en |
Implementation Reference
- src/index.ts:111-122 (handler)The handler function that implements the core logic for the 'get_species_observations' tool. It prepares query parameters, makes an API request to the eBird endpoint for recent species observations in a region, and returns the result as formatted JSON text content.async (args) => { const params: Record<string, string | number | boolean> = { back: args.back, hotspot: args.hotspot, includeProvisional: args.include_provisional, sppLocale: args.spp_locale, }; if (args.max_results) params.maxResults = args.max_results; const result = await makeRequest(`/data/obs/${args.region_code}/recent/${args.species_code}`, params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }
- src/index.ts:102-110 (schema)Zod schema defining the input parameters and their validation rules, descriptions, and defaults for the 'get_species_observations' tool.{ region_code: z.string().describe("Country, subnational1, subnational2, or location code"), species_code: z.string().describe("eBird species code (e.g., 'cangoo' for Canada Goose, 'barswa' for Barn Swallow)"), back: z.number().min(1).max(30).default(14).describe("Number of days back to fetch"), hotspot: z.boolean().default(false).describe("Only fetch from hotspots"), include_provisional: z.boolean().default(false).describe("Include unreviewed observations"), max_results: z.number().min(1).max(10000).optional().describe("Maximum observations to return"), spp_locale: z.string().default("en").describe("Language for common names"), },
- src/index.ts:99-123 (registration)The complete registration of the 'get_species_observations' tool with the McpServer instance using server.tool(), including name, description, input schema, and handler function.server.tool( "get_species_observations", "Get recent observations of a specific species in a region.", { region_code: z.string().describe("Country, subnational1, subnational2, or location code"), species_code: z.string().describe("eBird species code (e.g., 'cangoo' for Canada Goose, 'barswa' for Barn Swallow)"), back: z.number().min(1).max(30).default(14).describe("Number of days back to fetch"), hotspot: z.boolean().default(false).describe("Only fetch from hotspots"), include_provisional: z.boolean().default(false).describe("Include unreviewed observations"), max_results: z.number().min(1).max(10000).optional().describe("Maximum observations to return"), spp_locale: z.string().default("en").describe("Language for common names"), }, async (args) => { const params: Record<string, string | number | boolean> = { back: args.back, hotspot: args.hotspot, includeProvisional: args.include_provisional, sppLocale: args.spp_locale, }; if (args.max_results) params.maxResults = args.max_results; const result = await makeRequest(`/data/obs/${args.region_code}/recent/${args.species_code}`, params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } );
- src/index.ts:19-36 (helper)Shared helper utility function used by the 'get_species_observations' handler (and other tools) to construct and make authenticated HTTP requests to the eBird API, handling URL parameters, authentication, error checking, and JSON parsing.async function makeRequest(endpoint: string, params: Record<string, string | number | boolean> = {}): Promise<unknown> { const url = new URL(`${BASE_URL}${endpoint}`); Object.entries(params).forEach(([key, value]) => { if (value !== undefined && value !== null) { url.searchParams.append(key, String(value)); } }); const response = await fetch(url.toString(), { headers: { "X-eBirdApiToken": API_KEY! }, }); if (!response.ok) { throw new Error(`eBird API error: ${response.status} ${response.statusText}`); } return response.json(); }