Skip to content

Tools

Utility scripts are located in src/tools/.


Sets up the database, its collections/indexes, and optionally an application user — the one-time step before pointing the server at a fresh MongoDB instance.

ObjectPurpose
Collection resourcesresource content + its analysis
Collection namespace_entriesnamespace-to-resource membership
Index analysis_idxsparse, on resources.analysis — speeds up the unanalysed-lookup query
Index ns_idxon namespace_entries.namespace
Index hash_idxon namespace_entries.hash
Application user (optional)readWrite on the target database

Every step is safe to re-run — anything that already exists is reported and skipped rather than recreated.

Terminal window
# Read connection settings from configs/opentremor-core-local.yaml
python src/tools/init_mongo.py
# Connect with admin credentials explicitly
python src/tools/init_mongo.py --uri mongodb://admin:secret@localhost:27017
# ...and provision an application user in the same run
python src/tools/init_mongo.py \
--uri mongodb://admin:secret@localhost:27017 \
--app-user mcp_app \
--app-password changeme
# See the steps without touching the database
python src/tools/init_mongo.py --plan
# Point at a specific config file
python src/tools/init_mongo.py --config /etc/mcp/config.yaml
FlagDefaultDescription
--config FILEconfigs/opentremor-core-local.yamlconfig file to read connection settings from
--uri URIfrom configMongoDB URI, admin credentials
--database NAMEfrom configtarget database
--resources-collection NAMEfrom configname for the resources collection
--entries-collection NAMEfrom configname for the namespace-entries collection
--app-user USERapplication username to provision
--app-password PASSpassword for --app-user
--planprint the steps, make no changes
Terminal window
pip install pymongo pyyaml
# already covered if you installed via Poetry:
poetry install
target: mongodb://localhost:27017 (database 'mcp_analyzer')
collections: resources, namespace_entries
application user: mcp_app
proceed? [y/n]: y
created collection 'resources'
created index 'analysis_idx' on 'resources'
created collection 'namespace_entries'
created index 'ns_idx' on 'namespace_entries'
created index 'hash_idx' on 'namespace_entries'
created user 'mcp_app' (readWrite on 'mcp_analyzer')
done.

grant_superadmin.py — bootstrap a platform admin

Section titled “grant_superadmin.py — bootstrap a platform admin”

Grants or revokes is_superadmin — a permission axis independent of any org’s role, gating the cross-tenant Platform Admin surface (GET /admin/*). There is no in-app way to mint the first superadmin — POST /admin/users/{user_id}/superadmin itself requires one already — so this script writes the flag directly to MongoDB for an already-registered user (POST /auth/register first if needed). Every superadmin after that can be granted through the API instead.

Terminal window
# Grant, using settings from the default config file
python src/tools/grant_superadmin.py --email [email protected]
# Revoke
python src/tools/grant_superadmin.py --email [email protected] --revoke
# Explicit URI
python src/tools/grant_superadmin.py --email [email protected] --uri mongodb://localhost:27017
# Preview without making any changes
python src/tools/grant_superadmin.py --email [email protected] --dry-run
FlagDefaultDescription
--email EMAIL(required)The already-registered user to grant/revoke
--revokeRevoke instead of grant
--config FILEconfigs/opentremor-core-local.yamlYAML config to read connection settings from
--uri URIfrom configMongoDB URI
--database NAMEfrom configTarget database
--dry-runReport what would change, make no writes
Grant platform-admin status
URI: mongodb://localhost:27017
Database: mcp_analyzer
Connected to MongoDB
Granted platform-admin status for [email protected] (user_id=11a75db9-...).
They'll see it on their next login or POST /auth/session/switch —
is_superadmin is baked into the session JWT at mint time, like org_id/role.