Skip to main content
Version: V1.0.0

Integrate seekdb MCP Server with Claude Code

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.

The MCP Server allows large models to interact with seekdb and execute SQL statements. It is open-sourced on GitHub and can be quickly integrated into projects using suitable clients.

Claude Code is an AI-powered coding tool developed by Anthropic. It is a terminal-based intelligent coding assistant that helps developers rapidly convert ideas into high-quality code.

This article demonstrates how to use Claude Code to quickly build a backend application with seekdb MCP Server.

Prerequisites

  • You have deployed seekdb.

  • Install Python 3.11 or later and the corresponding pip. If your system has a lower version of Python, you can use Miniconda to create a new environment with Python 3.11 or later. For more information, see Miniconda installation guide.

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

    pip install uv
    uv --version
  • Install Claude Code:

    1. Install the Claude Code for VS Code plugin in Visual Studio Code.

      1

    2. Configure the Claude Code plugin.

      Configure the third-party API information for Claude Code and enable the Use Terminal option.

      export ANTHROPIC_BASE_URL=YOUR_BASE_URL
      export ANTHROPIC_API_KEY=YOUR_API_KEY
      export ANTHROPIC_MODEL=YOUR_MODE

      2

    3. Test the connection.

      3

Step 1: Obtain the database connection information

Contact the deployment personnel or administrator of seekdb to obtain the 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, which is 2881 by default.

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

    tip

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

  • $user_name: the database connection account.

  • $password: the account password.

Step 2: Configure the seekdb MCP server

This example uses Visual Studio Code to 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

Open the VS Code terminal and run the claude mcp add-json command

claude mcp add-json sse-seekdb '{
"autoApprove": [],
"disabled": false,
"timeout": 60,
"type": "sse",
"url": "http://ip:port/sse"
}'

Create a working directory for the Claude Code client and configure the seekdb MCP server

Manually create a working directory for Visual Studio Code on your local machine and open it with Visual Studio Code. The files generated by Claude Code will be stored in this directory. An example directory name is claudecode.

Verify whether you can connect to the database. When prompted with How many tables in the test database?, Claude Code will display the SQL statements to be executed and output the query results:

4

If the number of tables in the test database is displayed, the seekdb connection is successful.

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.

  1. 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":

    5

  2. Insert test data.

    Enter the prompt Insert 10 pieces of data into the customer table:

    6

  3. Create a FastAPI project.

    Enter the prompt Create a FastAPI project on the customer table. Multiple files are automatically generated. You can modify them as needed.

    7

  4. Configure the database connection information for the FastAPI project

    8

  5. Install project dependencies

    Run the following command to install the project dependencies:

    cd customer_api
    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":"Alice Johnson","age":28,"telephone":"555-0101","location":"New York","ID":1},{"name":"Bob Smith","age":35,"telephone":"555-0102","location":"Los Angeles","ID":2},{"name":"Carol White","age":42,"telephone":"555-0103","location":"Chicago","ID":3},{"name":"David Brown","age":31,"telephone":"555-0104","location":"Houston","ID":4},{"name":"Eve Davis","age":26,"telephone":"555-0105","location":"Phoenix","ID":5},{"name":"Frank Miller","age":39,"telephone":"555-0106","location":"Philadelphia","ID":6},{"name":"Grace Lee","age":33,"telephone":"555-0107","location":"San Antonio","ID":7},{"name":"Henry Taylor","age":45,"telephone":"555-0108","location":"San Diego","ID":8},{"name":"Ivy Martinez","age":29,"telephone":"555-0109","location":"Dallas","ID":9},{"name":"Jack Wilson","age":37,"telephone":"555-0110","location":"San Jose","ID":10}]