Add scope/collection management tools (create/drop scope, create/drop/update collection, get_collection_settings) - #196
Open
celticht32 wants to merge 3 commits into
Conversation
Move Validation to RestAPI path (couchbase#194)
…/update/get_settings collection)
This was referenced Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 3 of the phased admin-tool contribution discussed in #157. Follows the same shape and safety model as #187 and #195.
What this adds
Six tools that complete the scope/collection lifecycle the server currently only reads (
get_scopes_and_collections_in_bucket,get_scopes_in_bucket,get_collections_in_scope):create_scope— creates a scope in a bucket via the SDK'sCollectionManager.create_scope.drop_scope— drops a scope and all its collections. Requires bothconfirm=Trueandconfirm_namematching the target scope exactly — matches thedelete_bucketpattern from Add bucket management tools (create/update/delete/flush/compact/load_sample) #195. Rejects_defaultscope (server would reject anyway; catching it client-side gives a clearer error).create_collection— creates a collection inside a scope. Optionalmax_expiry_seconds(0 = no TTL; None = inherit bucket default) andhistory(Couchbase 7.2+ Magma per-document history retention) settings.drop_collection— drops a collection and all its documents. Sameconfirm=True+confirm_namegate asdrop_scope. Rejects the_default/_defaultcombination (server would reject anyway).update_collection— updates mutable settings on an existing collection (max_expiry_secondsand/orhistory). At least one of the two must be provided.get_collection_settings— returns per-collection TTL and history-retention settings for a single collection (read-only; the existingget_scopes_and_collections_in_bucketdoesn't surface these).Why it's shaped this way
Follows the conventions #187 and #195 established:
ctx-first tool functions, dict returns, raise on error, registration viatools/__init__.pylists +TOOL_ANNOTATIONS.ADMIN_WRITE_TOOLS— scope/collection lifecycle loads only whenread_only_modeis false ANDadmin_write_modeis true. Scope/collection create/drop is namespace-level structural mutation and gates behind the same higher-privilege flag as index DDL and bucket lifecycle._require_write_scope()shape asindex_admin.pyandbucket_admin.py. When an OAuth token is present the caller must additionally hold the write scope.CollectionManagerrather than direct REST — matches the style of the existing scope/collection read tools intools/server.py, which also go throughbucket.collections().get_all_scopes(). No new REST helper module needed; the SDK'sCollectionSpectype handles themax_expiry(7.6+) vs.max_ttl(7.0-7.5) compatibility layer correctly.max_expiry_seconds=0maps totimedelta(seconds=0)explicitly (Couchbase semantics: "no TTL").max_expiry_seconds=Noneis left unset in theCollectionSpec(semantics: "inherit bucket default" on create, "leave unchanged" on update).get_collection_settingsis added toREAD_ONLY_TOOLS(always loaded, no admin-write flag needed), which is whytests/unit/test_read_only_mode.pyneeds the tool-count updates (21 → 22 read-only, 25 → 26 total).Testing
Unit tests in
tests/unit/test_collections_admin.py(no cluster required): timedelta conversion (None / 0 / positive / negative), write-scope gate (present / missing / no-token), argument construction for all 5 write tools, confirmation gate coverage (drop_scope and drop_collection both requireconfirm=True+ name-match), rejection of_defaultscope and_default/_defaultcombo, correctCollectionSpecconstruction for TTL and history, and get_collection_settings return shape (settings present / missing max_expiry / scope not found / collection not found).ruff checkandruff format --checkpass against pinned ruff 0.12.5.tests/unit/test_read_only_mode.pyupdated to reflect the new read-only tool count.Open questions for maintainers
Same three from #187 and #195 apply here; happy to align with whatever you decide on those PRs:
create_scope,drop_scope,create_collection,drop_collection,update_collection) to match Add index management tools (create/drop/build + GSI settings) #187's and Add bucket management tools (create/update/delete/flush/compact/load_sample) #195's conventions.--admin-write-mode/CB_MCP_ADMIN_WRITE_MODEflag Add index management tools (create/drop/build + GSI settings) #187 introduced. If you decide to collapse that intoread_only_modeon Add index management tools (create/drop/build + GSI settings) #187, I'll follow suit here.ok()/err()envelope deferred to a future PR (best done uniformly at the registration layer).Refs #157, #187, #195.