MCP (Model Context Protocol) is an open-source protocol introduced and released by Anthropic in November 2024. It enables large language models to interact with external tools or data sources. With MCP, users can directly instruct tools to perform specific actions without manually copying and executing the model's output.
OceanBase MCP Server provides the capability for large language models to interact with OceanBase Database through the MCP protocol. It can execute SQL statements. With a suitable client, you can quickly build project prototypes. It has been open-sourced on GitHub.
Claude Code is an AI-powered coding tool developed by Anthropic. It runs in the terminal as an intelligent coding assistant that helps developers quickly turn ideas into high-quality code.
This topic demonstrates how to build a backend application with OceanBase MCP Server using Claude Code.
Prerequisites
You have deployed OceanBase Database and created a MySQL-compatible tenant. For more information, see Create a tenant.
You have installed Python 3.11 or later and the corresponding pip. If your machine has a lower Python version, you can use Miniconda to create a new Python 3.11 or later environment. For more information, see Miniconda installation guide.
You have installed Git based on your operating system:
Windows: https://git-scm.com/downloads/win
macOS: https://git-scm.com/download/mac
Linux: https://git-scm.com/downloads/linux
You have installed the Python package manager uv.
For macOS/Linux, run the following script:
curl -LsSf https://astral.sh/uv/install.sh | shFor Windows, run the following script:
irm https://astral.sh/uv/install.ps1 | iexOr use the platform-independent pip installation:
pip install uv
After installation, run
uv --versionto verify:pip install uv uv --versionClaude Code installation:
Open VS Code (install it from the official documentation if needed).
Click the Extensions icon in the sidebar.
Search for "Claude Code" and click Install.

Configure the Claude Code environment variables.
cat >> ~/.zshrc << 'EOF' export ANTHROPIC_BASE_URL=***** export ANTHROPIC_API_KEY=******* export ANTHROPIC_MODEL=******* EOF source ~/.zshrcTest the connection.

Select the Anthropic model.
Step 1: Obtain the database connection information
Contact the deployment personnel or administrator of OceanBase Database to obtain the database connection string. For example:
obclient -h$host -P$port -u$user_name -p$password -D$database_name
Parameter description:
$host: The IP address for connecting to OceanBase Database. For connection through OceanBase Database Proxy (ODP), use the ODP address. For direct connection, use the IP address of an OBServer node.$port: The port for connecting to OceanBase Database. For connection through ODP, the default value is2883. For direct connection, the default value is2881.$database_name: The name of the database to be accessed.Notice
The user connecting to the tenant must have the
CREATE,INSERT,DROP, andSELECTprivileges on the database. For more information, see Privilege types in MySQL-compatible mode.$user_name: The tenant account. For connection through ODP, the format isusername@tenant name#cluster nameorcluster name:tenant name:username. For direct connection, the format isusername@tenant name.$password: The account password.
For more information about the connection string, see Connect to an OceanBase tenant by using OBClient.
Step 2: Configure OceanBase MCP Server
Clone the OceanBase MCP Server repository
Run the following command to download the source code to your local machine:
git clone https://github.com/oceanbase/awesome-oceanbase-mcp.git
Navigate to the source code directory:
cd awesome-oceanbase-mcp
Install dependencies
In the oceanbase_mcp_server directory, run the following commands to create a virtual environment and install dependencies:
uv venv
source .venv/bin/activate
uv pip install .
Configure OceanBase MCP Server
Open the VS Code terminal and run the
claude mcp add-jsoncommand: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": "***" } }'Replace
/path/to/your/oceanbase_mcp_serverwith the absolute path of theoceanbase_mcp_serverfolder. ReplaceOB_HOST,OB_PORT,OB_USER,OB_PASSWORD, andOB_DATABASEwith your database information.Verify whether you can connect to the database.
Enter the prompt "How many tables are in the test database?". Claude Code will display the SQL statement to be executed and output the query result:
Claude Code will display the number of tables in the test database, indicating that you can successfully connect to OceanBase Database.
Step 3: Use FastAPI to quickly create a RESTful API project
FastAPI is a Python web framework that allows you to quickly build RESTful APIs.
Create a table.
Enter the prompt "Create a customer table with ID as the primary key and containing fields such as name, age, telephone, and location":
Insert test data.
Enter the prompt "Insert 10 pieces of test data":
Create a FastAPI project.
Enter the prompt "Create a FastAPI project that generates a RESTful API based on the customer table". Multiple files will be automatically generated. You can make secondary modifications if there are any issues.
Run the following command to install dependencies:
cd customer_api pip install -r requirements.txtStart the FastAPI project.
python3 main.pyView the data in the table.
Run
curl http://127.0.0.1:8000/customersin the command line or use other request tools to view the data in the table:curl http://127.0.0.1:8000/customers [{"name":"Alice","age":28,"telephone":"555-0101","location":"New York","ID":1},{"name":"Bob","age":35,"telephone":"555-0102","location":"Los Angeles","ID":2},{"name":"Carol","age":42,"telephone":"555-0103","location":"Chicago","ID":3},{"name":"David","age":31,"telephone":"555-0104","location":"Houston","ID":4},{"name":"Eve","age":26,"telephone":"555-0105","location":"Phoenix","ID":5},{"name":"Frank","age":39,"telephone":"555-0106","location":"Philadelphia","ID":6},{"name":"Grace","age":33,"telephone":"555-0107","location":"San Antonio","ID":7},{"name":"Henry","age":45,"telephone":"555-0108","location":"San Diego","ID":8},{"name":"Ivy","age":29,"telephone":"555-0109","location":"Dallas","ID":9},{"name":"Jack","age":37,"telephone":"555-0110","location":"San Jose","ID":10}]The create, read, update, and delete (CRUD) code has been generated.
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()