File size: 5,241 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
# Open Navigator MCP Server

**Model Context Protocol (MCP) server for Open Navigator**

This directory contains the MCP server implementation that exposes Open Navigator's data sources to AI assistants like Claude.

## What's Here

- **`open_navigator_server.py`** - Main MCP server implementation

## Quick Start

### 1. Install Dependencies

```bash
pip install mcp anthropic-mcp-sdk
```

### 2. Run the Server

```bash
# From project root
python scripts/mcp/open_navigator_server.py
```

### 3. Configure Claude Desktop

Add to `~/.config/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"
      }
    }
  }
}
```

## Features

The MCP server provides AI assistants with access to:

- **90,000+ U.S. Jurisdictions** - Cities, counties, and states from Census data
- **1.8M Nonprofit Organizations** - IRS Form 990 data with financials
- **4.5M+ Legislative Documents** - Bills, versions, and documents from Open States
- **Vector Search** - Semantic search across bills and meetings using Qdrant
- **Real-time Analytics** - PostgreSQL queries for statistics and aggregates

## Available Tools

### Jurisdiction Tools
- `search_jurisdictions` - Search cities, counties, states by name/location

### Nonprofit Tools
- `get_nonprofits` - Query nonprofits with Form 990 data

### Legislative Tools
- `vector_search_bills` - Semantic search across bills
- `vector_search_meetings` - Semantic search across meeting transcripts

### Analytics Tools
- `get_bill_stats` - Legislative statistics by state/topic
- `search_meetings` - Keyword search meeting records

## Documentation

πŸ“– **Full documentation:** [website/docs/integrations/mcp-server.md](../../website/docs/integrations/mcp-server.md)

Online: https://www.communityone.com/docs/integrations/mcp-server

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Claude Desktop β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ MCP Protocol (stdio)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ open_navigator_ β”‚
β”‚    server.py    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tools:          β”‚
β”‚ β€’ Jurisdictions │──► HuggingFace Datasets
β”‚ β€’ Nonprofits    │──► HuggingFace Datasets
β”‚ β€’ Vector Search │──► Qdrant (localhost:6333)
β”‚ β€’ Analytics     │──► PostgreSQL (localhost:5433)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Requirements

**Python packages:**
- `mcp>=0.1.0`
- `anthropic-mcp-sdk>=0.1.0`
- `qdrant-client` (optional, for vector search)
- `psycopg2-binary` (optional, for analytics)
- `datasets` (optional, for HuggingFace datasets)

**Services:**
- Qdrant (vector database) - `docker-compose up -d qdrant`
- PostgreSQL (analytics) - `docker-compose up -d postgres`

## Example Queries to Claude

Once configured, you can ask Claude:

> "Find all cities named Springfield in the database"

> "Show me 501c3 nonprofits in San Francisco focused on education"

> "What bills related to oral health were introduced in California in 2024?"

> "Which Massachusetts cities discussed housing in recent meetings?"

Claude will automatically use the appropriate MCP tools to answer!

## Troubleshooting

**Server won't start?**
```bash
# Check Python version (need 3.11+)
python --version

# Install dependencies
pip install -r requirements.txt
```

**Tools unavailable?**
```bash
# Start Qdrant
docker-compose up -d qdrant

# Start PostgreSQL
docker-compose up -d postgres

# Verify
curl http://localhost:6333/collections
psql -h localhost -p 5433 -U postgres -d open_navigator -c "SELECT 1"
```

**Claude can't connect?**
- Use **absolute paths** in `claude_desktop_config.json`
- Restart Claude Desktop after config changes
- Check logs: `~/Library/Logs/Claude/mcp*.log` (macOS)

## Development

### Adding New Tools

1. Add tool definition to `list_tools()`:

```python
Tool(
    name="my_new_tool",
    description="What this tool does",
    inputSchema={
        "type": "object",
        "properties": {
            "param": {"type": "string"}
        },
        "required": ["param"]
    }
)
```

2. Add handler to `call_tool()`:

```python
elif name == "my_new_tool":
    # Implementation
    return [TextContent(type="text", text=result)]
```

3. Test:

```bash
python scripts/mcp/open_navigator_server.py
```

### Testing with MCP Inspector

```bash
# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector

# Run inspector
mcp-inspector python scripts/mcp/open_navigator_server.py
```

Opens web UI to test tools interactively.

## Resources

- **MCP Protocol:** https://modelcontextprotocol.io/
- **Anthropic MCP SDK:** https://github.com/anthropics/anthropic-sdk-python
- **MCP Servers Repository:** https://github.com/modelcontextprotocol/servers
- **Open Navigator Docs:** https://www.communityone.com/docs

## License

Apache 2.0 - See [LICENSE](../../LICENSE)