Skip to main content
Glama
zachegner

EPA Envirofacts MCP Server

by zachegner

search_facilities_tool

Search EPA-regulated facilities by name, location, or industry code to identify environmental compliance data and program participation for analysis.

Instructions

Search for EPA-regulated facilities using various filters.

Search for facilities in the EPA's Facility Registry Service using facility name, NAICS code, state, ZIP code, or city. At least one search parameter must be provided.

Args: facility_name: Partial or full facility name (uses contains matching) naics_code: NAICS industry code state: Two-letter state code (e.g., 'NY', 'CA') zip_code: 5-digit ZIP code city: City name limit: Maximum results to return (default: 100)

Returns: List of facilities with registry ID, name, address, coordinates, active programs, industry codes, and status information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
facility_nameNo
naics_codeNo
stateNo
zip_codeNo
cityNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler function `search_facilities_tool` that wraps the core search logic.
    async def search_facilities_tool(
        facility_name: Optional[str] = None,
        naics_code: Optional[str] = None,
        state: Optional[str] = None,
        zip_code: Optional[str] = None,
        city: Optional[str] = None,
        limit: int = 100
    ) -> List[FacilityInfo]:
        """Search for EPA-regulated facilities using various filters.
        
        Search for facilities in the EPA's Facility Registry Service using facility name,
        NAICS code, state, ZIP code, or city. At least one search parameter must be provided.
        
        Args:
            facility_name: Partial or full facility name (uses contains matching)
            naics_code: NAICS industry code
            state: Two-letter state code (e.g., 'NY', 'CA')
            zip_code: 5-digit ZIP code
            city: City name
            limit: Maximum results to return (default: 100)
            
        Returns:
            List of facilities with registry ID, name, address, coordinates,
            active programs, industry codes, and status information
        """
        return await search_facilities(
            facility_name=facility_name,
            naics_code=naics_code,
            state=state,
            zip_code=zip_code,
            city=city,
            limit=limit
        )
  • Pydantic `BaseModel` defining the structure of `FacilityInfo` returned by the tool.
    class FacilityInfo(BaseModel):
        """Information about an EPA-regulated facility."""
        
        registry_id: str = Field(..., description="FRS Registry ID")
        name: str = Field(..., description="Facility name")
        address: Optional[str] = Field(None, description="Facility address")
        city: Optional[str] = Field(None, description="City")
        state: Optional[str] = Field(None, description="State abbreviation")
        zip_code: Optional[str] = Field(None, description="ZIP code")
        coordinates: Optional[Coordinates] = Field(None, description="Facility coordinates")
        programs: List[FacilityType] = Field(default_factory=list, description="Active EPA programs")
        naics_code: Optional[str] = Field(None, description="NAICS industry code")
        naics_description: Optional[str] = Field(None, description="NAICS industry description")
        distance_miles: Optional[float] = Field(None, ge=0, description="Distance from search center in miles")
        status: Optional[str] = Field(None, description="Facility status")
        
        def __str__(self) -> str:
            return f"{self.name} ({self.registry_id})"
  • The `register_tool` function that defines and registers the `search_facilities_tool` handler with the FastMCP instance.
    def register_tool(mcp: FastMCP):
        """Register the search facilities tool with FastMCP.
        
        Args:
            mcp: FastMCP instance
        """
        @mcp.tool()
        async def search_facilities_tool(
            facility_name: Optional[str] = None,
            naics_code: Optional[str] = None,
            state: Optional[str] = None,
            zip_code: Optional[str] = None,
            city: Optional[str] = None,
            limit: int = 100
        ) -> List[FacilityInfo]:
            """Search for EPA-regulated facilities using various filters.
            
            Search for facilities in the EPA's Facility Registry Service using facility name,
            NAICS code, state, ZIP code, or city. At least one search parameter must be provided.
            
            Args:
                facility_name: Partial or full facility name (uses contains matching)
                naics_code: NAICS industry code
                state: Two-letter state code (e.g., 'NY', 'CA')
                zip_code: 5-digit ZIP code
                city: City name
                limit: Maximum results to return (default: 100)
                
            Returns:
                List of facilities with registry ID, name, address, coordinates,
                active programs, industry codes, and status information
            """
            return await search_facilities(
                facility_name=facility_name,
                naics_code=naics_code,
                state=state,
                zip_code=zip_code,
                city=city,
                limit=limit
            )
  • server.py:95-98 (registration)
    Invocation of tool registration functions, including `register_search_tool(mcp)` which registers the search_facilities_tool.
    register_tool(mcp)
    register_search_tool(mcp)
    register_compliance_tool(mcp)
    register_chemical_tool(mcp)
  • Core helper function `search_facilities` that performs input validation and queries the FRSClient API.
    async def search_facilities(
        facility_name: Optional[str] = None,
        naics_code: Optional[str] = None,
        state: Optional[str] = None,
        zip_code: Optional[str] = None,
        city: Optional[str] = None,
        limit: int = 100
    ) -> List[FacilityInfo]:
        """Search for EPA-regulated facilities using various filters.
        
        This tool allows searching for facilities in the EPA's Facility Registry Service (FRS)
        using facility name, NAICS code, state, ZIP code, or city. At least one search parameter
        must be provided.
        
        Args:
            facility_name: Partial or full facility name (uses contains matching)
            naics_code: NAICS industry code
            state: Two-letter state code (e.g., 'NY', 'CA')
            zip_code: 5-digit ZIP code
            city: City name
            limit: Maximum results to return (default: 100, max: 1000)
        
        Returns:
            List of FacilityInfo objects containing:
            - Registry ID and facility name
            - Address and location information
            - Active EPA programs (TRI, RCRA, etc.)
            - Industry codes and descriptions
            - Facility status
        
        Raises:
            ValueError: If no search parameters provided or invalid parameter format
            Exception: If EPA API query fails
        
        Example:
            >>> facilities = await search_facilities(facility_name="Chemical", state="NY")
            >>> print(f"Found {len(facilities)} facilities")
            >>> for facility in facilities[:3]:
            ...     print(f"{facility.name} - {facility.city}, {facility.state}")
        """
        # Validate input parameters
        if not any([facility_name, naics_code, state, zip_code, city]):
            raise ValueError("At least one search parameter must be provided")
        
        if not (1 <= limit <= 1000):
            raise ValueError("Limit must be between 1 and 1000")
        
        # Clean and validate individual parameters
        if facility_name:
            facility_name = facility_name.strip()
            if not facility_name:
                raise ValueError("Facility name cannot be empty")
        
        if naics_code:
            naics_code = naics_code.strip()
            if not naics_code:
                raise ValueError("NAICS code cannot be empty")
        
        if state:
            state = state.strip().upper()
            if len(state) != 2:
                raise ValueError(f"State code must be 2 letters, got: {state}")
        
        if zip_code:
            # Convert to string and strip whitespace
            zip_code_str = str(zip_code).strip()
            # Remove any non-digit characters
            zip_code_clean = ''.join(c for c in zip_code_str if c.isdigit())
            # Validate length
            if len(zip_code_clean) > 5:
                raise ValueError(f"ZIP code must be 5 digits or less, got: {zip_code_clean}")
            # Zero-pad to 5 digits
            zip_code = zip_code_clean.zfill(5)
        
        if city:
            city = city.strip()
            if not city:
                raise ValueError("City cannot be empty")
        
        try:
            logger.info(f"Searching facilities with filters: facility_name={facility_name}, "
                       f"naics_code={naics_code}, state={state}, zip_code={zip_code}, city={city}, limit={limit}")
            
            # Use FRS client to search facilities
            async with FRSClient() as client:
                facilities = await client.search_facilities(
                    facility_name=facility_name,
                    naics_code=naics_code,
                    state=state,
                    zip_code=zip_code,
                    city=city,
                    limit=limit
                )
            
            logger.info(f"Found {len(facilities)} facilities matching search criteria")
            return facilities
            
        except ValueError:
            # Re-raise validation errors
            raise
        except EPAAPIError as e:
            logger.error(f"EPA API error during facility search: {e}")
            raise Exception(f"Failed to search facilities: {e}")
        except Exception as e:
            logger.error(f"Unexpected error during facility search: {e}")
            raise Exception(f"Failed to search facilities: {e}")
    
    
    # Register the tool with FastMCP
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 useful context about the search functionality (e.g., 'uses contains matching' for facility_name) and the data source, but doesn't mention rate limits, authentication needs, or potential errors. The description doesn't contradict annotations (none exist), but could be more comprehensive for a 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.

Conciseness5/5

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

The description is well-structured and front-loaded with the core purpose, followed by clear sections for arguments and returns. Every sentence adds value: the first states what the tool does, the second specifies requirements, and the parameter/return details are essential given the lack of schema descriptions. No wasted words.

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

Completeness4/5

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

Given 6 parameters with 0% schema coverage and no annotations, the description does a good job explaining inputs and outputs. The presence of an output schema means the description doesn't need to detail return values, which it appropriately summarizes. However, for a search tool with multiple filters, more behavioral context (e.g., performance expectations) would enhance completeness.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must fully compensate. It successfully adds meaning for all 6 parameters: it explains each filter's purpose (e.g., 'Partial or full facility name'), provides format examples (e.g., 'Two-letter state code'), and notes constraints like '5-digit ZIP code' and the default limit. This goes well beyond the bare schema.

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 tool searches for EPA-regulated facilities using various filters, specifying the data source (EPA's Facility Registry Service) and the type of resource. It distinguishes from siblings like 'get_facility_compliance_history_tool' by focusing on search rather than compliance history, though it doesn't explicitly name alternatives.

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 provides some usage context by stating 'At least one search parameter must be provided,' which helps avoid empty queries. However, it doesn't specify when to use this tool versus alternatives like 'environmental_summary_by_location' or 'get_facility_compliance_history_tool,' leaving the agent to infer based on tool names alone.

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/zachegner/envirofacts-mcp'

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