Skip to content

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

Notifications You must be signed in to change notification settings

technicalheist/mcp-server-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published