Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 13,015 Bytes
61d29fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | ---
sidebar_position: 1
---
# Model Context Protocol (MCP) Server
**Turn your Open Navigator data into an AI-accessible knowledge base!**
The Open Navigator MCP server exposes your entire civic data platform to AI assistants like Claude through the [Model Context Protocol](https://modelcontextprotocol.io/). This enables AI assistants to:
- ποΈ Search 90,000+ U.S. jurisdictions
- π’ Query 3M+ nonprofit organizations
- π Semantic search across 4.5M+ legislative documents
- π Get real-time statistics and analytics
- π Vector search meetings and bills with natural language
## What is MCP?
**Model Context Protocol (MCP)** is an open protocol that standardizes how AI applications provide context to LLMs. Instead of manually copying data or writing custom integrations, MCP lets AI assistants directly access your data sources through a unified interface.
**Benefits:**
- β
**Live Data**: AI queries your latest data, not stale exports
- β
**Semantic Search**: Natural language queries with vector search
- β
**Type-Safe**: Structured tool definitions with validated inputs
- β
**Composable**: Combine multiple data sources in one query
- β
**Secure**: Run locally with no data leaving your machine
## Architecture
```
βββββββββββββββββββββββ
β Claude Desktop β
β (or other AI) β
ββββββββββββ¬βββββββββββ
β MCP Protocol
ββββββββββββΌβββββββββββ
β Open Navigator β
β MCP Server β
βββββββββββββββββββββββ€
β β HuggingFace Hub ββββΊ 90k jurisdictions
β β Qdrant Vector DB ββββΊ Semantic search
β β PostgreSQL ββββΊ Analytics & stats
βββββββββββββββββββββββ
```
## Quick Start
### 1. Install MCP SDK
```bash
# Activate virtual environment
source .venv/bin/activate
# Install MCP dependencies
pip install mcp anthropic-mcp-sdk
```
### 2. Start Required Services
```bash
# Start Qdrant (vector database)
docker-compose up -d qdrant
# Start PostgreSQL (if not already running)
docker-compose up -d postgres
# Verify services
curl http://localhost:6333/collections # Qdrant
psql -h localhost -p 5433 -U postgres -d open_navigator -c "SELECT COUNT(*) FROM meetings" # PostgreSQL
```
### 3. Run the MCP Server
```bash
# Test the server
python scripts/mcp/open_navigator_server.py
```
**Expected Output:**
```
π Starting Open Navigator MCP Server...
π HuggingFace Datasets: β
π Qdrant Vector Search: β
πΎ PostgreSQL Analytics: β
Ready to serve requests via MCP protocol
```
### 4. Configure Claude Desktop
Add to your Claude Desktop configuration file:
**macOS/Linux:** `~/.config/Claude/claude_desktop_config.json`
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
```json
{
"mcpServers": {
"open-navigator": {
"command": "python",
"args": [
"/absolute/path/to/open-navigator/scripts/mcp/open_navigator_server.py"
],
"env": {
"QDRANT_HOST": "localhost",
"QDRANT_PORT": "6333",
"DATABASE_URL": "postgresql://postgres:password@localhost:5433/open_navigator"
}
}
}
}
```
:::tip
Use absolute paths! Replace `/absolute/path/to/open-navigator` with your actual project path.
:::
### 5. Restart Claude Desktop
Close and reopen Claude Desktop. The MCP server will start automatically when you begin a conversation.
## Available Tools
### ποΈ Jurisdiction Tools
#### `search_jurisdictions`
Search 90,000+ U.S. jurisdictions by name, type, or location.
**Parameters:**
- `query` (required): Search term (e.g., "San Francisco", "Orange County")
- `state` (optional): Filter by state code (e.g., "CA", "NY")
- `type` (optional): Filter by type ("city", "county", "state")
- `limit` (optional): Maximum results (default: 10)
**Example Claude Query:**
> "Find all cities named Springfield in the database"
**Returns:**
```json
[
{
"name": "Springfield",
"state_code": "IL",
"type": "city",
"population": 116250,
"fips_code": "1772000"
},
...
]
```
---
### π’ Nonprofit Tools
#### `get_nonprofits`
Get nonprofit organizations with Form 990 data.
**Parameters:**
- `state` (required): State code (e.g., "CA", "NY", "TX")
- `city` (optional): Filter by city name
- `subsection` (optional): IRS subsection code (e.g., "03" for 501c3)
- `limit` (optional): Maximum results (default: 50)
**Example Claude Query:**
> "Show me 501c3 nonprofits in San Francisco, CA"
**Returns:**
```json
[
{
"ein": "941234567",
"name": "Example Nonprofit",
"city": "SAN FRANCISCO",
"subsection": "03",
"revenue": 1500000,
"assets": 2000000
},
...
]
```
---
### π Legislative Tools
#### `vector_search_bills`
Semantic search across legislative bills using natural language.
**Parameters:**
- `query` (required): Natural language query
- `state` (optional): Filter by state code
- `limit` (optional): Maximum results (default: 10)
**Example Claude Query:**
> "Find bills related to oral health funding in California"
**Returns:**
```json
[
{
"bill_id": "CAB123",
"title": "An Act relating to dental health services",
"state": "CA",
"session": "2025-2026",
"score": 0.89,
"summary": "Establishes funding for community dental clinics..."
},
...
]
```
---
#### `vector_search_meetings`
Semantic search across meeting transcripts using natural language.
**Parameters:**
- `query` (required): Natural language query
- `municipality` (optional): Filter by city name
- `limit` (optional): Maximum results (default: 10)
**Example Claude Query:**
> "What did the Boston city council discuss about housing?"
**Returns:**
```json
[
{
"meeting_id": "MTG-2024-001",
"title": "Boston City Council Meeting",
"municipality": "Boston",
"date": "2024-03-15",
"score": 0.92,
"excerpt": "Discussion on affordable housing initiatives..."
},
...
]
```
---
### π Analytics Tools
#### `get_bill_stats`
Get legislative statistics and aggregates by state/topic.
**Parameters:**
- `state` (optional): State code for state-specific stats
- `topic` (optional): Filter by topic/category
**Example Claude Query:**
> "Show me bill statistics for California"
**Returns:**
```json
[
{
"state": "CA",
"topic": "Health",
"total_bills": 1523,
"bill_count": 1523
},
...
]
```
---
#### `search_meetings`
Search meeting records by keyword, location, or date.
**Parameters:**
- `query` (optional): Search keyword
- `state` (optional): Filter by state
- `limit` (optional): Maximum results (default: 20)
**Example Claude Query:**
> "Find recent city council meetings in Massachusetts"
**Returns:**
```json
[
{
"name": "City Council Meeting",
"organization_name": "Boston City Council",
"state": "MA",
"event_date": "2024-03-15",
"description": "Regular meeting agenda..."
},
...
]
```
## Example Use Cases
### 1. Multi-Source Research
**Query to Claude:**
> "Find nonprofits working on dental health in California cities with populations over 100k"
**What happens:**
1. Claude uses `search_jurisdictions` to find CA cities > 100k
2. Claude uses `get_nonprofits` to find dental health orgs
3. Claude combines results and filters
4. You get a comprehensive report!
---
### 2. Legislative Analysis
**Query to Claude:**
> "What oral health bills were introduced in 2024 and what did local governments say about them?"
**What happens:**
1. Claude uses `vector_search_bills` for oral health legislation
2. Claude uses `vector_search_meetings` for related discussions
3. Claude cross-references bills with meeting minutes
4. You get bill summaries + public sentiment!
---
### 3. Advocacy Targeting
**Query to Claude:**
> "Which California cities have discussed climate change but don't have major environmental nonprofits?"
**What happens:**
1. Claude searches meetings for climate discussions
2. Claude gets environmental nonprofits by city
3. Claude identifies gaps in nonprofit coverage
4. You get a list of cities to target for organizing!
## Troubleshooting
### Server Won't Start
**Check Python environment:**
```bash
source .venv/bin/activate
python --version # Should be 3.11+
```
**Install missing dependencies:**
```bash
pip install mcp anthropic-mcp-sdk qdrant-client psycopg2-binary datasets
```
---
### Tools Show as Unavailable
**Verify services are running:**
```bash
# Check Qdrant
curl http://localhost:6333/collections
# Check PostgreSQL
psql -h localhost -p 5433 -U postgres -d open_navigator -c "SELECT 1"
```
**Check environment variables:**
- `QDRANT_HOST` (default: localhost)
- `QDRANT_PORT` (default: 6333)
- `DATABASE_URL` (default: postgresql://postgres:password@localhost:5433/open_navigator)
---
### Claude Can't Find Server
**Verify configuration path:**
```bash
# macOS/Linux
cat ~/.config/Claude/claude_desktop_config.json
# Windows
type %APPDATA%\Claude\claude_desktop_config.json
```
**Use absolute paths:**
- β `./scripts/mcp/open_navigator_server.py`
- β
`/home/user/projects/open-navigator/scripts/mcp/open_navigator_server.py`
---
### HuggingFace Dataset Errors
**Authenticate with HuggingFace:**
```bash
# Login (if datasets are private)
huggingface-cli login
# Set token in environment
export HUGGINGFACE_TOKEN=hf_...
```
**Check dataset availability:**
```bash
python -c "from datasets import load_dataset; ds = load_dataset('getcommunityone/open-navigator-census', split='train'); print(len(ds))"
```
## Advanced Configuration
### Environment Variables
All configurable via environment variables:
```json
{
"mcpServers": {
"open-navigator": {
"command": "python",
"args": ["/path/to/scripts/mcp/open_navigator_server.py"],
"env": {
"QDRANT_HOST": "localhost",
"QDRANT_PORT": "6333",
"DATABASE_URL": "postgresql://postgres:password@localhost:5433/open_navigator",
"HUGGINGFACE_TOKEN": "hf_..."
}
}
}
}
```
### Multiple Environments
Run different configurations for dev/prod:
```json
{
"mcpServers": {
"open-navigator-local": {
"command": "python",
"args": ["/path/to/scripts/mcp/open_navigator_server.py"],
"env": {
"DATABASE_URL": "postgresql://localhost:5433/open_navigator"
}
},
"open-navigator-prod": {
"command": "python",
"args": ["/path/to/scripts/mcp/open_navigator_server.py"],
"env": {
"DATABASE_URL": "postgresql://prod-host:5432/open_navigator",
"QDRANT_HOST": "prod-qdrant-host"
}
}
}
}
```
## Performance Tips
### 1. Limit Result Sizes
Always specify `limit` parameters to avoid large payloads:
```
β "Find all nonprofits in California"
β
"Find the top 50 largest nonprofits in California"
```
### 2. Use Vector Search for Semantic Queries
For natural language queries, prefer vector search over text search:
```
β search_meetings with keyword "education"
β
vector_search_meetings with "What did they discuss about school funding?"
```
### 3. Filter Before Fetching
Apply filters early to reduce data transfer:
```
β Get all CA nonprofits, then filter by city
β
get_nonprofits(state="CA", city="San Francisco")
```
### 4. Cache HuggingFace Datasets
Datasets are cached after first load (~1-2 min initial load, instant after):
```bash
# Pre-load datasets for faster queries
python -c "from datasets import load_dataset; load_dataset('getcommunityone/open-navigator-census')"
```
## Security Considerations
### Local-Only by Default
The MCP server runs **locally** and only responds to local processes (Claude Desktop). No data leaves your machine.
### Database Credentials
Store credentials securely:
- β
Use environment variables
- β
Use `.env` files (gitignored)
- β Don't hardcode passwords in config
### Rate Limiting
For production deployments, add rate limiting:
```python
# In open_navigator_server.py
from ratelimit import limits, sleep_and_retry
@sleep_and_retry
@limits(calls=10, period=60)
@app.call_tool()
async def call_tool(name: str, arguments: dict):
# ... existing code
```
## Next Steps
- π [Build Custom MCP Tools](./custom-mcp-tools.md)
- π [Vector Search Optimization](../guides/vector-search.md)
- π [Deploy MCP Server to Cloud](./mcp-cloud-deployment.md)
- π€ [Integrate with Other AI Assistants](./ai-integrations.md)
## Resources
- **MCP Protocol Spec:** https://modelcontextprotocol.io/
- **Anthropic MCP SDK:** https://github.com/anthropics/anthropic-sdk-python
- **Open Navigator GitHub:** https://github.com/getcommunityone/open-navigator
- **MCP Server Examples:** https://github.com/modelcontextprotocol/servers
---
**Questions?** Open an issue at [github.com/getcommunityone/open-navigator/issues](https://github.com/getcommunityone/open-navigator/issues)
|