SQLLens.AI Docs
AI · Agents

MCP & AI database access

Connect Copilot Agent, Cursor, and chat to your saved SQLLens profiles. Agents can discover schema, run read-only queries, and — when you allow it — apply controlled writes — without exposing passwords or manual MCP wiring inside the editor.

Animated demo: AI agent generates SQL in the editor.
Agents and copilot share the same SQL editor and AI stack.
Animated demo: MCP uses saved connections in the SQL workspace.
MCP tools run against the same explorer, editor, and results you use manually.

What it is

SQLLens registers as an MCP server (Model Context Protocol) named SQLLens. When enabled, AI clients in VS Code or Cursor can use your saved connection profiles on this machine to:

This is separate from inline SQL generation (LLMs & AI): MCP gives agents structured tools to inspect and query live databases through SQLLens, similar to how DBCode exposes database context to an agent.

Diagram: Chat or Agent mode connects through SQLLens MCP to saved connection profiles and the database.
Agent or chat → SQLLens MCP → saved profiles → one connection + one database per operation.

VS Code & Cursor

When SQLLens is installed and MCP is enabled, the extension auto-registers the SQLLens MCP server with the editor. You do not need to edit mcp.json for in-editor Agent or chat use.

WhereWhat you see
Copilot Agent / Cursor AgentEnable SQLLens in the tools or MCP picker, then ask natural-language questions about your data.
Extension HostSQLLens must be running — use an installed build or Run Extension (F5) during development.
First useA one-time consent modal explains what agents can access; choose Allow to register tools.
Installed vs F5

Both the Marketplace extension and a debug (F5) session register MCP. Saved connections are the same profiles you use in the SQLLens sidebar — save at least one before asking agents to query.

@sql and @sqllens chat

SQLLens also registers two chat participants in supported editors:

MentionNamePurpose
@sqlsqlDatabase assistant backed by the same MCP tools.
@sqllensSQLLensSame behavior — use whichever mention your editor suggests.

Open chat, type @sql or @sqllens, then:

Example:

@sql list connections

@sqllens /schema

@sql run this query:
```sql
SELECT region, COUNT(*) AS n
FROM customers
GROUP BY region
ORDER BY n DESC
LIMIT 10
```

When an SQL editor tab has an Active database (see per-file database context), chat uses that connection by default.

Agent mode (natural language)

For multi-step questions, use Agent mode (Copilot Agent in VS Code, Agent in Cursor):

  1. Ensure SQLLens is running and you accepted the first-time MCP consent.
  2. Open the agent tools picker and enable SQLLens.
  3. Ask in plain language — the agent chains tools (connections → schema → query) without you writing SQL first.

Example prompts:

The agent picks the right tool calls; you review results in the chat thread. For a single known query, @sql with a SQL block is often faster.

Connection scope

MCP and chat work against all saved profiles in SQLLens — not only the sidebar Active badge.

ConceptBehavior
Default contextWhen you do not name a connection, tools use the active SQL tab binding or last-used tree context — same rules as Run SQL.
Any saved profileAgents can list every saved connection and target a specific one by name or id when you ask.
One operationEach tool call uses one connection and one database or schema.
EnginesMySQL, MariaDB, PostgreSQL, and SQLite profiles are all listed; engine type is included in connection metadata.

To align chat with a tab, set Active on the database in the connection tree or use /connect after naming the profile.

SQLite profiles

Each SQLite saved profile points at one database file. Agents are not limited to whichever SQLite file is active in the editor — name the profile (for example “ecommerce sample”) and the agent can query that file even when another tab is focused.

Use /disconnect or agent disconnect tools when you need to release file locks before external tools touch the same .db file.

Safety & privacy

Defaults are conservative:

SettingDefaultEffect
sqllens.ai.mcp.enabledonRegister SQLLens with MCP clients.
sqllens.ai.mcp.readOnlyonOnly SELECT-style reads through query tools.
sqllens.ai.mcp.allowWritesoffDML, DDL, and copy-data require read-only off and this on.

Search Settings for sqllens.ai MCP to adjust all keys. Only enable writes if you trust every agent and client that can reach these tools.

What agents can do (tool summary)

Agents and chat map to a small set of database tools:

CapabilityTypical useWrites
List connectionsDiscover saved profiles and default context—
List databases / schemasPick a catalog after choosing a connection—
Table & column metadataSchema discovery before querying—
Execute querySELECT (and read-only introspection)Read
Execute DMLINSERT, UPDATE, DELETERequires write settings
Execute DDLCREATE, ALTER, DROP, TRUNCATERequires write settings
Copy dataSELECT → insert into another table (row cap applies)Requires write settings
Connect / disconnectOpen or release pooled connections—

External MCP listener (optional)

Inside VS Code or Cursor, MCP uses the built-in registration — no extra listener. For external clients (for example Claude Desktop on the same machine), you can start an optional local listener:

  1. Run the command SQLLens: Start external MCP listener from the Command Palette.
  2. Point your external MCP client at the local listener (default port 5012 on this machine).
  3. Stop with SQLLens: Stop external MCP listener when finished.
Technical note

Default bind is localhost only. Optional Settings control auto-start on launch, port, bearer authorization, and whether other machines on your network may connect. Keep localhost-only unless you understand the exposure.

The extension must stay running while an external client connects — same as for in-editor MCP.

Getting started

  1. Install SQLLens from the Marketplace (or F5 from source).
  2. Save a connection — Connect a database and store at least one profile.
  3. Open an SQL file (optional) and set Active on the database you want as default.
  4. First MCP use — enable Agent tools or @sql; accept the consent modal.
  5. Try a prompt — “@sql list connections” or Agent: “What tables exist in my active database?”
  6. Tune safety — leave read-only on until you explicitly need agent-driven writes.

Related: LLMs & AI for editor CodeLens and assist panel; Explorer & active database for how Active context is chosen.

Tips & limits