refactor(managers): O(1) tenant lookups and missing APIs#10
Merged
andylim-duo merged 5 commits intomainfrom Mar 17, 2026
Merged
refactor(managers): O(1) tenant lookups and missing APIs#10andylim-duo merged 5 commits intomainfrom
andylim-duo merged 5 commits intomainfrom
Conversation
…missing APIs
Convert ToolManager, ResourceManager, and PromptManager from flat
tuple-keyed dicts to nested `{tenant_id: {name: T}}` dicts, giving O(1)
per-tenant lookups instead of O(n) scans. Add duplicate-warning support
for resource templates, add remove_resource and remove_prompt methods,
document thread-safety constraints, and centralize Context construction
in tests via a make_context fixture.
Github-Issue:#8
Owner
Author
Review Notes1.
MakeContext type alias duplicated across test files |
Move the duplicated MakeContext type alias from test_multi_tenancy_managers.py and test_resource_manager.py into conftest.py as the single source of truth. Github-Issue:#8
Remove the inner dict from the outer storage when the last entry for a tenant is deleted, preventing unbounded accumulation of empty dicts in long-running servers with transient tenants. Github-Issue:#8
Add tests for ResourceManager and PromptManager where a tenant has multiple items and only one is removed, exercising the branch where the scope dict persists. Fixes 100% branch coverage requirement in CI. Github-Issue:#8
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.
Summary
Addresses all follow-up items from #8 for the tenant-scoped manager storage introduced in PR #5.
ToolManager,ResourceManager, andPromptManagerfrom flatdict[tuple[str | None, str], T]to nesteddict[str | None, dict[str, T]], giving O(1) per-tenant lookups instead of O(n) scans across all tenantsResourceManager.add_template()now warns on duplicates and returns the existing template, matching the behavior ofadd_resource()andToolManager.add_tool()ResourceManager.remove_resource()andPromptManager.remove_prompt()for parity withToolManager.remove_tool()Context()construction in amake_contextconftest fixture so tests won't break if theContext.__init__signature changes_templatesdict access with publicadd_template()API, add type annotations for pyright complianceTest plan
pytest tests/server/mcpserver/)This PR closes #8