The Model Context Protocol (MCP) was introduced and open-sourced by Anthropic in November 2024. It lets large language models interact with external tools and data sources. With MCP, you don't have to copy model output and run it manually—the model can instruct tools to perform actions directly.
The OceanBase MCP Server uses MCP to give LLMs access to OceanBase Database so they can run SQL. With an MCP-capable client you can quickly prototype applications. The server is open source on GitHub.
Claude Code is an AI coding tool from Anthropic. It runs in the terminal as an intelligent coding assistant and helps developers turn ideas into production-quality code quickly.
This topic uses Claude Code to show how to build a backend application quickly with the OceanBase MCP Server.
Prerequisites
You have deployed OceanBase Database and created a MySQL-compatible tenant. For details, see Create a tenant.
You have Python 3.11 or later and pip installed. If your system Python is older, use Miniconda to create a Python 3.11+ environment.
You have Git installed for your OS:
- Windows: https://git-scm.com/downloads/win
- macOS: https://git-scm.com/download/mac
- Linux: https://git-scm.com/downloads/linux
You have the Python package manager uv installed:
macOS/Linux (standalone script):
curl -LsSf https://astral.sh/uv/install.sh | shWindows (PowerShell):
irm https://astral.sh/uv/install.ps1 | iexOr install with pip on any platform:
pip install uvVerify the installation:
uv --version
Claude Code is installed:
Open VS Code (install it from the official site if needed).
Click the Extensions icon in the sidebar.
Search for Claude Code and install it.
Configure Claude Code environment variables. For example, add the following to your shell config (e.g.
~/.zshrc):export ANTHROPIC_BASE_URL=***** export ANTHROPIC_API_KEY=******* export ANTHROPIC_MODEL=*******Then run
source ~/.zshrc(or the equivalent for your shell).Test the connection.
Select your Anthropic model.
Step 1: Get database connection details
Obtain the database connection string from your OceanBase deployment team or administrator. For example:
obclient -h$host -P$port -u$user_name -p$password -D$database_name
Parameters:
$host: The IP for connecting to OceanBase. Use an ODP address when connecting via OceanBase Database Proxy (ODP), or an OBServer IP for direct connection.$port: The connection port. ODP default is2883; direct connection default is2881. Both can be customized at deployment.$database_name: The database to use.Notice
The user connecting to the tenant must have
CREATE,INSERT,DROP, andSELECTprivileges on that database. For more on privileges, see Privilege types in MySQL-compatible mode.$user_name: The tenant account. ODP:username@tenant#clusterorcluster:tenant:username. Direct:username@tenant.$password: The account password.
For more on connection strings, see Connect to an OceanBase tenant by using OBClient.
Step 2: Configure the OceanBase MCP Server
Clone the OceanBase MCP Server repository
Download the source:
git clone https://github.com/oceanbase/awesome-oceanbase-mcp.git
Change into the project directory:
cd awesome-oceanbase-mcp
Install dependencies
From the oceanbase_mcp_server directory, create a virtual environment and install dependencies:
uv venv
source .venv/bin/activate
uv pip install .
Configure the OceanBase MCP Server
Open the terminal in VS Code and run the
claude mcp add-jsoncommand. Replace/path/to/your/oceanbase_mcp_serverwith the absolute path to theoceanbase_mcp_serverfolder, and setOB_HOST,OB_PORT,OB_USER,OB_PASSWORD, andOB_DATABASEto your database values.claude mcp add-json oceanbase '{ "command": "uv", "args": [ "--directory", "/path/to/your/oceanbase_mcp_server/src/oceanbase_mcp_server", "run", "oceanbase_mcp_server" ], "env": { "OB_HOST": "***", "OB_PORT": "***", "OB_USER": "***", "OB_PASSWORD": "***", "OB_DATABASE": "***" } }'Verify the connection. In the chat, ask: How many tables are in the test database? Claude Code will show the SQL it plans to run and then the query result.
Claude Code will show the number of tables in the
testdatabase, confirming that the connection to OceanBase is working.
Step 3: Build a RESTful API with FastAPI
FastAPI is a Python web framework well-suited for building RESTful APIs.
Create the table. Use the prompt: Create a customer table with primary key ID and columns name, age, telephone, and location.
Insert test data. Use the prompt: Insert 10 rows of test data.
Create the FastAPI project. Use the prompt: Create a FastAPI project that exposes a RESTful API for the customer table. Claude Code will generate the files. Adjust the code if anything needs to be changed.
Install dependencies.
cd customer_api pip install -r requirements.txtStart the FastAPI app.
python3 main.pyQuery the API. From a terminal or any HTTP client:
curl http://127.0.0.1:8000/customersThe response will contain the customer records. The generated code implements full CRUD (create, read, update, delete) for the
customertable.Example generated code:
from sqlalchemy.orm import Session from . import models, schemas from typing import List, Optional def get_customer(db: Session, customer_id: int): return db.query(models.Customer).filter(models.Customer.ID == customer_id).first() def get_customers(db: Session, skip: int = 0, limit: int = 100): return db.query(models.Customer).offset(skip).limit(limit).all() def create_customer(db: Session, customer: schemas.CustomerCreate): db_customer = models.Customer(**customer.dict()) db.add(db_customer) db.commit() db.refresh(db_customer) return db_customer def update_customer(db: Session, customer_id: int, customer: schemas.CustomerUpdate): db_customer = db.query(models.Customer).filter(models.Customer.ID == customer_id).first() if db_customer: update_data = customer.dict(exclude_unset=True) for key, value in update_data.items(): setattr(db_customer, key, value) db.commit() db.refresh(db_customer) return db_customer def delete_customer(db: Session, customer_id: int): db_customer = db.query(models.Customer).filter(models.Customer.ID == customer_id).first() if db_customer: db.delete(db_customer) db.commit() return True return False def search_customers(db: Session, name: Optional[str] = None, location: Optional[str] = None): query = db.query(models.Customer) if name: query = query.filter(models.Customer.name.contains(name)) if location: query = query.filter(models.Customer.location.contains(location)) return query.all()