Skip to content

Conversation

nithishr
Copy link
Contributor

No description provided.

- Introduced `connect_to_bucket` utility to establish bucket connections using the cluster context.
- Updated relevant functions to accept `bucket_name` as an argument where necessary, improving flexibility in handling Couchbase operations.
- Enhanced documentation and logging for better clarity on connection status and error handling.
…able usage

- Added new features for retrieving bucket, scope, and collection lists in the MCP server.
- Removed references to `CB_BUCKET_NAME` from environment variable sections
@nithishr nithishr marked this pull request as ready for review August 21, 2025 08:33
@nithishr nithishr requested a review from Copilot August 21, 2025 08:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the codebase to support multiple buckets instead of being limited to a single bucket. The changes remove bucket-specific configuration requirements and enable dynamic bucket access through function parameters.

Key changes:

  • Removes bucket-specific configuration and validation logic
  • Updates all bucket-dependent functions to accept bucket_name as a parameter
  • Adds new helper functions for bucket, scope, and collection discovery

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/context.py Removes bucket context management and validation, simplifies cluster connection logic
src/utils/connection.py Removes logging statement from bucket connection function
src/utils/config.py Removes validation functions for required parameters
src/utils/init.py Updates exports to reflect removed validation functions and context changes
src/tools/server.py Adds bucket discovery functions and updates existing functions to accept bucket parameters
src/tools/query.py Updates query functions to accept bucket_name parameter
src/tools/kv.py Updates key-value operations to accept bucket_name parameter
src/tools/init.py Adds new bucket discovery functions to exports
src/mcp_server.py Removes bucket-name CLI option and configuration
README.md Updates documentation to reflect removal of bucket configuration requirement

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

# Test basic connectivity by getting bucket name
bucket_name = bucket.name
cluster = get_cluster_connection(ctx)
bucket = connect_to_bucket(cluster, bucket_name) if bucket_name else None
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function attempts to connect to a bucket when bucket_name is provided, but there's no validation that bucket_name is not an empty string. An empty string would pass the truthiness check but would likely cause connection issues.

Suggested change
bucket = connect_to_bucket(cluster, bucket_name) if bucket_name else None
bucket = connect_to_bucket(cluster, bucket_name) if bucket_name and bucket_name.strip() else None

Copilot uses AI. Check for mistakes.

if scope_name not in scopes_and_collections:
logger.error(f"Scope {scope_name} not found in bucket {bucket_name}")
raise ValueError(f"Scope {scope_name} not found in bucket {bucket_name}")
return scopes_and_collections[scope_name]
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function calls get_scopes_and_collections_in_bucket which retrieves all scopes and collections, but only returns collections for a specific scope. This is inefficient as it fetches unnecessary data.

Suggested change
return scopes_and_collections[scope_name]
cluster = get_cluster_connection(ctx)
bucket = connect_to_bucket(cluster, bucket_name)
try:
scopes = bucket.collections().get_all_scopes()
for scope in scopes:
if scope.name == scope_name:
return [c.name for c in scope.collections]
logger.error(f"Scope {scope_name} not found in bucket {bucket_name}")
raise ValueError(f"Scope {scope_name} not found in bucket {bucket_name}")
except Exception as e:
logger.error(f"Error getting collections in scope: {e}")
raise

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant