SQLite MCP Server

SQLite MCP servers enable AI models to interact with SQLite databases, providing capabilities for structured data operations, SQL queries, and local data management.

GitHub starsnpm versionnpm downloads

Overview

The MCP SQLite Server provides a lightweight and efficient way for AI models to interact with SQLite databases. Based on the official Python reference, this Node.js implementation offers an npx-based solution for environments where Python's UVX runner might not be available. It enables AI to perform structured data operations, execute SQL queries, and manage local data, making it ideal for embedded applications and local data storage needs.

Created by:

Developed by johnnyoshika

Key Features

🗄️

Local Data Management

Efficiently manage and query data stored in local SQLite files.

💬

SQL Query Execution

Execute standard SQL queries for data retrieval and manipulation.

🚀

Lightweight & Embedded

Ideal for embedded applications and scenarios requiring a serverless database.

🔍

Schema Inspection

Inspect database schemas, tables, and column details.

Available Tools

Quick Reference

ToolPurposeCategory
queryExecute SELECT queriesRead
executeExecute INSERT/UPDATE/DELETEWrite
list_tablesList tables in the databaseSchema
describe_tableGet table structure detailsSchema

Detailed Usage

query

Execute SELECT queries with optional prepared statement parameters.

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "query",
  arguments: {
    sql: "SELECT * FROM users WHERE id = ?",
    params: [1]
  }
});

Returns matching rows from the database.

execute

Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "execute",
  arguments: {
    sql: "INSERT INTO users (name, email) VALUES (?, ?)",
    params: ["Jane Doe", "[email protected]"]
  }
});

Returns information about the executed statement (e.g., last insert ID, rows affected).

list_tables

List all tables in the connected SQLite database.

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "list_tables",
  arguments: {}
});

Returns a list of table names.

describe_table

Get the structure (columns, types) of a specific table.

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "describe_table",
  arguments: {
    table: "users"
  }
});

Provides column names, data types, and other table details.

Installation

{
  "mcpServers": {
    "sqlite": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-sqlite-npx",
        "/absolute/path/to/database.db"
      ],
      "env": {}
    }
  }
}

Database Path:

Replace /absolute/path/to/database.db with the actual path to your SQLite database file.

Common Use Cases

1. Local Data Storage

Store and retrieve application configuration or user preferences locally:

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "execute",
  arguments: {
    sql: "CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT)"
  }
});

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "execute",
  arguments: {
    sql: "INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)",
    params: ["theme", "dark"]
  }
});

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "query",
  arguments: {
    sql: "SELECT value FROM settings WHERE key = ?",
    params: ["theme"]
  }
});

2. Embedded Analytics

Perform simple analytics on local datasets without external dependencies:

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "query",
  arguments: {
    sql: "SELECT category, COUNT(*) as count FROM products GROUP BY category ORDER BY count DESC"
  }
});

3. Caching for Offline Access

Cache data from remote APIs for offline access or reduced network calls:

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "execute",
  arguments: {
    sql: "CREATE TABLE IF NOT EXISTS api_cache (url TEXT PRIMARY KEY, data TEXT, timestamp INTEGER)"
  }
});

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "execute",
  arguments: {
    sql: "INSERT OR REPLACE INTO api_cache (url, data, timestamp) VALUES (?, ?, ?)",
    params: ["/api/data", JSON.stringify(apiData), Date.now()]
  }
});

use_mcp_tool({
  server_name: "sqlite",
  tool_name: "query",
  arguments: {
    sql: "SELECT data FROM api_cache WHERE url = ? AND timestamp > ?",
    params: ["/api/data", Date.now() - 3600000] // Data less than 1 hour old
  }
});

Connection String Format

The SQLite MCP server connects directly to a specified .db file. The path to this file is provided as an argument during server initialization.

  • Database Path: The absolute path to the SQLite database file (e.g., /absolute/path/to/database.db).

Sources