Skip to content

Commit 62d5df8

Browse files
authored
Merge pull request #2 from Razee4315/feat/comses
feat: CoMSES Net integration (5 tools + 1 prompt)
2 parents 89102c8 + 29b0497 commit 62d5df8

13 files changed

Lines changed: 2768 additions & 5 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ exports/worlds/*.csv
4343

4444
# Auto-created models (from create_model tool)
4545
models/_created_*.nlogox
46+
47+
# Claude Code session scratch (worktrees, session state)
48+
.claude/
49+
50+
# COMSES download cache — live data, not source
51+
models/comses/

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added — CoMSES Net integration
11+
12+
- 5 new tools for exploring the CoMSES Net computational model library:
13+
`search_comses`, `get_comses_model`, `download_comses_model`,
14+
`open_comses_model`, `read_comses_files`.
15+
- 1 new prompt: `explore_comses` — NetLogo-first, source-introspection,
16+
never fabricates commands, stops-and-asks on runtime errors.
17+
- Safe download pipeline: HEAD screen + mid-stream byte cap
18+
(`COMSES_MAX_DOWNLOAD_MB`, default 50), zip-member path-traversal
19+
validation, zip-bomb guard, atomic temp-to-final extract with
20+
`.comses_complete` marker, race reconciliation.
21+
- `"latest"` version resolution with snapshot semantics — resolved to
22+
a concrete version before any cache path is computed; the resolved
23+
version is returned so follow-up reads stay pinned.
24+
- `read_comses_files` returns a precise contract with per-file
25+
`{content, full_size, returned_size, truncated}`, priority ordering
26+
(ODD → NetLogo → other code → md/txt), byte cap with line-boundary
27+
truncation, UTF-8 decoding with `errors="replace"`, zero-match case
28+
handled explicitly.
29+
- `httpx>=0.27` dependency.
30+
- 44 new tests covering retry matrix, zip-slip, zip-bomb, marker,
31+
race-orphan, NetLogo-file selection rule, ODD discovery, cache
32+
reuse, latest resolution, truncation, extension filters, prompt rules.
33+
834
## [0.1.0] - 2025-02-23
935

1036
### Added

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,27 @@ By default, a real NetLogo window opens so you can watch your simulations run li
5959
| `save_model(name, code)` | Save model to file |
6060
| `export_world()` | Export full world state to CSV |
6161
| `list_models()` | List model files in models directory |
62+
| `search_comses(query)` | Search the CoMSES Net model library |
63+
| `get_comses_model(uuid)` | Fetch metadata + citation text for one COMSES model |
64+
| `download_comses_model(uuid)` | Safely download + extract a COMSES archive |
65+
| `open_comses_model(uuid)` | Download (or reuse cache) and load NetLogo models |
66+
| `read_comses_files(uuid)` | Read ODD / source contents from a downloaded model |
6267

63-
Plus 3 resources (primitives reference, programming guide, model source) and 3 prompts (`analyze_model`, `create_abm`, `parameter_sweep`).
68+
Plus 3 resources (primitives reference, programming guide, model source) and 4 prompts (`analyze_model`, `create_abm`, `parameter_sweep`, `explore_comses`).
69+
70+
### CoMSES Net integration
71+
72+
NetLogo MCP can search and safely fetch any model from the [CoMSES Net computational model library](https://www.comses.net/) — the largest peer-reviewed ABM repository. NetLogo models load automatically; Python / R / Julia models are identified and cached locally so you can inspect their source and ODD documentation from any MCP client, including clients with no filesystem tools.
73+
74+
Try it with the `explore_comses` prompt or just ask: *"Find me a predator-prey ABM on COMSES and run a short baseline."*
75+
76+
Safety properties (applied to every download):
77+
- Archives streamed with a hard byte cap (`COMSES_MAX_DOWNLOAD_MB`, default 50 MB) enforced mid-stream, not just via HEAD.
78+
- Every zip member is path-traversal-validated before extraction.
79+
- Zip-bomb refusal on uncompressed-size overflow.
80+
- Extraction is atomic: downloads land in a temp dir first, then move to the cache only on success.
81+
- Cache directories are trusted only when they carry the `.comses_complete` marker.
82+
- `"latest"` is resolved to a concrete version before any cache path is computed; the resolved version is returned to the AI so follow-up reads stay pinned to the same slot.
6483

6584
## Prerequisites
6685

@@ -163,6 +182,7 @@ JAVA_HOME=C:/Program Files/Eclipse Adoptium/jdk-25.0.2.10-hotspot
163182
| `NETLOGO_MODELS_DIR` | No | Directory for model files (defaults to `./models`) |
164183
| `NETLOGO_GUI` | No | `"true"` (default) for live GUI window, `"false"` for headless |
165184
| `NETLOGO_EXPORTS_DIR` | No | Directory for exported views/worlds (defaults to `./exports`) |
185+
| `COMSES_MAX_DOWNLOAD_MB` | No | Max CoMSES archive size in MB (default 50). Enforced mid-stream. |
166186

167187
## Client Setup
168188

docs/DEVELOPMENT.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ NetLogo_MCP/
1616
├── src/
1717
│ └── netlogo_mcp/
1818
│ ├── server.py # FastMCP app, stdout protection, lifespan
19-
│ ├── tools.py # All 12 tools
19+
│ ├── tools.py # All 17 tools (12 NetLogo + 5 CoMSES)
20+
│ ├── comses.py # CoMSES Net API client + safe zip extract
2021
│ ├── resources.py # 3 resources (docs + model source)
21-
│ ├── prompts.py # 3 prompts (analyze, create, sweep)
22+
│ ├── prompts.py # 4 prompts (analyze, create, sweep, explore_comses)
2223
│ ├── config.py # Environment variable loading
2324
│ ├── py.typed # PEP 561 type marker
2425
│ └── data/
@@ -30,7 +31,9 @@ NetLogo_MCP/
3031
├── conftest.py # Mock fixtures (no JVM needed)
3132
├── test_server.py
3233
├── test_tools.py
33-
└── test_resources.py
34+
├── test_comses.py # CoMSES integration: API, zip safety, tools, prompt
35+
├── test_resources.py
36+
└── fixtures/comses/ # Captured JSON fixtures for CoMSES tests
3437
```
3538

3639
## Tech Stack

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"pandas",
1717
"numpy",
1818
"python-dotenv",
19+
"httpx>=0.27",
1920
]
2021

2122
[project.optional-dependencies]

0 commit comments

Comments
 (0)