Skip to main content
Version: V1.0.0

Integrate seekdb MCP Server with Cursor

MCP (Model Context Protocol) is an open-source protocol launched by Anthropic in November 2024. It enables large language models (LLMs) to interact with external tools or data sources. With MCP, users can directly instruct tools to perform specific actions based on the LLM's output, eliminating the need for manual copying and execution.

seekdb MCP Server allows LLMs to interact with seekdb and execute SQL statements. It is open-source on GitHub and can be quickly integrated with a suitable client.

Cursor is an AI-powered code editor that supports Windows, macOS, and Linux.

This article demonstrates how to integrate Cursor with seekdb MCP Server to build a backend application quickly.

Prerequisites

  • You have deployed seekdb.

  • Install Python 3.11 or later and the corresponding pip. If the Python version on your machine is too low, you can use Miniconda to create a new Python 3.11 or later environment. For more information, see Miniconda installation guide.

  • Install the Python package manager uv. After the installation is complete, run the uv --version command to verify whether the installation is successful:

    pip install uv
    uv --version
  • Download Cursor and install the version that matches your operating system. When you use Cursor for the first time, you need to register a new account or log in with an existing account. After you log in, you can create a new project or open an existing project.

Step 1: Obtain the database connection information

Contact the deployment personnel or administrator of seekdb to obtain the corresponding database connection string, for example:

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

Parameter description:

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

  • $port: the port for connecting to seekdb. The default value is 2881.

  • $database_name: the name of the database to be accessed.

    tip

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

  • $user_name: the database connection account.

  • $password: the account password.

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 the seekdb MCP Server 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 Cursor client and configure the seekdb MCP Server

Manually create a working directory for Cursor and open it with Cursor. The files generated by Cursor will be stored in this directory. An example directory name is cursor.

Use the shortcut Ctrl + L (Windows) or Command + L (MacOS) to open the chat dialog box. Click the gear icon in the upper right corner and select MCP Tools.

1

Add and configure MCP Servers

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

    2

  2. Fill in the configuration file and click Confirm.

    {
    "mcpServers": {
    "sse-seekdb": {
    "autoApprove": [],
    "disabled": false,
    "timeout": 60,
    "type": "sse",
    "url": "http://ip:port/sse"
    }
    }
    }
  3. If the configuration is successful, the status will show as Available.

    3

Test the MCP Server

In the dialog box, enter the prompt: How many tables in the test database?. The Cursor client will display the SQL statement to be executed. After confirming, click the Run tool button to execute. The Cursor client will display all the table names in the test database, indicating that we have successfully connected to seekdb.

4

Use FastAPI to quickly create a RESTful API project

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

  1. Create a customer table

    In the dialog box, enter the prompt: Create a "customer" table with "ID" as the primary key and containing fields such as "name", "age", "telephone", and "location". After confirming the SQL statement, click the Run tool button to execute.

    5

  2. Insert test data

    In the dialog box, enter the prompt: Insert 10 pieces of data into the customer table. After confirming the SQL statement, click the Run tool button to execute. If the insertion is successful, you will see the message: Done! Here are the 10 customer records inserted:.

    6

  3. Create a FastAPI project

    In the dialog box, enter the prompt: Create a FastAPI project on the customer table. Click the Run tool button to execute.

    7

    This step will automatically generate multiple files. It is recommended to select All accept for the first use, as the AI-generated file content may be uncertain. You can adjust them as needed later.

  4. Configure the database connection information for the FastAPI project

    Configure the seekdb connection information in the .env file.

    8

  5. Install project dependencies

    Run 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 returned result is as follows:

    [{"name":"John Smith","age":32,"telephone":"555-0101","location":"New York, NY","ID":1},{"name":"Emily Johnson","age":28,"telephone":"555-0102","location":"Los Angeles, CA","ID":2},{"name":"Michael Chen","age":45,"telephone":"555-0103","location":"San Francisco, CA","ID":3},{"name":"Sarah Williams","age":36,"telephone":"555-0104","location":"Chicago, IL","ID":4},{"name":"David Brown","age":29,"telephone":"555-0105","location":"Houston, TX","ID":5},{"name":"Jessica Lee","age":41,"telephone":"555-0106","location":"Phoenix, AZ","ID":6},{"name":"Robert Garcia","age":55,"telephone":"555-0107","location":"Philadelphia, PA","ID":7},{"name":"Amanda Martinez","age":23,"telephone":"555-0108","location":"San Antonio, TX","ID":8},{"name":"Christopher Wilson","age":38,"telephone":"555-0109","location":"San Diego, CA","ID":9},{"name":"Nicole Taylor","age":31,"telephone":"555-0110","location":"Dallas, TX","ID":10}]