Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

MCP SQLite Server

A Model Context Protocol (MCP) server that provides SQLite database access through standardized tools. This server allows AI assistants to interact with SQLite databases by listing tables, describing schemas, and executing queries.

This MCP server was written using Claude Desktop and the Claude Sonnet 4. This README was generated by Claude Sonnet 4 based on the files in this repo.

Features

  • List Tables: View all tables in the connected SQLite database
  • Describe Schema: Get detailed table structure including column types, constraints, and primary keys
  • Execute Queries: Run SELECT, INSERT, UPDATE, DELETE, and other SQL commands
  • Error Handling: Comprehensive error handling with detailed logging
  • Safe Operations: Built-in protections and query validation

Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Setup

  1. Clone this repository:
git clone https://github.com/makeralchemy/claude-desktop-mcp-sqlite
cd mcp-sqlite
  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:
# Windows
venv\Scripts\activate

# macOS/Linux
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt

Configuration

1. Update Database Path

Edit mcpsqlite.py and modify the DB_PATH variable to point to your SQLite database:

DB_PATH = r"path/to/your/database.db"

2. Configure Claude Desktop

Add the server configuration to your Claude Desktop config file:

Location of config file:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Configuration:

{
  "mcpServers": {
    "sqlite": {
      "command": "/path/to/your/venv/Scripts/python.exe",
      "args": [
        "/path/to/your/mcpsqlite.py"
      ]
    }
  }
}

Replace the paths with your actual installation paths.

Usage

Once configured, the server provides three main tools that can be used through Claude Desktop:

Available Tools

1. list_tables

Lists all tables in the connected database.

Example usage:

"Show me all tables in the database"

2. describe_table

Provides detailed schema information for a specific table.

Parameters:

  • table_name (string): Name of the table to describe

Example usage:

"Describe the structure of the 'users' table"

3. run_query

Executes SQL queries against the database.

Parameters:

  • query (string): SQL query to execute

Example usage:

"SELECT * FROM users WHERE age > 21"
"UPDATE products SET price = 29.99 WHERE id = 1"

File Structure

mcp-sqlite/
├── mcpsqlite.py              # Main MCP server implementation
├── claude_desktop_config.json # Example configuration
├── mcp_sqlite.log            # Log file (generated at runtime)
├── venv/                     # Virtual environment
└── README.md                # This file

Logging

The server automatically logs all operations to both:

  • Console output
  • mcp_sqlite.log file

Log entries include:

  • Tool requests and executions
  • Database connection status
  • Error messages and stack traces
  • Query execution results

Error Handling

The server includes robust error handling for:

  • Missing database files
  • Invalid SQL queries
  • Connection failures
  • Missing required parameters
  • SQLite-specific errors

All errors are logged and returned as descriptive messages to the client.

Security Considerations

  • Database Access: The server has full read/write access to the configured database
  • Query Validation: Basic validation is performed, but consider additional restrictions for production use
  • File Permissions: Ensure the database file has appropriate access permissions
  • Network Security: This server is designed for local use with Claude Desktop

Development

Running in Development Mode

  1. Activate your virtual environment
  2. Run the server directly:
python mcpsqlite.py

Testing

You can test the server functionality by:

  1. Configuring it with Claude Desktop
  2. Using the MCP Inspector tool
  3. Running direct SQLite queries to verify database access

Troubleshooting

Common Issues

Server not connecting:

  • Verify the Python path in your configuration
  • Check that the virtual environment is properly set up
  • Ensure all dependencies are installed

Database not found:

  • Verify the DB_PATH in mcpsqlite.py points to your database
  • Check file permissions on the database file
  • Ensure the database file exists and is accessible

Tool execution fails:

  • Check the mcp_sqlite.log file for detailed error messages
  • Verify your SQL syntax for query operations
  • Ensure table names are spelled correctly

Log Analysis

Check mcp_sqlite.log for detailed information about:

  • Server startup and initialization
  • Tool execution attempts
  • Database connection status
  • Specific error messages

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License

Support

For issues and questions:

  • Check the troubleshooting section above
  • Review the log files for error details
  • Open an issue on GitHub with relevant log entries

About

MCP for connecting to SQLite databases via Claude Desktop

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages