# text2sql [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/cpenniman12/text2sql-mcp  
**GitHub Stars:** 1  
**Views:** 4  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/text2sql

## Description
Ask any SQL database in natural language. Agent explores schema, writes SQL, self-corrects.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "text2sql": {
    "command": "uvx",
    "args": ["text2sql-mcp"],
    "env": {
      "TEXT2SQL_DATABASE_URL": "",
      "ANTHROPIC_API_KEY": "",
      "OPENAI_API_KEY": ""
    }
  }
}
```

**Requires environment variables:** `TEXT2SQL_DATABASE_URL`, `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What text2sql does

The text2sql MCP server connects an MCP-compatible assistant to a SQL database and turns natural-language questions into executed queries. It supports SQLite by default and can be installed with extras for Postgres, MySQL, Snowflake, or BigQuery. Anthropic is the default model provider, while OpenAI models can be enabled with the corresponding installation extra.

The main interaction is the `query` tool. It accepts a question and an optional `max_rows` limit, then returns the generated SQL, result data, any error, the row count, and the number of tool calls made. This makes it suitable for assistants that need to inspect data rather than only explain how to write a query.

## How it works

The text2sql MCP server is a thin MCP wrapper around the text2sql-framework. The agent first explores the connected database schema, creates SQL for the user’s question, and runs that SQL through an `execute_sql` tool. If execution produces an error, the agent can revise the query and try again.

This workflow operates directly against the configured database. It does not require a retrieval-augmented generation layer, manually maintained schema descriptions, or precomputed embeddings. You can also provide business guidance through `TEXT2SQL_INSTRUCTIONS`, such as definitions for revenue or other domain-specific terms. The optional `TEXT2SQL_EXAMPLES` variable points to a `scenarios.md` file that the agent can use with its `lookup_example` tool.

## Setup and configuration

Install the package with pip or run it through `uvx`. The default installation is suitable for SQLite with Anthropic:

```bash
pip install text2sql-mcp
uvx text2sql-mcp
```

Use the matching extra when another database or provider is needed, such as `text2sql-mcp[postgres]`, `text2sql-mcp[mysql]`, `text2sql-mcp[snowflake]`, or `text2sql-mcp[bigquery]`. Add the `openai` extra to use OpenAI models.

Configure the MCP client with `TEXT2SQL_DATABASE_URL`, using a SQLAlchemy URL such as `sqlite:///mydb.db` or a PostgreSQL connection URL. An `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` is also required. `TEXT2SQL_MODEL` selects the LangChain model ID and defaults to `anthropic:claude-sonnet-4-6`.

The package can be registered as a command-line MCP server in Claude Desktop, Cursor, or another compatible client. Goose can be configured with its command-line extension settings.

## Tools and capabilities

- Ask natural-language questions with `query`.
- Limit returned results with `max_rows`, which defaults to 100.
- Inspect database schema before query generation.
- Execute generated SQL against the configured database.
- Retry after SQL execution errors.
- Return SQL, data, errors, row counts, and tool-call counts.

## Limitations and notes

The server connects to one configured SQL database through `TEXT2SQL_DATABASE_URL`; the material does not describe multi-database orchestration. Database support beyond SQLite depends on installing the relevant extra and driver. Query results are limited to 100 rows by default unless a different `max_rows` value is supplied.

The agent uses an LLM provider key, so model availability and behavior depend on the selected Anthropic or OpenAI configuration.

_Full upstream README: https://allmcps.com/mcp/text2sql/readme_

