Skip to main content
Glama
mattjegan

eBird MCP Server

by mattjegan

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
NameRequiredDescriptionDefault
region_codeYesCountry, subnational1, subnational2, or location code
species_codeYeseBird species code (e.g., 'cangoo' for Canada Goose, 'barswa' for Barn Swallow)
backNoNumber of days back to fetch
hotspotNoOnly fetch from hotspots
include_provisionalNoInclude unreviewed observations
max_resultsNoMaximum observations to return
spp_localeNoLanguage for common namesen

Implementation Reference

  • 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) }] };
    }
  • 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) }] };
      }
    );
  • 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();
    }

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/mattjegan/ebird-mcp'

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