mcp-postal-geocoder

wbott/mcp-postal-geocoder

3.2

If you are the rightful owner of mcp-postal-geocoder 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.

MCP Postal Geocoder is a high-performance server for US postal code geocoding using US Census Bureau ZCTA data.

Tools
5
Resources
0
Prompts
0

title: MCP Postal Geocoder emoji: šŸ“ colorFrom: blue colorTo: green sdk: streamlit sdk_version: "1.39.0" app_file: streamlit_app.py pinned: false

MCP Postal Geocoder

Complete MCP Server & Client Implementation for US Postal Code Geocoding

A full-featured Model Context Protocol implementation including both MCP Server (FastMCP backend) and MCP Client (Streamlit demo app). Provides a drop-in replacement for GeoNames postal code API using US Census Bureau ZIP Code Tabulation Areas (ZCTAs). Fast, accurate, and comprehensive with 33,791 US postal codes.

🌟 Features

  • Complete MCP Implementation: Both server (5 tools) and client (Streamlit app)
  • 5 MCP Tools: Search, geocode, reverse geocode, validate, and statistics
  • Census Accuracy: Official US Census Bureau ZCTA data
  • High Performance: <1ms exact lookups, <50ms reverse geocoding
  • Complete Coverage: All 33,791 US postal codes with cities and states
  • Reference Implementation: Perfect example for building MCP clients
  • Multi-Environment: Works in development, containers, and cloud deployments

šŸš€ Demo

Try the live demo: MCP Postal Geocoder on HuggingFace Spaces

Features in Demo:

  • šŸ“Š Database Statistics - Real-time stats on 33,791 postal codes
  • šŸ” Search Tools - Exact match and prefix search with maps
  • šŸŒ Geocoding - Convert postal codes to coordinates
  • šŸ“ Reverse Geocoding - Find postal codes near any location
  • āœ… Validation - Quick postal code validation

šŸ› ļø Available Tools

  1. postal_code_search - Search postal codes (exact match or prefix)
  2. geocode_postal - Convert postal code to coordinates
  3. reverse_geocode - Find postal codes near coordinates
  4. validate_postal - Check if postal code exists
  5. postal_stats - Database statistics and health

šŸ“¦ Installation

pip install -e .

šŸŽÆ Usage

MCP Server

# Start MCP server
mcp-postal-server

# Or with Python
python -m mcp_postal_geocoder.server.mcp_server

CLI Client

# Test all tools
postal-cli test

# Individual commands
postal-cli geocode 90210
postal-cli reverse 47.606 -122.332
postal-cli stats

Streamlit Demo

streamlit run streamlit_app.py

šŸ—‚ļø Database Schema

  • zcta_code (TEXT) - 5-digit ZIP code (primary key)
  • latitude, longitude (REAL) - WGS84 coordinates
  • state (TEXT) - State abbreviation
  • city (TEXT) - City name
  • land_area_sqm, water_area_sqm (REAL) - Area measurements
  • country_code (TEXT) - Always "US"

šŸ”§ Development

# Install in development mode
pip install -e .

# Run tests
pytest

# Lint and format  
ruff check src/
black src/
mypy src/

šŸ“Š Performance

  • Exact postal code lookup: <1ms
  • Prefix searches: <10ms
  • Reverse geocoding: <50ms
  • Concurrent connections: 100+
  • Database size: 6.9MB SQLite

šŸ—ļø Architecture

src/mcp_postal_geocoder/
ā”œā”€ā”€ server/
│   ā”œā”€ā”€ mcp_server.py          # Main MCP server (FastMCP)
│   ā”œā”€ā”€ database/
│   │   ā”œā”€ā”€ connection.py      # SQLite connection management
│   │   ā”œā”€ā”€ models.py          # Pydantic data models
│   │   └── queries.py         # Optimized SQL queries
│   └── utils/
│       └── formatters.py      # Response formatting
ā”œā”€ā”€ client/
│   └── cli_tool.py           # CLI client for testing
└── data/
    └── postal_census_complete.db  # SQLite database (33,791 records)

🌐 API Compatibility

Designed as a drop-in replacement for GeoNames postal API:

{
  "totalResultsCount": 1,
  "geonames": [
    {
      "postalCode": "90210",
      "lat": 34.102512,
      "lng": -118.415075,
      "countryCode": "US", 
      "state": "CA",
      "placeName": "Santa Monica"
    }
  ]
}

šŸ“„ License

MIT License - see LICENSE file for details.

šŸš€ Deployment

HuggingFace Spaces

  1. Create a new Space on HuggingFace with Streamlit SDK
  2. Copy files: streamlit_app.py, requirements.txt, src/, data/
  3. Use space_config.yml for Space configuration
  4. Or use the GitHub Action for automatic sync

GitHub Action Setup

  1. Add HF_TOKEN to GitHub repository secrets
  2. Update USERNAME/SPACENAME in .github/workflows/sync-to-hf.yml
  3. Push to main branch triggers automatic deployment

Local Development

streamlit run streamlit_app.py

šŸ¤ Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

šŸ“ˆ Status

  • āœ… Phase 1: Core MCP server implementation
  • āœ… Phase 2: Advanced search and city assignments
  • āœ… Phase 3: CLI client and testing tools
  • āœ… Phase 4: Streamlit demo and deployment
  • šŸ”„ Phase 5: Documentation and optimization

šŸ™ Acknowledgments

  • US Census Bureau for ZCTA data
  • Anthropic for MCP framework
  • FastMCP for modern server implementation