Metadata-Version: 2.3
Name: mcp-server-sql-inspector
Version: 0.1.3
Summary: A Model Context Protocol server that enables AI to inspect SQL databases and analyze query performance.
Author: Tam Dao
Author-email: daotam4536@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Provides-Extra: all
Provides-Extra: mssql
Provides-Extra: mysql
Provides-Extra: postgres
Requires-Dist: mcp[cli] (>=1.26.0)
Requires-Dist: mysql-connector-python ; extra == "mysql" or extra == "all"
Requires-Dist: psycopg2-binary ; extra == "postgres" or extra == "all"
Requires-Dist: pyodbc ; extra == "mssql" or extra == "all"
Requires-Dist: sqlalchemy (>=2.0.46)
Description-Content-Type: text/markdown

# MCP Server SQL Inspector

[![PyPI version](https://img.shields.io/pypi/v/mcp-server-sql-inspector.svg)](https://pypi.org/project/mcp-server-sql-inspector/)

A Model Context Protocol (MCP) server that enables AI to inspect SQL databases and analyze query performance.

## Tools

- **list_tables**: List tables in the database.
- **get_schema**: Get schema definition for one or more tables.
  - `table_names` (list): List of table names to inspect.
- **get_table_stats**: Get estimated row count for a table.
- **run_explain**: Analyze a query execution plan.
  - `query`: The SQL query to analyze (SELECT only).
  - `just_explain_plan` (optional): If true, gets the plan without running the query (default: False).

## Installation

### Using `uv` (Recommended)

When using `uv` no installation is necessary. You can run the server directly:

```bash
uvx mcp-server-sql-inspector
```

### Configuration with Claude Desktop

Add this to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "sql-inspector": {
      "command": "uvx",
      "args": ["mcp-server-sql-inspector"],
      "env": {
        "DATABASE_URL": "postgresql://user:password@localhost:5432/dbname"
      }
    }
  }
}
```

### Local Development Configuration

If you are developing the server locally and want to test changes in Claude Desktop:

```json
{
  "mcpServers": {
    "sql-inspector": {
      "command": "/absolute/path/to/mcp-server-sql-inspector/.venv/bin/mcp-server-sql-inspector",
      "args": [],
      "env": {
        "DATABASE_URL": "sqlite:///demo.db"
      }
    }
  }
}
```

### From Source

```bash
git clone <repository-url>
cd mcp-server-sql-inspector
poetry install --extras all
```

### Docker

Build the image:
```bash
docker build -t mcp-server-sql-inspector .
```

Run the container:
```bash
docker run -i --rm -e DATABASE_URL="postgresql://user:password@host:port/dbname" mcp-server-sql-inspector
```

#### Docker Configuration for Claude Desktop

```json
{
  "mcpServers": {
    "sql-inspector": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e", "DATABASE_URL=postgresql://user:password@host:port/dbname",
        "mcp-server-sql-inspector"
      ]
    }
  }
}
```

## Configuration

The server requires a `DATABASE_URL` environment variable to connect to your database.

Supported database protocols (requires appropriate drivers):
- PostgreSQL: `postgresql://...`
- MySQL: `mysql://...`
- MSSQL: `mssql+pyodbc://...`
- SQLite: `sqlite:///...`

## Development

1. Install dependencies:
   ```bash
   poetry install --extras all
   ```

2. Run the server:
   ```bash
   export DATABASE_URL="sqlite:///test.db"
   poetry run mcp-server-sql-inspector
   ```

## License

[MIT](LICENSE)

