permit-data-mcp-server-nhc

ChrisTansey007/permit-data-mcp-server-nhc

3.2

If you are the rightful owner of permit-data-mcp-server-nhc and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The PermitData FastMCP Server for New Hanover County is a comprehensive solution for managing building permit data through ArcGIS Feature Services integration.

Tools
  1. check_permit_data

    Verify data freshness and synchronization status.

  2. download_permits

    Fetch all permits with intelligent caching and pagination.

  3. get_recent_permits

    Retrieve permits based on date criteria.

  4. filter_permits

    Apply Python expressions to filter permit datasets.

  5. permit_stats_summary

    Generate statistical summaries grouped by specified fields.

PermitData FastMCP Server - New Hanover County (NHC)

A comprehensive FastMCP server providing 8 specialized tools for managing New Hanover County building permit data through ArcGIS Feature Services integration.

๐Ÿš€ Quick Start

# Clone the repository
git clone https://github.com/yourusername/permit-data-mcp-server-nhc.git
cd permit-data-mcp-server-nhc

# Install dependencies
pip install -r requirements.txt

# Copy environment template
cp .env.example .env

# Run the server
python permit_mcp_server_nhc.py

The server will start at http://localhost:8000/mcp

๐Ÿ“‹ Features

Data Management

  • check_permit_data: Verify data freshness and compare local vs server records
  • download_permits: Fetch all permits with intelligent caching and pagination
  • get_recent_permits: Retrieve permits based on date criteria

Analytics & Filtering

  • filter_permits: Apply Python expressions to filter permit datasets
  • permit_stats_summary: Generate statistical summaries grouped by specified fields

State Management

  • get_current_subcontractors: Retrieve cached subcontractor list
  • update_current_subcontractors: Add/remove subcontractors from persistent state

Reporting

  • generate_reports: Create markdown and CSV reports with timestamped outputs

๐Ÿ›  Configuration

Environment Variables

Create a .env file from .env.example and configure:

# Data storage
DATA_DIR=./data

# New Hanover County ArcGIS endpoints
PERMIT_FEATURESERVER_URL_PRIMARY=https://gis.nhcgov.com/server/rest/services/Thematic/BuildingPermits/FeatureServer/0/query

# State management
SUBSCRIBER_STATE_PATH=./data/current_subs.json
REPORTS_OUTPUT_DIR=./data

# Optional API authentication
# MCP_API_KEY=your_secure_api_key_here

# Server configuration
PORT=8000

Required Dependencies

  • fastmcp >=0.1.0: FastMCP framework
  • pandas >=2.0.0: Data manipulation and analysis
  • requests >=2.31.0: HTTP client for API calls
  • python-dateutil >=2.8.2: Date parsing utilities
  • python-dotenv >=1.0.0: Environment variable management

๐Ÿณ Docker Deployment

Using Docker Compose (Recommended)

# Build and start the service
docker-compose up -d

# View logs
docker-compose logs -f

# Stop the service
docker-compose down

Using Docker Directly

# Build the image
docker build -t permit-mcp-server-nhc .

# Run the container
docker run -d \
  --name permit-mcp-nhc \
  -p 8000:8000 \
  -v $(pwd)/data:/app/data \
  -v $(pwd)/logs:/app/logs \
  permit-mcp-server-nhc

๐Ÿ“– API Reference

Tool: check_permit_data

Verify data freshness and synchronization status.

Parameters:

  • base_url (str): ArcGIS Feature Service URL
  • local_csv (str): Path to local CSV file for comparison
  • delta_days (int, default=1): Days threshold for staleness check
  • strict (bool, default=False): Raise exceptions on errors

Returns:

{
  "is_stale": true,
  "server_record_count": 1250,
  "server_last_edit": "2025-01-15T10:30:00",
  "local_record_count": 1245,
  "local_last_modified": "2025-01-14T15:20:00",
  "reason": "stale counts / age"
}

Tool: download_permits

Fetch all permits with intelligent caching and pagination.

Parameters:

  • base_url (str): ArcGIS Feature Service URL
  • force (bool, default=False): Force download even if cache is fresh
  • where (str, default="1=1"): SQL WHERE clause for filtering
  • page_size (int, default=10000): Records per API request
  • out_csv (str, optional): Output CSV path for caching

Returns:

{
  "records": 1250,
  "csv_path": "./data/permits.csv",
  "dataframe": [...],
  "skipped": false
}

Tool: get_recent_permits

Retrieve permits based on date criteria.

Parameters:

  • base_url (str): ArcGIS Feature Service URL
  • since (str): ISO date string (required)
  • date_field (str, default="ISSUE_DATE"): Date field to filter on
  • page_size (int, default=10000): Records per API request

Tool: filter_permits

Apply Python expressions to filter permit datasets.

Parameters:

  • permits_json (List[Dict]): Permit records to filter
  • filter_expr (str): Python expression (e.g., "row['PERMIT_VALUE'] > 50000")

Tool: permit_stats_summary

Generate statistical summaries grouped by specified fields.

Parameters:

  • permits_json (List[Dict]): Permit records to analyze
  • group_by (str, default="GENERAL_CONTRACTOR"): Field to group by

๐Ÿงช Testing

Run the test suite with pytest:

# Install test dependencies
pip install pytest

# Run all tests
pytest test_permit_server.py -v

# Run with coverage
pip install pytest-cov
pytest test_permit_server.py --cov=permit_mcp_server_nhc

๐Ÿ“ Project Structure

permit-data-mcp-server-nhc/
โ”œโ”€โ”€ permit_mcp_server_nhc.py    # Main FastMCP server
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ .env.example               # Environment template
โ”œโ”€โ”€ Dockerfile                 # Container configuration
โ”œโ”€โ”€ docker-compose.yml         # Docker orchestration
โ”œโ”€โ”€ test_permit_server.py      # Test suite
โ”œโ”€โ”€ README.md                  # This file
โ”œโ”€โ”€ LICENSE                    # MIT License
โ”œโ”€โ”€ .gitignore                # Git ignore rules
โ”œโ”€โ”€ data/                     # Runtime data storage
โ””โ”€โ”€ logs/                     # Application logs

๐Ÿ”ง Development

Local Development Setup

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -r requirements.txt
pip install pytest pytest-cov black flake8

# Format code
black .

# Lint code
flake8 permit_mcp_server_nhc.py

# Run server in development mode
python permit_mcp_server_nhc.py

Data Source Information

This server connects to New Hanover County's public ArcGIS Feature Service:

Note: Unlike Brunswick County, New Hanover County does not expose public EnerGov/COAST endpoints for contractor contact information.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the file for details.

๐Ÿ†˜ Support

๐Ÿ”— Related Projects


Built with โค๏ธ using FastMCP for New Hanover County permit data management.