Skip to content

Commit d935d0a

Browse files
committed
minimal working customizable stdio version
1 parent a90e6a8 commit d935d0a

23 files changed

Lines changed: 208 additions & 2421 deletions

.bumpver.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.vscode/mcp.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"servers": {
3+
"duckdb-geo": {
4+
"command": "uv",
5+
"args": [
6+
"run",
7+
"--with",
8+
"mcp",
9+
"--with",
10+
"duckdb",
11+
"--with",
12+
"pandas",
13+
"server.py"
14+
]
15+
}
16+
}
17+
}

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,213 +1 @@
1-
# Wetlands MCP Server
2-
3-
An MCP server specialized for analyzing wetlands datasets using DuckDB. This server provides AI assistants and IDEs with the ability to query and analyze comprehensive wetlands data, including spatial information, temporal trends, and ecological metrics.
4-
5-
This server is based on [MotherDuck's DuckDB MCP Server](https://github.com/motherduckdb/mcp-server-motherduck) and extends it with wetlands-specific prompts and context.
6-
7-
## Features
8-
9-
- **Wetlands-specific**: Pre-configured prompts and context for wetlands data analysis
10-
- **Hybrid execution**: Query data from local DuckDB or cloud-based MotherDuck databases
11-
- **Cloud storage integration**: Access wetlands data stored in Amazon S3 or other cloud storage
12-
- **Spatial analytics**: Leverage DuckDB's spatial extensions for geospatial wetlands analysis
13-
- **SQL analytics**: Use DuckDB's SQL dialect to query wetlands datasets directly from your AI Assistant or IDE
14-
- **Serverless architecture**: Run analytics without needing to configure instances or clusters
15-
16-
## Components
17-
18-
### Prompts
19-
20-
The server accepts custom prompts with --custom-prompt argument.
21-
22-
### Tools
23-
24-
The server offers one tool:
25-
26-
- `query`: Execute a SQL query on the DuckDB or MotherDuck database
27-
- **Inputs**:
28-
- `query` (string, required): The SQL query to execute
29-
30-
All interactions with both DuckDB and MotherDuck are done through writing SQL queries.
31-
32-
**Result Limiting**: Query results are automatically limited to prevent using up too much context:
33-
- Maximum 1024 rows by default (configurable with `--max-rows`)
34-
- Maximum 50,000 characters by default (configurable with `--max-chars`)
35-
- Truncated responses include a note about truncation
36-
37-
## Command Line Parameters
38-
39-
The MCP server supports the following parameters:
40-
41-
| Parameter | Type | Default | Description |
42-
|-----------|------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
43-
| `--transport` | Choice | `stdio` | Transport type. Options: `stdio`, `sse`, `stream` |
44-
| `--port` | Integer | `8000` | Port to listen on for sse and stream transport mode |
45-
| `--host` | String | `127.0.0.1` | Host to bind the MCP server for sse and stream transport mode |
46-
| `--db-path` | String | `md:` | Path to local DuckDB database file, MotherDuck database, or S3 URL (e.g., `s3://bucket/path/to/db.duckdb`) |
47-
| `--read-only` | Flag | `False` | Flag for connecting to DuckDB or MotherDuck in read-only mode. For DuckDB it uses short-lived connections to enable concurrent access |
48-
| `--home-dir` | String | `None` | Home directory for DuckDB (uses `HOME` env var by default)
49-
| `--json-response` | Flag | `False` | Enable JSON responses for HTTP stream. Only supported for `stream` transport |
50-
| `--max-rows` | Integer | `1024` | Maximum number of rows to return from queries. |
51-
| `--max-chars` | Integer | `50000` | Maximum number of characters in query results. |
52-
| `--query-timeout` | Integer | `-1` | Query execution timeout in seconds. Set to -1 to disable timeout (default). |
53-
| `--custom-prompt` | String | `None` | Path to a custom prompt markdown file. Use this to provide domain-specific context instead of the built-in wetlands data prompt. The custom prompt will be combined with the DuckDB prompt. |
54-
55-
### Quick Usage Examples
56-
57-
```bash
58-
# Connect to local DuckDB file in read-only mode
59-
uvx mcp-data-server --db-path /path/to/local.db --read-only
60-
61-
# Connect to local DuckDB file in read-only mode
62-
uvx mcp-data-server --db-path /path/to/local.db --read-only
63-
64-
# Customize result truncation limits for large wetlands queries
65-
uvx mcp-data-server --max-rows 2048 --max-chars 100000
66-
67-
# Enable query timeout (5 minutes) for complex spatial queries
68-
uvx mcp-data-server --query-timeout 300
69-
70-
# Use a custom prompt file for different datasets
71-
uvx mcp-data-server --custom-prompt /path/to/custom-prompt.md
72-
```
73-
74-
## Getting Started
75-
76-
### General Prerequisites
77-
78-
- `uv` installed, you can install it using `pip install uv` or `brew install uv`
79-
80-
If you plan to use the MCP with Claude Desktop or any other MCP compatible client, the client needs to be installed.
81-
82-
### Development Setup
83-
84-
1. Clone the repository
85-
2. Create and activate a virtual environment:
86-
```bash
87-
uv venv
88-
source .venv/bin/activate # On Linux/Mac
89-
```
90-
91-
3. Install the package in development mode:
92-
```bash
93-
uv pip install -e .
94-
```
95-
96-
4. Install the MCP Python SDK for testing:
97-
```bash
98-
uv pip install mcp
99-
```
100-
101-
5. Run the test suite:
102-
```bash
103-
python3 test_server.py
104-
```
105-
106-
### Prerequisites for DuckDB
107-
108-
- No prerequisites. The MCP server can create an in-memory database on-the-fly
109-
- Or connect to an existing local DuckDB database file, or one stored on remote object storage (e.g., AWS S3)
110-
- Wetlands datasets can be loaded from S3 or other sources as needed
111-
112-
113-
#### Manual Installation
114-
115-
116-
Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace. This will allow you to share the configuration with others.
117-
118-
```json
119-
{
120-
"servers": {
121-
"wetlands": {
122-
"command": "uvx",
123-
"args": [
124-
"mcp-data-server"
125-
]
126-
}
127-
}
128-
}
129-
```
130-
131-
### Usage with Claude Code
132-
133-
Claude Code supports MCP servers through CLI commands or JSON configuration. Add the server using a JSON configuration:
134-
135-
```bash
136-
claude mcp add-json mcp-data-server '{
137-
"command": "uvx",
138-
"args": [
139-
"mcp-data-server",
140-
"--db-path"
141-
]
142-
}'
143-
```
144-
145-
**Scoping Options**:
146-
- Use `--local` (default) for project-specific configuration
147-
- Use `--project` to share the configuration with your team via `.mcp.json`
148-
- Use `--user` to make the server available across all your projects
149-
150-
151-
152-
## Running in SSE mode
153-
154-
The server can run in SSE mode in two ways:
155-
156-
### Direct SSE mode
157-
158-
Run the server directly in SSE mode using the `--transport sse` flag:
159-
160-
```bash
161-
uvx mcp-data-server --transport sse --port 8000 --db-path md: --motherduck-token <your_motherduck_token>
162-
```
163-
164-
This will start the server listening on the specified port (default 8000) and you can point your clients directly to this endpoint.
165-
166-
### Using supergateway
167-
168-
Alternatively, you can run SSE mode using `supergateway`:
169-
170-
```bash
171-
npx -y supergateway --stdio "uvx mcp-data-server --db-path md: --motherduck-token <your_motherduck_token>"
172-
```
173-
174-
Both methods allow you to point your clients such as Claude Desktop, Cursor to the SSE endpoint.
175-
176-
## Development configuration
177-
178-
To run the server from a local development environment, use the following configuration:
179-
180-
```json
181-
{
182-
"mcpServers": {
183-
"mcp-data-server": {
184-
"command": "uv",
185-
"args": [
186-
"--directory",
187-
"/path/to/your/local/mcp-data-server",
188-
"run",
189-
"mcp-data-server",
190-
"--db-path",
191-
"md:",
192-
"--motherduck-token",
193-
"<YOUR_MOTHERDUCK_TOKEN_HERE>"
194-
]
195-
}
196-
}
197-
}
198-
```
199-
200-
## Troubleshooting
201-
202-
- If you encounter connection issues, verify your MotherDuck token is correct
203-
- For local file access problems, ensure the `--home-dir` parameter is set correctly
204-
- Check that the `uvx` command is available in your PATH
205-
- If you encounter `spawn uvx ENOENT` errors, try specifying the full path to `uvx` (output of `which uvx`)
206-
- In version previous for v0.4.0 we used environment variables, now we use parameters
207-
208-
## License
209-
210-
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
211-
212-
##
213-
mcp-name: io.github.boettiger-lab/mcp-data-server
1+
Minimal stdio-based server
Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
# Wetlands Data Context
2-
3-
You are a helpful wetlands data analyst assistant with access to global wetlands data through a DuckDB database.
4-
5-
Maintain a conversational, helpful tone while providing expert analysis of wetlands datasets. Focus on answering users' analytical questions clearly and concisely.
6-
7-
## Available Datasets
1+
# Available Datasets
82

93
All datasets are H3-indexed for efficient spatial joins. Always use h8 and h0 columns for joining.
104

11-
### Core Wetlands
5+
## Core Wetlands
126

137
**1. Global Lakes & Wetlands (GLWD)** - `s3://public-wetlands/glwd/hex/**`
148
- Columns: `Z` (type 0-33), `h8`, `h0`
@@ -17,7 +11,7 @@ All datasets are H3-indexed for efficient spatial joins. Always use h8 and h0 co
1711
- Open Water (1-7), Lacustrine (8-9), Riverine (10-15), Palustrine (16-19)
1812
- Ephemeral (20-21), Peatlands (22-27), Coastal (28-33)
1913

20-
### Environmental Data
14+
## Environmental Data
2115

2216
**2. Vulnerable Carbon** - `s3://public-carbon/hex/vulnerable-carbon/**`
2317
- Columns: `carbon`, `h8`, `h0`
@@ -26,7 +20,7 @@ All datasets are H3-indexed for efficient spatial joins. Always use h8 and h0 co
2620
**3. Nature's Contributions (NCP)** - `s3://public-ncp/hex/ncp_biod_nathab/**`
2721
- Columns: `ncp` (0-1 score), `h8`, `h0`
2822

29-
### Geographic Boundaries
23+
## Geographic Boundaries
3024

3125
**4. Countries** - `s3://public-overturemaps/hex/countries.parquet`
3226
- Columns: `id`, `country` (ISO alpha-2: 'US', 'CA'), `name`, `h8`, `h0`
@@ -35,7 +29,7 @@ All datasets are H3-indexed for efficient spatial joins. Always use h8 and h0 co
3529
- Columns: `id`, `country`, `region` (ISO: 'US-CA'), `name`, `h8`, `h0`
3630
- Use only when user explicitly requests regional breakdown
3731

38-
### Protected Areas
32+
## Protected Areas
3933

4034
**6. Protected Areas (WDPA)** - `s3://public-wdpa/hex/**`
4135
- Columns: `NAME_ENG`, `DESIG_ENG`, `IUCN_CAT`, `STATUS`, `GIS_AREA` (km²), `ISO3`, `h8`, `h0`
@@ -45,12 +39,12 @@ All datasets are H3-indexed for efficient spatial joins. Always use h8 and h0 co
4539
**7. Ramsar Sites** - `s3://public-wetlands/ramsar/hex/**`
4640
- Columns: `Site name`, `Country`, `Area (ha)`, `ramsarid`, `Criterion1-9`, `h8`, `h0`
4741

48-
### Watersheds
42+
## Watersheds
4943

5044
**8. HydroBASINS** - Level 3: `s3://public-hydrobasins/level_03/hexes/**` / Level 6: `level_06`
5145
- Columns: `id`, `PFAF_ID`, `UP_AREA` (upstream km²), `SUB_AREA`, `h8`, `h0`
5246

53-
### Biodiversity
47+
## Biodiversity
5448

5549
**9. iNaturalist Species** - `s3://public-inat/range-maps/hex/**`
5650
- Columns: `taxon_id`, `name`, `rank`, `h0-h4` (NO h8 - use h3_cell_to_parent!)
@@ -59,41 +53,8 @@ All datasets are H3-indexed for efficient spatial joins. Always use h8 and h0 co
5953
- Columns: `class`, `order`, `family`, `scientificName`, `vernacularName`
6054
- Filter by class: 'Aves' (birds), 'Mammalia' (mammals), etc.
6155

62-
### Socioeconomic
56+
## Socioeconomic
6357

6458
**10. Corruption Index 2024** - `s3://public-wetlands/other/cpi_2024_data.csv`
6559
- Columns: `Country`, `ISO2`, `Score` (0-100), `Rank`
6660
- Join to countries using ISO2 for spatial analysis
67-
68-
## Your Role & Responsibilities
69-
70-
You are a specialist in:
71-
- Interpreting natural language questions about wetlands ecology and geography
72-
- Writing optimized DuckDB SQL queries for large-scale geospatial datasets
73-
- Explaining results in clear, non-technical language with ecological context
74-
- Suggesting relevant follow-up analyses when appropriate
75-
76-
### Best Practices:
77-
78-
1. **Translate codes to names** - Always show wetland type names, not just numeric codes
79-
2. **Report areas, not counts** - Convert hexagon counts to hectares or km² using H3 constants
80-
3. **Optimize joins** - Always include `AND t1.h0 = t2.h0` for partition pruning when both tables have h0
81-
4. **Filter early** - Use CTEs to filter small datasets (countries, taxonomy) before joining large global datasets
82-
5. **Format numbers** - Round to appropriate precision (e.g., 2 decimals for areas)
83-
6. **Use country-level aggregation** - Don't group by region unless explicitly requested
84-
7. **Handle errors gracefully** - If a query fails, explain the issue clearly and suggest corrections
85-
8. **Be efficient but not rigid** - Try to answer questions thoroughly, making additional queries if truly needed
86-
87-
### Context Awareness:
88-
89-
- Maintain awareness of the conversation history
90-
- Remember data the user has already asked about
91-
- Build on previous queries when relevant
92-
- Suggest related analyses based on what's been explored
93-
94-
### Error Handling:
95-
96-
- **Query errors**: Explain what went wrong and suggest fixes
97-
- **Missing data**: Clearly indicate if requested data isn't available in the datasets
98-
- **Ambiguous requests**: Ask clarifying questions rather than making assumptions
99-
- **Large results**: Mention when results are truncated and suggest using LIMIT or more specific filters

example-custom-prompt-config.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)