Contributing to Couchbase MCP Server
June 1, 2026 ยท View on GitHub
Thank you for your interest in contributing to the Couchbase MCP Server! This guide will help you set up your development environment and understand our development workflow.
๐ Development Setup
Prerequisites
- Python 3.10+: Required for the project
- uv: Fast Python package installer and dependency manager
- Git: For version control
- VS Code (recommended): With Python extension for the best development experience
Clone and Setup
# Clone the repository
git clone https://github.com/Couchbase-Ecosystem/mcp-server-couchbase.git
cd mcp-server-couchbase
Note: External contributors do not have commit permissions on the main repository. Fork the repo to your own GitHub account and clone your fork instead of this repo.
# Install dependencies (including development tools)
uv sync --extra dev
Install Development Tools
# Install pre-commit hooks (runs linting on every commit)
uv run pre-commit install
# Verify installation
uv run pre-commit run --all-files
๐งน Code Quality & Linting
We use Ruff for fast linting and code formatting to maintain consistent code quality.
Manual Linting
# Check code quality (no changes made)
./scripts/lint.sh
# or: uv run ruff check src/
# Auto-fix issues
./scripts/lint_fix.sh
# or: uv run ruff check src/ --fix && uv run ruff format src/
Automatic Linting
- Pre-commit hooks: Ruff runs automatically on every
git commit - VS Code: Auto-format on save using Ruff extension
Linting Rules
Our Ruff configuration includes:
- Code style: PEP 8 compliance with 88-character line limit
- Import organization: Automatic import sorting and cleanup
- Code quality: Detection of unused variables, simplification opportunities
- Modern Python: Encourages modern Python patterns with
pyupgrade
๐ Adding New Features
Before You Start
- Check existing issues to see if someone is already working on it
- Open an issue to discuss larger changes
- Review the codebase to understand existing patterns
Implementation Guidelines
- Follow existing patterns: Look at similar tools for guidance
- Use the utility modules: Leverage existing connection and context management
- Add proper logging: Use the hierarchical logging system
- Handle errors gracefully: Provide helpful error messages
- Consider read-only mode: If your tool modifies data, respect
read_only_modesettings - Update documentation: Update README.md, DOCKER.md, and the docs site (in the Couchbase-Ecosystem/mcp-server-couchbase-docs repo, under
versioned_docs/version-<X>/) if adding user-facing features
๐๏ธ Project Structure
mcp-server-couchbase/
โโโ src/
โ โโโ mcp_server.py # MCP server entry point (uv run src/mcp_server.py)
โ โโโ providers/ # Standalone-host ClusterProvider implementations
โ โ โโโ __init__.py
โ โ โโโ static.py # StaticClusterProvider used by mcp_server.py
โ โโโ cb_mcp/ # Reusable Python package shared with other implementations
โ โโโ __init__.py # Package marker
โ โโโ tool_registration.py # Shared tool preparation for MCP server: parse, filter, wrap with confirmation
โ โโโ core/ # Host-agnostic contracts (ClusterProvider, ...)
โ โ โโโ __init__.py
โ โ โโโ contracts.py
โ โโโ certs/ # SSL/TLS certificates
โ โ โโโ __init__.py # Package marker
โ โ โโโ capella_root_ca.pem # Capella root CA certificate (for Capella connections)
โ โโโ tools/ # MCP tool implementations
โ โ โโโ __init__.py # Tool exports and ALL_TOOLS list
โ โ โโโ server.py # Server status and connection tools
โ โ โโโ kv.py # Key-value operations (CRUD)
โ โ โโโ query.py # SQL++ Query based tools
โ โ โโโ index.py # Index operations and recommendations
โ โโโ utils/ # Utility modules
โ โโโ __init__.py # Utility exports
โ โโโ constants.py # Project constants
โ โโโ config.py # Configuration management
โ โโโ connection.py # Couchbase connection handling
โ โโโ context.py # Application context management
โ โโโ elicitation.py # Confirmation/elicitation support
โ โโโ index_utils.py # Index-related helper functions
โ โโโ query_utils.py # Query-related helper functions
โโโ scripts/ # Development scripts
โ โโโ lint.sh # Manual linting script
โ โโโ lint_fix.sh # Auto-fix linting issues
โ โโโ setup_test_data.py # Setup script for integration tests
โ โโโ update_version.sh # Script to bump package version
โโโ tests/ # Test suite
โ โโโ conftest.py # Shared test fixtures
โ โโโ test_confirmation_tools.py # Tests for confirmation/elicitation
โ โโโ test_index_tools.py # Tests for index tools
โ โโโ test_is_explain_statement.py # Tests for EXPLAIN detection
โ โโโ test_kv_tools.py # Tests for KV operations
โ โโโ test_mcp_integration.py # MCP integration tests
โ โโโ test_parse_tool_names.py # Tests for tool name parsing
โ โโโ test_performance_tools.py # Tests for performance analysis tools
โ โโโ test_query_plan_evaluation.py # Tests for query plan evaluation
โ โโโ test_query_tools.py # Tests for query tools
โ โโโ test_read_only_mode.py # Tests for read-only mode
โ โโโ test_server_configuration_status_tool.py # Tests for server configuration status
โ โโโ test_server_tools.py # Tests for server tools
โ โโโ test_tool_registration.py # Tests for tool registration
โ โโโ test_utils.py # Tests for utility functions
โโโ .pre-commit-config.yaml # Pre-commit hook configuration
โโโ build.sh # Docker image build script
โโโ Dockerfile # Docker container definition
โโโ DOCKER.md # Docker usage documentation
โโโ glama.json # Glama MCP catalog metadata
โโโ LICENSE # Apache 2.0 license
โโโ pyproject.toml # Project dependencies and Ruff config
โโโ RELEASE.md # Release process documentation
โโโ server.json # MCP Registry configuration
โโโ smithery.yaml # Smithery.ai deployment config
โโโ CONTRIBUTING.md # Contribution Guide
โโโ README.md # Usage
๐ ๏ธ Development Workflow
Making Changes
-
Create a branch for your feature/fix:
git checkout -b feature/your-feature-name -
Make your changes following the existing patterns
-
Test your changes:
# Run linting ./scripts/lint.sh # Test the MCP server uv run src/mcp_server.py --help -
Commit your changes:
git add . git commit -m "feat: add your feature description"The pre-commit hooks will automatically run and fix any formatting issues.
Adding New Tools
When adding new MCP tools:
- Create the tool function in the appropriate module under
src/cb_mcp/tools/(server.py,kv.py,query.py, orindex.py) - Export the tool in
src/cb_mcp/tools/__init__.pyand add it to__all__ - Add to the correct tool list in
src/cb_mcp/tools/__init__.py:READ_ONLY_TOOLSif it only reads data, orKV_WRITE_TOOLSif it modifies data (so it's excluded under read-only mode) - Add an entry to
TOOL_ANNOTATIONSin the same file with the appropriate hints (readOnlyHint,idempotentHint,destructiveHint) - Write tests for the new tool in the
tests/directory - Test the tool with an MCP client
Code Style Guidelines
- Line length: 88 characters (enforced by Ruff)
- Import organization: Use isort-style grouping (standard library, third-party, local)
- Type hints: Use modern Python type hints where helpful
- Docstrings: Add docstrings for public functions and classes
- Error handling: Include appropriate exception handling with logging
๐งช Testing
Manual Testing
Currently, testing is done manually with MCP clients:
- Set up environment variables for your Couchbase cluster
- Run the server with an MCP client like Claude Desktop
- Test tool functionality through the client interface
Automated Tests
Ensure all existing tests pass so your changes don't break anything. The project has a comprehensive test suite in the tests/ directory:
# Run all tests
uv run pytest
# Run a specific test file
uv run pytest tests/test_query_tools.py
# Run tests with verbose output
uv run pytest -v
Setting Up Test Data
For integration tests that need a running Couchbase cluster:
# Set required environment variables
export CB_CONNECTION_STRING="couchbase://localhost"
export CB_USERNAME="username"
export CB_PASSWORD="password"
export CB_MCP_TEST_BUCKET="travel-sample"
# Run the setup script to create indexes and populate test data
uv run scripts/setup_test_data.py
Test Categories
- Unit tests: Test individual functions and utilities (e.g.,
test_utils.py,test_parse_tool_names.py) - Tool tests: Test each tool category (e.g.,
test_kv_tools.py,test_query_tools.py,test_index_tools.py) - Feature tests: Test specific features like read-only mode (
test_read_only_mode.py), confirmation tools (test_confirmation_tools.py), and query plan evaluation (test_query_plan_evaluation.py) - Integration tests: Test MCP server integration (
test_mcp_integration.py)
Writing Tests
When adding new features or tools, add corresponding tests:
- Create a test file in
tests/following thetest_*.pynaming convention - Use shared fixtures from
conftest.py - Test both success and error paths
- Test read-only mode interactions if your tool performs write operations
๐ค Submitting Changes
-
Run final checks:
# Ensure all linting passes ./scripts/lint.sh # Test with pre-commit uv run pre-commit run --all-files -
Push your branch and create a pull request (PR)
If you are working on a forked version of the repo, follow these instructions to create the PR.
-
Describe your changes in the PR description:
- What does this change do?
- Why is this change needed?
- How have you tested it?
๐ก Tips for Contributors
Common Development Tasks
# Install new dependencies
uv add package-name
# Install new dev dependencies
uv add --dev package-name
# Update all package dependencies to the latest compatible versions
uv sync --upgrade
# Update specific package to the latest compatible version
uv sync --upgrade-package package-name
# Run the server for testing
uv run src/mcp_server.py --connection-string "..." --username "..." --password "..."
# Run with write operations enabled
uv run src/mcp_server.py --connection-string "..." --username "..." --password "..." --read-only-mode false
# Run with confirmation required for specific tools
uv run src/mcp_server.py --connection-string "..." --username "..." --password "..." --confirmation-required-tools "delete_document_by_id,replace_document_by_id"
# Run with specific tools disabled
uv run src/mcp_server.py --connection-string "..." --username "..." --password "..." --disabled-tools "upsert_document_by_id,delete_document_by_id"
Debugging
- Use logging: The project uses hierarchical logging with the pattern
logger = logging.getLogger(f"{MCP_SERVER_NAME}.module.name") - Check connection: Ensure your Couchbase cluster is accessible
- Validate configuration: Make sure all required environment variables are set
๐ Additional Resources
- Model Context Protocol Documentation
- Couchbase Python SDK Documentation
- SQL++ Query Language
- Ruff Documentation
๐ Getting Help
- Open an issue for bugs or feature requests
- Check existing issues for similar problems
- Review the code for examples and patterns
Thank you for contributing to the Couchbase MCP Server! ๐