MCP Integration in Streamlit Dashboard
Overview
The MCP (Model Context Protocol) server has been integrated directly into the Streamlit dashboard, allowing you to fetch data from various sources without leaving the app.
How to Use
1. Access the Data Fetching View
- Open the Streamlit dashboard
- In the sidebar, select âđ„ Fetch Data Sourcesâ from the Analysis View options
- Youâll see a new section for fetching data from external sources
2. Available Data Sources
Anthropic EconomicIndex
- Source: Hugging Face dataset
- Usage: Select âAnthropic EconomicIndexâ, enter release version, click âFetch Dataâ
- Returns: Economic indicators related to AI impacts
- Requires:
pip install datasets(if MCP not available)
Stanford AI Index
- Source: Stanford HAI AI Index Report 2025
- Usage: Select âStanford AI Indexâ, choose metric type, click âFetch Dataâ
- Returns: AI investment, adoption, and performance metrics
- Metrics Available:
- Investment (US: $109.1B, China: $9.3B, UK: $4.5B)
- Adoption (78% of organizations using AI in 2024)
- Performance metrics
World Bank Indicator
- Source: World Bank API
- Usage: Select âWorld Bank Indicatorâ, enter indicator code, country, and year range
- Common Indicators:
SL.EMP.ICTI.ZS- ICT Services EmploymentSL.EMP.ICTM.ZS- ICT Manufacturing EmploymentIT.NET.USER.ZS- Internet Users
- Returns: Time series data with statistics
ITU ICT Data
- Source: ITU via World Bank API
- Usage: Select âITU ICT Dataâ, choose indicator (internet/mobile/broadband), enter country
- Returns: ICT penetration and usage data
View Source Information
- Usage: Select âView Source Informationâ, choose a source
- Returns: Information about data sources, URLs, and access methods
Features
Automatic Fallback
- If MCP SDK is not installed, the app uses direct API access
- World Bank data uses direct API calls (faster)
- Anthropic data can use Hugging Face datasets library directly
- Stanford data shows key metrics even without MCP
Data Display
- Fetched data is displayed in interactive tables
- Statistics are shown as metrics
- Data can be viewed, analyzed, and exported
Error Handling
- Clear error messages if data fetch fails
- Installation instructions for missing dependencies
- Graceful degradation if services are unavailable
Code Structure
Files
mcp_client.py- Simplified MCP client wrapperMCPDataFetcherclass- Methods for each data source
- Fallback mechanisms
app.py- Updated Streamlit app- New âFetch Data Sourcesâ view
- UI components for data fetching
- Integration with MCP client
Usage in Code
from mcp_client import data_fetcher
# Fetch Anthropic data
result = data_fetcher.fetch_anthropic_data("release_2025_09_15")
# Fetch Stanford AI Index
result = data_fetcher.fetch_stanford_ai_index("investment")
# Fetch World Bank indicator
result = data_fetcher.fetch_world_bank_indicator(
"SL.EMP.ICTI.ZS",
"USA",
2015,
2024
)Installation
Option 1: With MCP (Full Features)
pip install mcpOption 2: Without MCP (Fallback Mode)
# For Anthropic data
pip install datasets
# World Bank and ITU work without MCP (direct API)Example Workflow
Start Dashboard:
streamlit run app.pyNavigate to Fetch Data:
- Select âđ„ Fetch Data Sourcesâ from sidebar
Fetch Data:
- Choose a data source
- Configure parameters
- Click âFetch Dataâ
View Results:
- Data appears in tables
- Statistics shown as metrics
- Can be analyzed further
Integrate Data:
- Use fetched data for analysis
- Compare with existing dashboard data
- Export if needed
Troubleshooting
MCP Not Available
- The app will use direct API access
- World Bank data works without MCP
- Some features may be limited
Import Errors
# Install missing dependencies
pip install mcp datasets requests pandasData Fetch Failures
- Check internet connection
- Verify API endpoints are accessible
- Check error messages for specific issues
Next Steps
- Test Data Fetching: Try fetching from each source
- Integrate Data: Use fetched data in dashboard analysis
- Extend Functionality: Add more data sources as needed
- Save Data: Optionally save fetched data to database
Support
For issues: - Check mcp_server/README.md for MCP server details - Review DATA_SOURCES.md for source information - See INTEGRATION_GUIDE.md for integration steps