USPS Address Validation and Standardization MCP Server
Enables AI assistants to validate and standardize US addresses using the official USPS Address Validation API with secure OAuth2 authentication.
README
USPS Address Validation and Standardization MCP Server
A Model Context Protocol (MCP) server that provides AI assistants with tools to interact with USPS services, specifically address validation and standardization.
Features
- Address Validation: Validate and standardize US addresses using the official USPS Address Validation API
- OAuth2 Authentication: Secure authentication using USPS OAuth2 Client Credentials flow
- MCP Protocol Compliance: Standard MCP server implementation for AI model integration
- Comprehensive Error Handling: Robust error handling for API timeouts, rate limits, and validation errors
- TypeScript Support: Full TypeScript implementation with type safety
Prerequisites
- USPS Business Account: You need a USPS Business Account to access the APIs. Read the Getting Started at USPS Developer Portal
- API Credentials: Obtain Consumer Key and Consumer Secret from your API app
Setup
1. Clone and Install
git clone https://github.com/bailur/usps-mcp-server.git
cd usps-mcp-server
npm install
2. Environment Configuration
Copy the example environment file and configure your USPS credentials:
cp .env.example .env
Edit .env with your USPS API credentials:
USPS_CLIENT_ID=your_consumer_key_here
USPS_CLIENT_SECRET=your_consumer_secret_here
NODE_ENV=development
3. Build and Run as stdio
# Development
npm run dev
# Production build
npm run build
npm start
# Run tests
npm test
4. Run as an SSE MCP server
# Production build
npm run start:http
Usage
As a stdio MCP Server
The server runs as a stdio-based MCP server. Configure your AI client to use this server:
{
"mcpServers": {
"usps": {
"command": "node",
"args": ["/path/to/usps-mcp-server/dist/index.js"],
"env": {
"USPS_CLIENT_ID": "your_key",
"USPS_CLIENT_SECRET": "your_secret"
}
}
}
}
Usage in Claude as stdio
{
"mcpServers": {
"usps": {
"command": "npx",
"args": [
"tsx",
"/path/to/usps-mcp-server/src/index.ts",
"--env", "USPS_CLIENT_ID=your_client_id",
"--env", "USPS_CLIENT_SECRET=your_consumer_secret",
"--env", "NODE_ENV=prod",
"--env", "MCP_TRANSPORT=stdio",
"--env", "USPS_BASE_URL=https://apis.usps.com",
"--env", "USPS_TEST_BASE_URL=https://apis-tem.usps.com"
]
}
},
"globalShortcut": "CommandOrControl+Shift+Space"
}
Usage in VS Code Copilot as SSE
Run the app using SSE
npm run start:http
Configure VS Code mcp.json
{
"servers": {
"usps-remote-mcp-server": {
"url": "http://localhost:3000/mcp",
"type": "sse"
}
},
"inputs": []
}
Available Tools
validate_address
Validates and standardizes a US address using USPS services.
Parameters:
streetAddress(required): Street address (e.g., "123 Main St")city(required): City name (e.g., "New York")state(required): Two-letter state code (e.g., "NY")zipCode(required): ZIP code (e.g., "12345" or "12345-6789")urbanization(optional): Urbanization name (Puerto Rico only)
Example Usage:
{
"tool": "validate_address",
"arguments": {
"streetAddress": "123 Main Street",
"city": "New York",
"state": "NY",
"zipCode": "10001"
}
}
Response:
{
"success": true,
"originalAddress": {
"streetAddress": "123 Main Street",
"city": "New York",
"state": "NY",
"zipCode": "10001"
},
"validatedAddress": {
"address": {
"streetAddress": "123 MAIN ST",
"city": "NEW YORK",
"state": "NY",
"ZIPCode": "10001",
"ZIPPlus4": "1234"
},
"additionalInfo": {
"DPVConfirmation": "Y",
"business": "N"
}
},
"summary": "Standardized address: 123 MAIN ST, NEW YORK, NY, 10001-1234 (delivery point confirmed)"
}
API Integration
USPS Authentication
The server automatically handles OAuth2 authentication:
- Uses Client Credentials flow with your USPS Consumer Key/Secret
- Caches access tokens and handles automatic refresh
- Adds Bearer token to all API requests
Rate Limiting
- USPS APIs have rate limits (default: 60 calls per hour)
- The server implements delays between batch requests
- Consider implementing additional rate limiting for production use
Testing Environment
For development, set NODE_ENV=development to use the USPS Testing Environment for Mailers (TEM):
- Production:
apis.usps.com - Testing:
apis-tem.usps.com
Error Handling
The server provides comprehensive error handling:
- Authentication Errors: Invalid credentials, expired tokens
- Validation Errors: Invalid input parameters, malformed addresses
- API Errors: USPS service errors, network timeouts
- Rate Limit Errors: Automatic retry with exponential backoff
Development
Project Structure
src/
├── auth/
│ └── oauth-client.ts # OAuth2 client implementation
├── services/
│ └── address-validation.ts # Address validation service
├── tools/
│ └── validate-address-tool.ts # MCP tool definition
├── types/
│ └── address-types.ts # TypeScript type definitions
├── server.ts # Main MCP server
└── index.ts # Entry point
Adding New Tools
- Create service class in
src/services/ - Define tool schema in
src/tools/ - Register tool in
src/server.ts - Add tests and update documentation
License
MIT License - see LICENSE file for details
Support
For USPS API issues:
For MCP Server issues:
- Create an issue in this repository
- Check the MCP Specification
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.