Grain SQL

السجل الرسمي البيانات وقواعدها

Run SQL queries and inspect database schemas through safe, visible MCP tools.

التثبيت

أضف هذا إلى إعدادات MCP في عميلك (Claude Desktop: claude_desktop_config.json، وCursor: ‏.cursor/mcp.json، ويستخدم VS Code وغيره الصيغة نفسها «mcpServers»).

NPM package grain-tools
Claude Code
claude mcp add grain-sql -e 'GRAIN_CONNECTIONS=<your grain_connections>' -e 'GRAIN_MCP_SAFE_MODE=<GRAIN_MCP_SAFE_MODE>' -e 'GRAIN_MAX_ROWS=<GRAIN_MAX_ROWS>' -- npx -y grain-tools@0.10.39 --stdio
إعداد JSON (Claude Desktop وCursor وVS Code)
{
    "mcpServers": {
        "grain-sql": {
            "command": "npx",
            "args": [
                "-y",
                "grain-tools@0.10.39",
                "--stdio"
            ],
            "env": {
                "GRAIN_CONNECTIONS": "<your grain_connections>",
                "GRAIN_MCP_SAFE_MODE": "<GRAIN_MCP_SAFE_MODE>",
                "GRAIN_MAX_ROWS": "<GRAIN_MAX_ROWS>"
            }
        }
    }
}

متغيرات البيئة

  • GRAIN_CONNECTIONS سري JSON array of Grain connection profiles for headless use.
  • GRAIN_MCP_SAFE_MODE Set to false to allow mutating SQL. Defaults to true.
  • GRAIN_MAX_ROWS Maximum rows returned by query tools. Defaults to 10000.

التوثيق

مأخوذ من ملف README للمشروع على GitHub ويُحدَّث أسبوعيًا. تفتح الروابط على GitHub.

المحتويات
  1. Grain
  2. Quick start
  3. Use Grain from an AI agent
  4. Features
  5. Supported databases
  6. Examples
  7. Privacy
  8. FAQ
  9. Getting help
  10. Star History
  11. License

Grain

A fast SQL workspace for VS Code, and for the AI agents you work with.

Docs · Changelog · Report a bug · Ask a question

Run SQL from any .sql file with Ctrl+Enter and get the results in a sortable grid inside VS Code. Passwords stay in your OS keychain, and Grain has no hosted service.

Quick start

  1. Install Grain from the VS Code Marketplace or Open VSX (for Cursor, Windsurf, and VSCodium).
  2. Open a folder in VS Code. Grain adds its demo files there.
  3. Open the Grain panel and click Try the Demo.
  4. Put your cursor in any query in the file that opens and press Ctrl+Enter (Cmd+Enter on macOS).

The demo reads two CSV files through Grain's built-in DuckDB connection, so there's nothing to set up. To query your own database, run Grain: Manage Connections, add a profile, and test it before you save.

If Grain is useful to you, a star on this repo helps other developers find it.

Use Grain from an AI agent

Grain can serve your database connections to Claude Code, Cursor, and GitHub Copilot over MCP. Agents get read-only access by default, and every query an agent runs shows up in your Grain results panel, so you can see exactly what it did.

MCP is off until you turn on grain.mcpEnabled in settings. Setup steps for each client are in the MCP docs, and example prompts are in examples/agents/.

Features

FeatureWhat it does
Run from the editorCtrl+Enter runs the file; Run Query Under Cursor runs one statement; Run Query in New Tab keeps the previous result
Non-blocking queriesQueries run in a background process, so a slow query doesn't freeze VS Code
Connection managerCreate, test, and switch database profiles without editing JSON
Result gridSort, filter, and resize columns, see each column's SQL type, copy a selection as TSV
Full exportThe grid shows the first 500 rows; export re-runs the query and writes every row to CSV, TSV, or JSON
Agent access over MCPClaude Code, Cursor, and Copilot can query your connections; their results land in your panel
Remote setupsWorks over WSL, dev containers, GitHub Codespaces, and Remote - SSH

Supported databases

Relational databases

PostgreSQL

MySQL

SQL Server

SQLite

Data warehouses

Snowflake

BigQuery

Query engines & lakehouses

Trino / Presto

DuckDB

Search

Elasticsearch

Through Trino or Presto you can query your cluster's Iceberg, Delta Lake, and Hive tables. DuckDB queries local CSV and Parquet files directly.

PostgreSQL and Trino / Presto are bundled with the extension. The others load their driver on first use, and if a driver is missing, Grain tells you what to install.

Need another database? Request a connector. Requests with the most 👍 get built first.

Examples

Runnable queries for Postgres, MySQL, Elasticsearch, and DuckDB, plus agent prompts. Open any .sql file with Grain installed and press Ctrl+Enter.

Privacy

  • Your SQL, results, and passwords stay on your machine. Passwords are stored in VS Code Secret Storage, backed by your OS keychain, and never in a settings file.
  • Agents are read-only by default. With grain.mcpSafeMode on (the default), agents can only run SELECT, SHOW, DESCRIBE, EXPLAIN, WITH, and metadata queries. Agents can't read stored passwords or change saved connections.
  • Telemetry is anonymous. Grain sends usage data that never includes SQL, results, credentials, hostnames, or schema names. Turn it off with grain.telemetry.enabled.

FAQ

Is Grain open source?\ No. Grain is closed-source. This repo holds the issue tracker, docs, and examples.

Which databases does it support?\ The nine listed above. To ask for another one, request a connector.

Do my queries or passwords leave my machine?\ No. There's no Grain server. Queries go straight from VS Code to your database, and passwords stay in your OS keychain. See Privacy for what the anonymous telemetry does and doesn't include.

How do I connect Claude Code or Cursor?\ Turn on grain.mcpEnabled, then follow the steps for your client in the MCP docs.

Why does my database show a driver error?\ Some connectors load their driver on first use. The error message names what to install. If it's still failing after that, file a bug report with the Output panel logs (View → Output → Grain).

Getting help

We don't have a fixed roadmap yet. What we build next depends a lot on what people ask for here, especially connector requests. See CONTRIBUTING.md for how to file a good issue.

Star History

License

Grain is closed-source. See LICENSE.

الأسئلة الشائعة

ما هو Grain SQL؟

Run SQL queries and inspect database schemas through safe, visible MCP tools.

كيف أثبّت Grain SQL؟

يعمل على جهازك. في Claude Code: claude mcp add grain-sql -e 'GRAIN_CONNECTIONS=<your grain_connections>' -e 'GRAIN_MCP_SAFE_MODE=<GRAIN_MCP_SAFE_MODE>' -e 'GRAIN_MAX_ROWS=<GRAIN_MAX_ROWS>' -- npx -y grain-tools@0.10.39 --stdio. وفي العملاء الآخرين، الصق إعداد JSON من هذه الصفحة في إعدادات MCP الخاصة بهم.

هل يحتاج Grain SQL إلى مفتاح API؟

نعم. يتطلب GRAIN_CONNECTIONS، وتضبطها في إعداداته.

هل Grain SQL مفتوح المصدر؟

شيفرته علنية على GitHub، لكن المستودع لا يعلن ترخيصًا قياسيًا.

من يصون Grain SQL؟

ينشره pattrnlabs. يدرجه AI.tn لكنه لا يصونه ولا يوصي به.

من سجل MCP الرسمي. الإدراج ليس توصية: راجع شيفرة الخادم وصلاحياته قبل منحه الوصول إلى بياناتك.