Skip to main content
Version: V1.0.0

Integrate MCP Server with TrAE

Model Context Protocol (MCP) is an open-source protocol introduced by Anthropic in November 2024. It allows large language models to interact with external tools or data sources. With MCP, you do not need to manually copy and execute the output of large language models. Instead, the large language model can directly command tools to perform specific actions.

The MCP Server provides the capability for large models to interact with SeekDB through the MCP protocol and can execute SQL statements. With the right client, you can quickly set up a project prototype. It has been open-sourced on GitHub.

TRAE is an IDE that can integrate with MCP Server, can be downloaded from its official website.

This topic will show you how to use Trae IDE to integrate with seekdb MCP Server and quickly build a backend application.

Prerequisites

  • You have deployed seekdb.

  • You have installed Python 3.11 or later and the corresponding pip. If your system has a low Python version, you can use Miniconda to create a new Python 3.11 or later environment. For more information, see Install Miniconda.

  • You have installed uv, a Python package manager. After the installation, run the uv --version command to check whether the installation was successful:

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

Step 1: Obtain the database connection information

Contact your seekdb deployment engineer or administrator to obtain the database connection string. For example:

mysql -h$host -P$port -u$user_name -p$password -D$database_name

Parameters:

  • $host: The IP address for connecting to seekdb.

  • $port: The port number for connecting to seekdb. Default is 2881.

  • $database_name: The name of the database to access.

    tip

    The connected user must have CREATE, INSERT, DROP, and SELECT privileges on the database.

  • $user_name: The username for connecting to the database.

  • $password: The password for the account.

Step 2: Configure the seekdb MCP Server

Install the seekdb MCP Server

Run the following command to install the seekdb MCP Server:

pip install seekdb-mcp-server

Configure the seekdb server environment variables in the .env file

Create a file named .env in the current directory and add the following content:

vi .env

SEEKDB_HOST=localhost # Database host
SEEKDB_PORT=2881 # Database port (default: 2881)
SEEKDB_USER=your_username
SEEKDB_PASSWORD=your_password
SEEKDB_DATABASE=your_database

Start in SSE mode

env $(cat .env | xargs) uvx seekdb-mcp-server --transport sse --port 8000 --host 0.0.0.0

Create a working directory for the TRAE client and configure the seekdb MCP Server

Manually create a working directory for TRAE and open it. TRAE will generate files in this directory. The example directory name is trae-generate.

Press Ctrl + U (Windows) or Command + U (MacOS) to open the chat box. Click the gear icon in the upper-right corner and select MCP.

Configure the seekdb MCP Server

  1. Click Add Custom MCP and fill in the configuration file.

    2

  2. Fill in the configuration file and click OK.

    {
    "mcpServers": {
    "sse-seekdb": {
    "autoApprove": [],
    "disabled": false,
    "timeout": 60,
    "type": "sse",
    "url": "http://ip:port/sse"
    }
    }
    }
  3. The configuration is successful.

    3

Test the MCP server

  1. Select the Builder with MCP agent.

    4

  2. In the dialog box, enter How many tables in the test database?. The TRAE client will execute the command and display the names of all tables in the test database. This indicates that you have successfully connected to seekdb.

    5

Create a RESTful API project using FastAPI

You can use FastAPI to quickly create a RESTful API project. FastAPI is a Python web framework that enables you to build RESTful APIs efficiently.

  1. Create the customer table.

    In the dialog box, enter Create a "customer" table with "ID" as the primary key and containing fields such as "name", "age", "telephone", and "location". Confirm the SQL statement and click the Accept button.

    6

  2. Insert test data.

    In the dialog box, enter Insert 10 pieces of data into the customer table.

    7

  3. Create a FastAPI project.

    In the dialog box, enter Create a FastAPI project on the customer table.

    8

    This step will generate multiple files. We recommend that you select Accept All for the first use, because the files generated by AI may contain uncertain contents. You can adjust them based on your actual needs later.

  4. FastAPI project configuration database connection information

    9

  5. Install project dependencies

    Execute the following command to install the project dependencies:

    pip install -r requirements.txt
  6. Start the FastAPI project.

    Run the following command to start the FastAPI project:

    source .env
    uvicorn main:app --reload
  7. View the data in the table.

    Run the following command in the command line or use other request tools to view the data in the table:

    curl http://127.0.0.1:8000/customers

    The return result is as follows:

    [{"name":"John Smith","age":35,"telephone":"555-1234","location":"New York, NY","ID":1},{"name":"Sarah Johnson","age":28,"telephone":"555-5678","location":"Los Angeles, CA","ID":2},{"name":"Michael Brown","age":42,"telephone":"555-9012","location":"Chicago, IL","ID":3},{"name":"Emma Davis","age":31,"telephone":"555-3456","location":"Houston, TX","ID":4},{"name":"James Wilson","age":45,"telephone":"555-7890","location":"Phoenix, AZ","ID":5},{"name":"Olivia Taylor","age":26,"telephone":"555-2345","location":"Philadelphia, PA","ID":6},{"name":"William Anderson","age":38,"telephone":"555-6789","location":"San Antonio, TX","ID":7},{"name":"Ava Thomas","age":33,"telephone":"555-0123","location":"San Diego, CA","ID":8},{"name":"Benjamin Martinez","age":40,"telephone":"555-4567","location":"Dallas, TX","ID":9},{"name":"Sophia Garcia","age":29,"telephone":"555-8901","location":"Austin, TX","ID":10}]