text2sql

Registre officiel Données et bases de données

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

Que pouvez-vous faire avec text2sql ?

  • query(question, max_rows=100) — ask the database a natural-language question. Returns {sql, data, error, row_count, tool_calls_made}.

Installation

Ajoutez ceci à la configuration MCP de votre client (Claude Desktop : claude_desktop_config.json ; Cursor : .cursor/mcp.json ; VS Code et les autres utilisent la même forme « mcpServers »).

PYPI package text2sql-mcp
Claude Code
claude mcp add text2sql -e 'TEXT2SQL_DATABASE_URL=<TEXT2SQL_DATABASE_URL>' -e 'ANTHROPIC_API_KEY=<your anthropic_api_key>' -e 'OPENAI_API_KEY=<your openai_api_key>' -e 'TEXT2SQL_MODEL=<TEXT2SQL_MODEL>' -- uvx text2sql-mcp==0.1.2
Configuration JSON (Claude Desktop, Cursor, VS Code)
{
    "mcpServers": {
        "text2sql": {
            "command": "uvx",
            "args": [
                "text2sql-mcp==0.1.2"
            ],
            "env": {
                "TEXT2SQL_DATABASE_URL": "<TEXT2SQL_DATABASE_URL>",
                "ANTHROPIC_API_KEY": "<your anthropic_api_key>",
                "OPENAI_API_KEY": "<your openai_api_key>",
                "TEXT2SQL_MODEL": "<TEXT2SQL_MODEL>"
            }
        }
    }
}

Variables d'environnement

  • TEXT2SQL_DATABASE_URL obligatoire SQLAlchemy connection URL, e.g. sqlite:///mydb.db or postgresql://user:pass@host/db
  • ANTHROPIC_API_KEY secret Anthropic API key (required if using the default Anthropic model)
  • OPENAI_API_KEY secret OpenAI API key (required when TEXT2SQL_MODEL is set to an openai:* model)
  • TEXT2SQL_MODEL Optional LangChain model id (default: anthropic:claude-sonnet-4-6)

Documentation

Tirée du README du projet sur GitHub, actualisée chaque semaine. Les liens ouvrent GitHub.

Sommaire
  1. text2sql-mcp
  2. Install
  3. Configure
  4. Tools
  5. How it works
  6. License

text2sql-mcp

MCP server for text2sql-framework. Plugs into Claude Desktop, Cursor, Goose, or any other MCP-compatible assistant and lets it ask a SQL database questions in natural language.

The agent explores the schema, writes SQL, executes it against the real DB, and self-corrects on errors — no RAG layer, no schema descriptions, no pre-computed embeddings.

Install

Out of the box, text2sql-mcp supports SQLite + Anthropic:

pip install text2sql-mcp
# or
uvx text2sql-mcp

For other databases or LLM providers, install with the matching extra so the right driver gets installed:

You want…Install command
SQLite (default)uvx text2sql-mcp
Postgresuvx 'text2sql-mcp[postgres]'
MySQLuvx 'text2sql-mcp[mysql]'
Snowflakeuvx 'text2sql-mcp[snowflake]'
BigQueryuvx 'text2sql-mcp[bigquery]'
OpenAI modelsadd openai, e.g. uvx 'text2sql-mcp[postgres,openai]'

Configure

Set environment variables in your MCP client config:

VariableRequiredDescription
TEXT2SQL_DATABASE_URLyesSQLAlchemy URL, e.g. sqlite:///mydb.db, postgresql://user:pass@host/db
ANTHROPIC_API_KEY or OPENAI_API_KEYyesLLM provider key
TEXT2SQL_MODELnoLangChain model id (default: anthropic:claude-sonnet-4-6)
TEXT2SQL_INSTRUCTIONSnoBusiness rules / hints, e.g. "Revenue = net of refunds."
TEXT2SQL_EXAMPLESnoPath to a scenarios.md file for the agent's lookup_example tool
Claude Desktop / Cursor / generic MCP
{
  "mcpServers": {
    "text2sql": {
      "command": "uvx",
      "args": ["text2sql-mcp"],
      "env": {
        "TEXT2SQL_DATABASE_URL": "sqlite:///mydb.db",
        "ANTHROPIC_API_KEY": "sk-ant-..."
      }
    }
  }
}
Goose CLI
goose configure
# Add Extension → Command-line Extension
# Name: text2sql
# Command: uvx text2sql-mcp
# Env: TEXT2SQL_DATABASE_URL, ANTHROPIC_API_KEY

Tools

  • query(question, max_rows=100) — ask the database a natural-language question. Returns {sql, data, error, row_count, tool_calls_made}.

How it works

Under the hood this is a thin wrapper around text2sql-framework, which uses LangChain Deep Agents to do iterative tool-calling against a single execute_sql tool. See the framework README for benchmarks (19/20 on Spider zero-shot across 80 tables) and architecture details.

License

MIT

Questions fréquentes

Qu'est-ce que text2sql ?

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

Comment installer text2sql ?

Il s'exécute sur votre machine. Dans Claude Code : claude mcp add text2sql -e 'TEXT2SQL_DATABASE_URL=<TEXT2SQL_DATABASE_URL>' -e 'ANTHROPIC_API_KEY=<your anthropic_api_key>' -e 'OPENAI_API_KEY=<your openai_api_key>' -e 'TEXT2SQL_MODEL=<TEXT2SQL_MODEL>' -- uvx text2sql-mcp==0.1.2. Pour les autres clients, collez la configuration JSON de cette page dans leurs réglages MCP.

Faut-il une clé API pour text2sql ?

Oui. Il attend TEXT2SQL_DATABASE_URL, ANTHROPIC_API_KEY, OPENAI_API_KEY, à renseigner dans sa configuration.

text2sql est-il open source ?

Oui. Son code est sur GitHub sous licence MIT.

Qui maintient text2sql ?

Il est publié par cpenniman12. AI.tn le référence sans le maintenir ni le recommander.

Issu du registre MCP officiel. Être listé n'est pas une recommandation : vérifiez le code et les permissions d'un serveur avant de lui donner accès à vos données.