uk_ons_mcp_server
v1.0.0
Published
MCP server for UK Office for National Statistics (ONS) API - providing access to UK government statistics
Maintainers
Readme
UK ONS MCP Server
A Model Context Protocol server that provides access to UK Office for National Statistics (ONS) data. This enables AI assistants to retrieve and analyze official UK government statistics including economic indicators, population data, and social metrics.
Features
- 🔓 No API Key Required - Uses the free ONS Beta API
- 📊 Comprehensive Data Access - Economic, social, and demographic statistics
- 🔍 Smart Search - Find datasets by keyword or topic
- 📈 Real-time Data - Access the latest official UK statistics
- 🌐 Travel-Friendly - Perfect for UK travel apps needing area demographics
Available Tools
Dataset Discovery
list_datasets()- Get all available datasetssearch_datasets(query)- Search datasets by keywordget_popular_datasets()- Get commonly used datasets
Dataset Information
get_dataset_info(dataset_id)- Detailed dataset informationget_dataset_editions(dataset_id)- Available editionsget_dataset_download_url(dataset_id)- Download links
Data Access
get_dataset_data(dataset_id)- Retrieve actual statistical data
Popular Datasets
- cpih01 - Consumer Price Inflation (CPI)
- lms - Labour Market Statistics
- regional-gdp-by-year - Regional GDP Data
- wellbeing-quarterly - National Well-being Indicators
- population-estimates-timeseries - Population Estimates
- house-prices - UK House Price Statistics
- retail-sales-index - Retail Sales Data
- uk-trade-info - International Trade Statistics
Installation
Prerequisites
- Python 3.9+
- uv (recommended) or pip
Install with npm and pip
git clone https://github.com/dwain-barnes/uk-ons-mcp-server.git
cd uk-ons-mcp-server
npm install
npm run install-depsFor development
npm run install-dev-depsUsage
Running the Server
Development Mode
npm run devProduction Mode
npm startTesting
npm testClaude Desktop Integration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"uk-ons-statistics": {
"command": "python",
"args": ["/path/to/uk-ons-mcp-server/uk_ons_mcp_server/server.py"]
}
}
}Using with MCP Inspector
Test the server during development:
npx @modelcontextprotocol/inspector python uk_ons_mcp_server/server.pyExample Queries
Ask Claude these questions once connected:
- "What datasets are available about employment?"
- "Show me the latest inflation data"
- "Get population statistics for UK regions"
- "Find datasets related to housing"
- "What's the GDP data for different UK regions?"
API Reference
Data Source
All data comes from the official ONS Beta API:
- Base URL: https://api.beta.ons.gov.uk/v1
- Authentication: None required
- Rate Limits: Reasonable usage (no official limits published)
- Documentation: https://developer.ons.gov.uk/
Error Handling
The server includes comprehensive error handling for:
- Network timeouts and connection issues
- Invalid dataset IDs or parameters
- API rate limiting (if implemented)
- Data parsing errors
Development
Setup Development Environment
git clone https://github.com/dwain-barnes/uk-ons-mcp-server.git
cd uk-ons-mcp-server
npm install
npm run install-dev-depsRunning Tests
npm testCode Formatting
npm run formatType Checking
npm run type-checkLinting
npm run lintProject Structure
uk-ons-mcp-server/
├── uk_ons_mcp_server/
│ ├── __init__.py
│ └── server.py # Main MCP server implementation
├── tests/
│ ├── __init__.py
│ └── test_server.py # Unit tests
├── pyproject.toml # Project configuration
├── README.md # This file
├── LICENSE # MIT License
└── .gitignore # Git ignore patternsContributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Run the test suite (
uv run pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- UK Office for National Statistics for providing free, open access to official statistics
- Model Context Protocol for the standardized AI integration framework
- Anthropic for developing MCP and Claude
Related Projects
- police-uk-api-mcp-server - UK Police data MCP server
- Model Context Protocol Servers - Official MCP server implementations
Disclaimer
This is an unofficial implementation and is not affiliated with, endorsed by, or sponsored by the UK Office for National Statistics. All data remains subject to ONS terms of use.
