MCP Server for NetCDF format file
Project description
NetCDF Explorer MCP Server
A simple and powerful MCP (Message Communication Protocol) server for exploring, analyzing, and interacting with NetCDF format files. Designed to simplify NetCDF data management with intuitive APIs and efficient data handling.
Overview
NetCDF (Network Common Data Form) is a widely used format for storing scientific data. This MCP server provides a streamlined interface to work with NetCDF files, offering essential functionalities to list files, inspect structures, extract data, and analyze variables—all while handling large datasets efficiently through smart sampling.
Features
- 📁 File Discovery: List all NetCDF files (
.nc,.cdf,.netcdf,.nc4) in a specified directory. - 🔍 Structure Inspection: Retrieve detailed metadata of NetCDF files, including dimensions, variables, attributes, and global properties.
- 📊 Data Extraction: Read variable data with support for flexible slicing (e.g.,
lat: "0:10:2"to extract subsets). - 🧠 Smart Sampling: Automatically sample large datasets to prevent memory overflow, with configurable element limits.
- ⏰ Time Series Analysis: Extract temporal data from spatial variables, with optional custom location coordinates.
- 🔎 Search Functionality: Find variables and attributes by keyword, simplifying navigation in complex files.
- 📋 Variable Summaries: Generate human-readable summaries of variables, including dimensions, data types, and attributes.
Installation
Prerequisites
- Python ≥ 3.13
Install via pip
pip install nc-mcp
Install from Source
-
Clone the repository:
git clone https://github.com/HanchaoLi/nc-mcp.git cd nc-mcp
-
Install dependencies (using
uvfor faster dependency management):# Install uv (if not already installed) curl -LsSf https://astral.sh/uv/install.sh | sh # Sync dependencies uv sync --all-groups
Quick Start
Start the Server
python -m nc_mcp_server.main
API Reference
Core Functions
| Function | Description | Parameters |
|---|---|---|
list_netcdf_files |
Lists all NetCDF files in a directory. | directory (str): Path to search (default: .). |
get_netcdf_info |
Returns metadata and structure of a NetCDF file (dimensions, variables, attributes). | file_path (str): Path to the NetCDF file. |
get_variable_data |
Extracts data from a specific variable (supports slicing and sampling). | file_path (str), variable_name (str), slices (dict, optional), max_elements (int, default: 1000). |
search_variables |
Searches variables and attributes for a keyword (case-insensitive). | file_path (str), search_term (str). |
extract_timeseries |
Extracts time series data from a spatial variable. | file_path (str), variable_name (str), location (dict, optional: spatial coordinates like {"lat": 10, "lon": 20}). |
Testing
Run the test suite to verify functionality:
uv run pytest tests/ -v
Tests cover:
- File discovery logic
- NetCDF structure parsing
- Data extraction with slicing
- Sampling for large datasets
- Error handling for invalid inputs
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Links
- Homepage: https://github.com/HanchaoLi/nc-mcp
- Repository: https://github.com/HanchaoLi/nc-mcp
- Issue Tracker: https://github.com/HanchaoLi/nc-mcp/issues
- PyPI: https://pypi.org/project/nc-mcp/
Author
John Li
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nc_mcp-0.1.2.tar.gz.
File metadata
- Download URL: nc_mcp-0.1.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c3f4d8049619a26070af1807c8715eec89e1395cbf89b12c4fa47bd6cd7de66
|
|
| MD5 |
9930474dcd5061359c837323493499ec
|
|
| BLAKE2b-256 |
0416989507fd3f77570412da1a678b6305fdcb407292e87800e59d8a3c8c44e1
|
Provenance
The following attestation bundles were made for nc_mcp-0.1.2.tar.gz:
Publisher:
publish.yml on HanchaoLi/nc-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nc_mcp-0.1.2.tar.gz -
Subject digest:
4c3f4d8049619a26070af1807c8715eec89e1395cbf89b12c4fa47bd6cd7de66 - Sigstore transparency entry: 427597995
- Sigstore integration time:
-
Permalink:
HanchaoLi/nc-mcp@58f6b089a44769546c69d53adc045f9464ca83b4 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/HanchaoLi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@58f6b089a44769546c69d53adc045f9464ca83b4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nc_mcp-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nc_mcp-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eca8b4455a0f333f7422661271a34758b954187cf94895ed42c53a36fa082367
|
|
| MD5 |
b7325b45d969f2d7b0f00b16a86a0eb0
|
|
| BLAKE2b-256 |
ae41bb182533fbdf8193f36bdced6b0272581c4d854f34550bbcd675911ca15b
|
Provenance
The following attestation bundles were made for nc_mcp-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on HanchaoLi/nc-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nc_mcp-0.1.2-py3-none-any.whl -
Subject digest:
eca8b4455a0f333f7422661271a34758b954187cf94895ed42c53a36fa082367 - Sigstore transparency entry: 427598010
- Sigstore integration time:
-
Permalink:
HanchaoLi/nc-mcp@58f6b089a44769546c69d53adc045f9464ca83b4 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/HanchaoLi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@58f6b089a44769546c69d53adc045f9464ca83b4 -
Trigger Event:
release
-
Statement type: