The DirectFileResourceLoader now supports:
- ✅ Disk caching with commit-hash-based invalidation
- ✅ Hot-reload for automatic updates on
git pull - ✅ Fast startup (~100ms from cache vs ~30s+ cold scan)
- ✅ Automatic cache cleanup
-
First Scan:
- Scans 3 canonical repos (daml, canton, daml-finance)
- Gets commit hash for each repo
- Saves scan results to
~/.canton-mcp/resource-cache-{hashes}.json
-
Subsequent Starts:
- Checks current commit hashes
- Looks for matching cache file
- Loads instantly if found (~100ms)
- Falls back to full scan if cache miss
-
Cache Invalidation:
- Automatic when any repo's commit hash changes
- Manual: delete
~/.canton-mcp/resource-cache-*.jsonfiles
When enabled via CANTON_HOT_RELOAD=true:
- Watches all 3 canonical repo directories
- Detects file changes (e.g., after
git pull) - Checks if commit hashes changed
- Automatically re-scans and updates cache
- Debounced to handle multi-file git pulls efficiently (2 second delay)
# First run - slow (full scan)
uv run canton-mcp-server
# Subsequent runs - FAST (from cache)
uv run canton-mcp-server# Enable hot-reload
export CANTON_HOT_RELOAD=true
uv run canton-mcp-server
# In another terminal, update a repo
cd /Users/martinmaurer/Projects/Martin/canonical-daml-docs/daml
git pull
# Server automatically detects change and reloads!First Run (Cold Start):
INFO | Scanning cloned repositories for documentation files...
INFO | Scanning repository: daml
INFO | Found 2145 documentation files in daml
INFO | Scanning repository: canton
INFO | Found 876 documentation files in canton
INFO | Scanning repository: daml-finance
INFO | Found 123 documentation files in daml-finance
INFO | Found 3144 documentation files across all repositories
INFO | 💾 Saved to disk cache: resource-cache-daml-abc12345-canton-def67890-daml-finance-ghi11223.json
Second Run (Warm Start):
INFO | ✅ Loaded from disk cache: resource-cache-daml-abc12345-canton-def67890-daml-finance-ghi11223.json
INFO | Loaded 3144 resources from disk cache
Hot-Reload After Git Pull:
INFO | 🔥 Started hot-reload watcher for canonical repositories
INFO | Canonical repo file changed: /path/to/daml/some-file.md
INFO | 📦 Commit hashes changed: daml(abc12345→xyz98765)
INFO | 🔄 Reloading canonical resources...
INFO | Scanning cloned repositories for documentation files...
INFO | Found 3145 documentation files across all repositories
INFO | 💾 Saved to disk cache: resource-cache-daml-xyz98765-canton-def67890-daml-finance-ghi11223.json
INFO | ✅ Resources reloaded after git pull
Cache files are stored in:
~/.canton-mcp/resource-cache-{commit-hashes}.json
Example filename:
resource-cache-daml-abc12345-canton-def67890-daml-finance-ghi11223.json
Old cache files are automatically cleaned up when new ones are created.
CANONICAL_DOCS_PATH: Path to canonical docs (default:/Users/martinmaurer/Projects/Martin/canonical-daml-docs)CANTON_HOT_RELOAD: Enable hot-reload watching (default:false)
export CANONICAL_DOCS_PATH=/path/to/canonical-daml-docs
export CANTON_HOT_RELOAD=true
uv run canton-mcp-serverRun the test script:
./test_caching.shThis will:
- Test cold start (no cache)
- Verify cache creation
- Test warm start (with cache)
- Show hot-reload instructions
- Every startup: 30-60 seconds (full scan)
- After git pull: Manual server restart required
- First startup: 30-60 seconds (full scan + save cache)
- Subsequent startups: ~100ms (load from cache)
- After git pull (hot-reload enabled): Automatic reload (~30s scan)
- After git pull (hot-reload disabled): Next startup detects change, loads new cache
-
src/canton_mcp_server/core/direct_file_loader.py:- Added
CanonicalRepoFileHandlerfor hot-reload - Added disk caching methods
- Added commit hash checking
- Added file watcher management
- Added
-
src/canton_mcp_server/handlers/resource_handler.py:- Integrated
CANTON_HOT_RELOADenvironment variable - Pass hot-reload flag to
DirectFileResourceLoader
- Integrated
_get_all_commit_hashes(): Get current commit hashes for all repos_load_from_disk_cache(): Load cached resources by commit hashes_save_to_disk_cache(): Save resources with commit hashes_start_file_watcher(): Start watchdog observer for hot-reload_check_and_reload_on_commit_change(): Detect git pulls and reload
- Check
~/.canton-mcp/.jsonexists - Verify commit hashes match current repos
- Look for "Cache commit hashes don't match" warning
- Ensure
CANTON_HOT_RELOAD=trueis set - Check logs for "🔥 Started hot-reload watcher"
- Verify file changes are detected (look for "Canonical repo file changed")
- Wait 2 seconds after git pull (debounce delay)
- Cache file contains full resource data (~10-20MB for 3k+ files)
- This is normal and necessary for fast loading
- Only one cache file per commit hash combination
# Option 1: Delete cache
rm ~/.canton-mcp/resource-cache-*.json
# Option 2: Pass force_refresh (requires code change)
loader.scan_repositories(force_refresh=True)Potential improvements:
- Add
--clear-cacheCLI flag - Add cache compression (gzip)
- Add cache statistics/metrics
- Add incremental scanning (only changed files)
- Add cache expiration (time-based)