wbott/mcp-postal-geocoder
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.
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
- postal_code_search - Search postal codes (exact match or prefix)
- geocode_postal - Convert postal code to coordinates
- reverse_geocode - Find postal codes near coordinates
- validate_postal - Check if postal code exists
- 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
- Create a new Space on HuggingFace with Streamlit SDK
- Copy files:
streamlit_app.py
,requirements.txt
,src/
,data/
- Use
space_config.yml
for Space configuration - Or use the GitHub Action for automatic sync
GitHub Action Setup
- Add
HF_TOKEN
to GitHub repository secrets - Update USERNAME/SPACENAME in
.github/workflows/sync-to-hf.yml
- Push to main branch triggers automatic deployment
Local Development
streamlit run streamlit_app.py
š¤ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- 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