sql-mpc-server

phanithlim/sql-mpc-server

3.1

If you are the rightful owner of sql-mpc-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A FastAPI-based, read-only server for managing and querying SQL databases using the Model Context Protocol (MCP).

SQL MCP Server

A FastAPI-based, read-only server for managing and querying SQL databases using the Model Context Protocol (MCP). This is a simple template for an MCP server designed to interact with SQL databases in a read-only mode.

Installation

Install UV package manager:

curl -LsSf https://astral.sh/uv/install.sh | sh

or pipx

pip install uv

Install Dependencies

uv sync

Usage

Run MCP Server Inspector:

make mcp-dev

Run the FastAPI application:

make dev

Project Structure

ā”œā”€ā”€ app.py            # FastAPI application entry point
ā”œā”€ā”€ Dockerfile        # Containerization support
ā”œā”€ā”€ pyproject.toml    # Project metadata and dependencies
ā”œā”€ā”€ uv.lock           # uv dependency lock file
ā”œā”€ā”€ config.json      # Configuration file for MCP server
ā”œā”€ā”€ tools/
│   ā”œā”€ā”€ server.py     # Server logic for FastMCP
│   ā”œā”€ā”€ model.py      # Response models for FastMCP
│   ā”œā”€ā”€ helpers.py    # Helper functions for FastMCP
│   └── __init__.py
└── README.md          # Project documentation

Features

  • get_all_tables: Retrieve a list of tables in the database.
  • get_table_info: Get information about a specific table.
  • get_table_description: Retrieves the description of a specific table from the config file (useful if tables or columns have short names).
  • get_all_table_descriptions: Retrieves descriptions of all tables from the config file (useful if tables or columns have short names).
  • execute_query: Execute a SQL query and return the results.

Deployment

Docker

Build the Docker image:

docker build -t mcp-server .

Run the Docker container:

docker run -d -p 8000:8000 mcp-server
  • MCP server url: http://localhost:8000/mcp/sse