mcp-server-example

technicalheist/mcp-server-example

3.1

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

The SQLite MCP Server is a Model Context Protocol server that facilitates interaction with a SQLite database through MCP tools and resources.

Tools
3
Resources
0
Prompts
0

SQLite MCP Server

A Model Context Protocol (MCP) server that provides SQLite database operations through MCP tools and resources.

Description

This project implements an MCP server using FastMCP that allows clients to interact with a SQLite database. It provides tools for executing SQL queries, listing tables, retrieving table schemas, and accessing database information.

Features

Tools

  • execute_sql: Execute arbitrary SQL queries on the database
  • list_tables: List all tables in the database
  • get_table_schema: Get detailed schema information for a specific table

Resources

  • sqlite://tables: Provides an overview of the database including table names and count

Installation

  1. Clone or download this repository
  2. Install dependencies:
    pip install -r requirements.txt
    

Usage

Running Locally

  1. Ensure you have a Python virtual environment set up (optional but recommended)
  2. Run the server:
    python app.py
    

Or use the provided script:

./run_mcp.sh

Docker

Build and run using Docker:

docker build -t sqlite-mcp-server .
docker run -v $(pwd)/app/data:/app/app/data sqlite-mcp-server

The database file is stored in app/data/mcp.db and can be mounted as a volume for persistence.

Requirements

  • Python 3.7+
  • mcp>=1.14.0

Database

The server uses a SQLite database located at app/data/mcp.db. The database is automatically initialized on first run with WAL mode enabled for better concurrency.

API Reference

execute_sql(sql: str, params: List[Any] = None)

Executes an SQL query.

  • sql: The SQL query string
  • params: Optional parameters for parameterized queries
  • Returns: Query results for SELECT statements, or affected row count for other operations

list_tables()

Lists all tables in the database.

  • Returns: List of table names

get_table_schema(table_name: str)

Gets schema information for a table.

  • table_name: Name of the table
  • Returns: Column details including name, type, nullability, default values, and primary key status

Resource: sqlite://tables

Provides a text summary of the database structure.