Skip to content

Follow-up improvements from PR #5 (tenant-scoped manager storage) #8

@andylim-duo

Description

@andylim-duo

Context

PR #5 introduced composite (tenant_id, name) keyed storage across ToolManager, ResourceManager, and PromptManager. The implementation is solid and backward compatible, but a few improvements were identified during review.

Follow-up items

  • add_template doesn't warn on duplicates — Unlike add_resource, add_tool, and add_prompt, ResourceManager.add_template() silently overwrites an existing template for the same (tenant_id, uri_template) key. It should follow the same pattern: return the existing entry and optionally warn.

  • list_* methods are O(n) scans — Every list_tools/list_resources/list_prompts call iterates the entire dict filtering by tenant_id. Consider a nested dict structure (dict[str | None, dict[str, T]]) for O(1) lookups if tenant count grows. Low priority — fine for now.

  • Existing test directly sets internal statetest_resource_manager.py::TestResourceManager::test_get_resource_from_template manually assigns to manager._templates[(None, template.uri_template)] instead of using manager.add_template(). Should be refactored to use the public API.

  • No remove_resource / remove_prompt methodsToolManager has remove_tool with tenant support, but the other two managers lack remove methods. Will likely be needed for tenant lifecycle management (e.g., tenant teardown).

  • Thread safety of plain dict storage — The storage dicts are not thread-safe. If multiple async tasks register entries for different tenants concurrently, there could be race conditions. Pre-existing concern, but multi-tenancy increases the likelihood of concurrent access.

  • Tests construct Context() with no argstest_multi_tenancy_managers.py creates bare Context() instances. If Context.__init__ signature changes in later iterations, these tests will break. Consider a test fixture or factory for constructing test contexts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions