OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Database

  • Overview of the ecosystem
  • ORM frameworks
    • Java
      • Spring Boot
      • Spring Batch
      • Use Spring JDBC to connect to OceanBase Database
      • Spring Data JPA
      • Hibernate
      • MyBatis
      • jOOQ
    • Python
      • Use SQLAlchemy to connect to OceanBase Database
      • Connect to OceanBase Database by using peewee
      • Use Tortoise ORM to connect to OceanBase Database
    • Go
      • Connect to OceanBase Database by using GORM
      • beego ORM
    • Rust
      • SeaORM Connection to OceanBase Database
      • Diesel Connection to OceanBase Database
    • Ruby
      • Active Record
      • Sequel Connection to OceanBase Database
      • Connect to OceanBase Database by using Ruby on Rails
    • Node.js
      • Sequelize
      • TypeORM
      • Prisma
      • Drizzle
    • C#
      • Dapper
      • SqlSugar
      • FreeSQL
    • PHP
      • Connect to OceanBase Database by using the Yii 2.0 ORM
      • Connect to OceanBase Database by using Laravel Eloquent ORM
      • CakePHP
  • Database version management
    • Liquibase
    • Flyway
  • Data integration
    • Flink
      • Apache Flink
      • Flink DirectLoad
      • Flink Connector OceanBase
    • dbt
    • SeaTunnel
    • Maxwell
    • Debezium
    • Spark Catalog
    • NiFi
    • Qlik Replicate
    • RisingWave CDC
    • Flume
    • Migrate data from SQL Server to OceanBase Database by using MySQL Workbench
  • SQL development
    • WebLogic
    • DBeaver
    • Navicat
    • DataGrip
    • TablePlus
    • DMS
  • Orchestration and scheduling
    • Airflow
    • PowerJob
    • DolphinScheduler
    • Linkis
  • Visualization tools
    • Superset
    • Excel
    • Power BI
    • Quick BI
    • Tableau
    • GuanData
    • vividime
    • DataV
    • Metabase
    • Redash
    • FineReport
  • Database management
    • NineData
    • Bytebase
    • DataHub
    • Zabbix
  • AI
    • OpenAI
    • Qwen
    • LangChain
    • LlamaIndex
    • Dify
    • n8n
    • Trae
    • SpringAI
    • Cline
    • Cursor
    • Continue
    • MCP Toolbox
    • CamelAI
    • Firecrawl
    • Hugging Face
    • Ollama
    • Google Gemini
    • Cloudflare Workers AI
    • DB GPT
    • Jina AI
    • Augment Code
    • Claude Code
    • Kiro
    • GPT4All
  • Application
    • Ghost
    • Jira
    • Seata
    • SAP Crystal Reports
  • Middleware
    • Apache Pulsar

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Database
  3. master

Integrate OceanBase MCP Server with Trae

Last Updated:2026-09-04 07:40:45

Prerequisites
Step 1: Get database connection details
Step 2: Configure the OceanBase MCP Server
Clone the OceanBase MCP Server repository
Install dependencies
Create a Trae project directory
Configure the OceanBase MCP Server in Trae
Add and configure MCP servers
Test the MCP Server
Build a RESTful API with FastAPI

The Model Context Protocol (MCP) was introduced and open-sourced by Anthropic in November 2024. It enables large language models to interact with external tools and data sources. With MCP, you no longer need to copy model output and run it manually—the model can instruct tools to perform actions directly.

The OceanBase MCP Server uses MCP to let LLMs work with OceanBase Database: they can run SQL on your behalf. Together with an MCP-capable client, you can quickly prototype applications. The server is open source on GitHub.

Trae is an IDE that supports MCP Server integration. Download the latest version from the official site.

This topic shows how to integrate the OceanBase MCP Server with Trae IDE to build a backend application quickly.

Prerequisites

  • You have deployed OceanBase Database and created a MySQL-compatible 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.

  • You have the Python package manager uv installed. Verify with:

    pip install uv
    uv --version
    
  • You have downloaded and installed Trae IDE for your operating system.

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 is 2883 (configurable at deploy time). Direct connection default is 2881.

  • $database_name: The database to use.

    Notice

    The user connecting to the tenant must have CREATE, INSERT, DROP, and SELECT privileges on that database.

  • $user_name: The tenant account. ODP formats: username@tenant#cluster or cluster:tenant:username. Direct: username@tenant.

  • $password: The account password.

Step 2: Configure the OceanBase MCP Server

Clone the OceanBase MCP Server repository

Download the source to your machine:

git clone https://github.com/oceanbase/mcp-oceanbase.git

Change into the project directory:

cd mcp-oceanbase

Install dependencies

From the mcp-oceanbase directory, create a virtual environment and install dependencies:

uv venv
source .venv/bin/activate
uv pip install .

Create a Trae project directory

Create a folder for your Trae project and open it in Trae. Generated files will be placed here (e.g. trae-generate).

Configure the OceanBase MCP Server in Trae

Open the chat panel with Ctrl + U (Windows) or Command + U (macOS). Click the gear icon in the top-right and select MCP.

Add and configure MCP servers

  1. Click Add MCP Servers and choose Manual configuration.

  2. Replace the sample content in the editor with the configuration below (replace placeholders as described).

    {
      "mcpServers": {
        "oceanbase": {
          "command": "uv",
          "args": [
            "--directory",
            "/path/to/your/mcp-oceanbase/src/oceanbase_mcp_server",
            "run",
            "oceanbase_mcp_server"
          ],
          "env": {
            "OB_HOST": "***",
            "OB_PORT": "***",
            "OB_USER": "***",
            "OB_PASSWORD": "***",
            "OB_DATABASE": "***"
          }
        }
      }
    }
    

    Replace /path/to/your/mcp-oceanbase/src/oceanbase_mcp_server with the absolute path to the oceanbase_mcp_server folder, and set OB_HOST, OB_PORT, OB_USER, OB_PASSWORD, and OB_DATABASE to your OceanBase connection details.

  3. When configuration is successful, the server shows as Available.

Test the MCP Server

  1. Select the Builder with MCP agent.

  2. In the chat, ask: How many tables are in the test database? Trae will show the SQL it plans to run. Review it and click Run to execute.

  3. Trae will list the tables in the test database, confirming that the connection to OceanBase is working.

Build a RESTful API with FastAPI

You can use FastAPI to quickly create a REST-style API. FastAPI is a Python web framework well-suited for building APIs.

  1. Create the customer table.

    In the chat, prompt: Create a customer table with primary key ID and columns name, age, telephone, and location. Confirm the generated SQL and click Run.

  2. Insert test data.

    Prompt: Insert 10 rows into the customer table. Confirm the SQL and click Run.

  3. Create the FastAPI project.

    Prompt: Create a FastAPI project that exposes a RESTful API for the customer table. Confirm and click Run.

    This step generates three files. For a first run, accepting all generated content is recommended; you can adjust it later as needed.

  4. Create a virtual environment and install dependencies.

    In the project directory, run:

    uv venv
    source .venv/bin/activate
    uv pip install -r requirements.txt
    
  5. Start the FastAPI app.

    uvicorn main:app --reload
    
  6. Query the API.

    From a terminal or any HTTP client:

    curl http://127.0.0.1:8000/customers
    

    You should see JSON with the customer records. The generated code implements full CRUD over the customer table:

    from fastapi import FastAPI
    from pydantic import BaseModel
    import mysql.connector
    
    app = FastAPI()
    
    # Database connection config
    config = {
        'user': '*******',
        'password': '******',
        'host': 'xx.xxx.xxx.xx',
        'database': 'test',
        'port':xxxx,
        'raise_on_warnings': True
    }
    
    class Customer(BaseModel):
        id: int
        name: str
        age: int
        telephone: str
        location: str
    
    @app.get('/customers')
    async def get_customers():
        cnx = mysql.connector.connect(**config)
        cursor = cnx.cursor(dictionary=True)
        query = 'SELECT * FROM customer'
        cursor.execute(query)
        results = cursor.fetchall()
        cursor.close()
        cnx.close()
        return results
    
    @app.get('/customers/{customer_id}')
    async def get_customer(customer_id: int):
        cnx = mysql.connector.connect(**config)
        cursor = cnx.cursor(dictionary=True)
        query = 'SELECT * FROM customer WHERE ID = %s'
        cursor.execute(query, (customer_id,))
        result = cursor.fetchone()
        cursor.close()
        cnx.close()
        return result
    
    @app.post('/customers')
    async def create_customer(customer: Customer):
        cnx = mysql.connector.connect(**config)
        cursor = cnx.cursor()
        query = 'INSERT INTO customer (ID, name, age, telephone, location) VALUES (%s, %s, %s, %s, %s)'
        data = (customer.id, customer.name, customer.age, customer.telephone, customer.location)
        cursor.execute(query, data)
        cnx.commit()
        cursor.close()
        cnx.close()
        return {'message': 'Customer created successfully'}
    
    @app.put('/customers/{customer_id}')
    async def update_customer(customer_id: int, customer: Customer):
        cnx = mysql.connector.connect(**config)
        cursor = cnx.cursor()
        query = 'UPDATE customer SET name = %s, age = %s, telephone = %s, location = %s WHERE ID = %s'
        data = (customer.name, customer.age, customer.telephone, customer.location, customer_id)
        cursor.execute(query, data)
        cnx.commit()
        cursor.close()
        cnx.close()
        return {'message': 'Customer updated successfully'}
    
    @app.delete('/customers/{customer_id}')
    async def delete_customer(customer_id: int):
        cnx = mysql.connector.connect(**config)
        cursor = cnx.cursor()
        query = 'DELETE FROM customer WHERE ID = %s'
        cursor.execute(query, (customer_id,))
        cnx.commit()
        cursor.close()
        cnx.close()
        return {'message': 'Customer deleted successfully'}
    

Previous topic

n8n
Last

Next topic

SpringAI
Next
on this page
Prerequisites
Step 1: Get database connection details
Step 2: Configure the OceanBase MCP Server
Clone the OceanBase MCP Server repository
Install dependencies
Create a Trae project directory
Configure the OceanBase MCP Server in Trae
Add and configure MCP servers
Test the MCP Server
Build a RESTful API with FastAPI