Build with AI
SQG includes a built-in Model Context Protocol (MCP) server that lets AI assistants like Claude Code, Claude Desktop, and Cursor generate type-safe database code directly from SQL queries. This guide shows you how to set it up and use it.
What is MCP?
Section titled “What is MCP?”The Model Context Protocol is a standard that allows AI assistants to interact with external tools and services. SQG’s MCP server provides two tools:
generate_code: Generate type-safe database access code from SQL queries with SQG annotationsvalidate_sql: Validate SQL queries with SQG annotations without generating code
With MCP enabled, you can ask your AI assistant to:
- Generate TypeScript or Java code from SQL queries
- Validate SQL syntax and annotations
- Help debug SQL query issues
- Create complete database access layers
Prerequisites
Section titled “Prerequisites”Before setting up MCP, ensure you have:
- SQG installed - See the Installation section in the Getting Started guide for detailed instructions.
- An MCP-compatible AI assistant - Claude Code, Claude Desktop, Cursor IDE, or similar
Choose your AI assistant below and follow the configuration steps.
Configure Claude Code
Section titled “Configure Claude Code”Claude Code is Anthropic’s CLI tool for AI-assisted development.
-
Add SQG MCP Server
Run this command to add SQG as an MCP server:
Terminal window claude mcp add sqg -- sqg mcpOr for a project-local installation:
Terminal window claude mcp add sqg -- node ./node_modules/@sqg/sqg/dist/sqg.mjs mcp -
Verify Connection
Start Claude Code and verify the server is available:
Terminal window claudeThen type
/mcpto see connected servers. You should seesqglisted. -
Test It
Ask Claude Code to generate some code:
“Use the SQG generate_code tool to create TypeScript code for a users table with id, name, and email columns. Use typescript/sqlite.”
Configure Claude Desktop
Section titled “Configure Claude Desktop”-
Open Claude Desktop Settings
- macOS: Click the Claude menu → Settings → Developer → Edit Config
- Windows: Click Settings → Developer → Edit Config
- Linux: Click Settings → Developer → Edit Config
-
Add SQG MCP Server
Edit the configuration file and add SQG to the
mcpServerssection:{"mcpServers": {"sqg": {"command": "sqg","args": ["mcp"]}}}If
sqgis not in your PATH, use the full path:{"mcpServers": {"sqg": {"command": "node","args": ["/path/to/sqg/dist/sqg.mjs", "mcp"]}}}To find the path to SQG:
Terminal window # If installed globally with pnpmwhich sqg# Or check pnpm global binpnpm config get global-bin-dir -
Restart Claude Desktop
Close and reopen Claude Desktop to load the new MCP server configuration.
-
Verify Connection
In Claude Desktop, you should see SQG listed as an available tool. You can test it by asking:
“What tools are available from the SQG MCP server?”
Configure Cursor IDE
Section titled “Configure Cursor IDE”-
Open Cursor Settings
- Go to Settings → Features → Model Context Protocol
- Or open the MCP configuration file directly
-
Add SQG Server
Add SQG to your MCP configuration:
{"mcpServers": {"sqg": {"command": "sqg","args": ["mcp"]}}}For project-local installations, use the full path:
{"mcpServers": {"sqg": {"command": "node","args": ["./node_modules/@sqg/sqg/dist/sqg.mjs", "mcp"]}}} -
Restart Cursor
Restart Cursor IDE to load the MCP server.
-
Verify Integration
In Cursor, the SQG tools should be available when you use AI features.