Skip to main content
Glama
SQLite MCP Server

SQLite MCP Server

by TIMBOTGPT
README.md
# SQLite MCP Server

A Model Context Protocol (MCP) server that provides SQLite database access and operations for Claude AI.

## Features

- **connect_database**: Connect to SQLite database files
- **execute_query**: Run SQL queries (SELECT, INSERT, UPDATE, DELETE, etc.)
- **get_schema**: Get complete database schema information
- **list_tables**: List all tables in a database
- **describe_table**: Get detailed table information including columns and indexes
- **list_connections**: Show all active database connections
- **close_connection**: Close database connections
- Support for multiple simultaneous database connections
- Prepared statement parameter binding
- Comprehensive error handling

## Installation

### Quick Install
```bash
npm install -g sqlite-mcp-server
```

### From Source
1. Clone the repository:
   ```bash
   git clone https://github.com/TIMBOTGPT/sqlite-mcp.git
   cd sqlite-mcp
   ```

2. Install dependencies:
   ```bash
   npm install
   ```

3. Build the project:
   ```bash
   npm run build
   ```

4. Test the server:
   ```bash
   npm start
   ```

## Usage with Claude Desktop

Add this server to your Claude Desktop MCP configuration (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "sqlite": {
      "command": "npx",
      "args": ["-y", "sqlite-mcp-server"],
      "description": "SQLite database operations"
    }
  }
}
```

Or if installed locally:
```json
{
  "mcpServers": {
    "sqlite": {
      "command": "node",
      "args": ["/path/to/sqlite-mcp/dist/index.js"],
      "env": {
        "DATABASE_PATH": "/path/to/your/databases"
      },
      "description": "SQLite database operations"
    }
  }
}
```

## Available Tools

### connect_database
Connect to a SQLite database file.

**Parameters:**
- `path` (required): Path to the SQLite database file
- `alias` (optional): Connection alias (defaults to filename)

**Example:**
```json
{
  "name": "connect_database",
  "arguments": {
    "path": "/path/to/database.db",
    "alias": "mydb"
  }
}
```

### execute_query
Execute SQL queries on connected databases.

**Parameters:**
- `database` (required): Database alias or path
- `query` (required): SQL query to execute
- `params` (optional): Array of parameters for prepared statements

**Example:**
```json
{
  "name": "execute_query",
  "arguments": {
    "database": "mydb",
    "query": "SELECT * FROM users WHERE age > ?",
    "params": [25]
  }
}
```

### get_schema
Get the complete schema of a database.

**Parameters:**
- `database` (required): Database alias or path

### list_tables
List all tables in a database.

**Parameters:**
- `database` (required): Database alias or path

### describe_table
Get detailed information about a specific table.

**Parameters:**
- `database` (required): Database alias or path
- `table` (required): Table name

### list_connections
Show all active database connections.

### close_connection
Close a database connection.

**Parameters:**
- `database` (required): Database alias or path to close

## Requirements

- Node.js 18+
- SQLite3
- Claude Desktop with MCP support

## Security

- File existence validation before connection attempts
- Proper connection management and cleanup
- Parameter binding for SQL injection prevention
- Comprehensive error handling

## Development

```bash
# Install dependencies
npm install

# Build TypeScript
npm run build

# Development with auto-reload
npm run dev

# Run tests
npm test
```

## License

MIT License - see LICENSE file for details

## Contributing

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

## Support

For issues and questions, please use the [GitHub Issues](https://github.com/TIMBOTGPT/sqlite-mcp/issues) page.