dwagent-ai
v1.0.0
Published
AI-powered database assistant
Downloads
112
Maintainers
Readme
SQL Generation API
A powerful API service for converting natural language to SQL, validating SQL queries, and managing database schemas.
Use AI2SQL in Claude Code (MCP)
AI2SQL is available as an MCP server for Claude Code. Generate, explain, optimize and fix SQL queries without leaving your editor.
Quick Setup
Add to your Claude Code settings:
{
"mcpServers": {
"ai2sql": {
"command": "npx",
"args": ["-y", "ai2sql-mcp"]
}
}
}Available Tools
| Tool | Description |
|------|-------------|
| generate_sql | Convert natural language to SQL |
| explain_sql | Get plain English explanation of any query |
| optimize_sql | Performance optimization suggestions |
| fix_sql_error | Fix broken queries from error messages |
Supports PostgreSQL, MySQL, SQL Server, Snowflake, Oracle, and SQLite.
Features
Core API Services
- Text-to-SQL Conversion: Convert natural language queries to SQL statements
- SQL Validation: Validate SQL queries against your database schema
- Schema Management: Store and reference your database schema for better SQL generation
- Multiple SQL Dialects: Support for standard SQL, MySQL, PostgreSQL, SQL Server, and Snowflake
Authentication & Security
- API Key Authentication: Simple and secure API key-based authentication
- HTTPS-Only Access: All API endpoints are served over HTTPS
- Key Management: Create, revoke, and manage API keys through the dashboard
Usage & Rate Limits
- Flexible Plans: Different rate limits based on your subscription level
- Usage Analytics: Monitor your API usage with a comprehensive dashboard
- Clear Rate Limit Headers: X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers
Getting Started
Installation
Clone the repository:
git clone https://github.com/yourusername/dwagent-ai.gitInstall dependencies:
npm installSet up your environment variables:
cp .env.example .envUpdate the
.envfile with your database credentials and API keys.Run database migrations:
npm run prisma:migrateStart the development server:
npm run dev
Using the API
Authentication
All API requests require an API key to be included in the X-API-Key header:
const response = await fetch('https://api.example.com/api/sql/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your_api_key'
},
body: JSON.stringify({
text: 'Find all users who signed up in the last month',
dialect: 'mysql'
})
});Converting Text to SQL
// JavaScript Example
const response = await fetch('https://api.example.com/api/sql/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your_api_key'
},
body: JSON.stringify({
text: 'Find all users who signed up in the last month',
dialect: 'mysql',
prettify: true
})
});
const data = await response.json();
console.log(data.sql);# Python Example
import requests
response = requests.post(
'https://api.example.com/api/sql/generate',
headers={
'Content-Type': 'application/json',
'X-API-Key': 'your_api_key'
},
json={
'text': 'Find all users who signed up in the last month',
'dialect': 'mysql',
'prettify': True
}
)
data = response.json()
print(data['sql'])// PHP Example
$url = 'https://api.example.com/api/sql/generate';
$data = [
'text' => 'Find all users who signed up in the last month',
'dialect' => 'mysql',
'prettify' => true
];
$options = [
'http' => [
'method' => 'POST',
'header' => [
'Content-Type: application/json',
'X-API-Key: your_api_key'
],
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$result = json_decode($response, true);
echo $result['sql'];API Documentation
Interactive API documentation is available at /api-docs when running the server.
Key Endpoints
- POST /api/sql/generate - Convert natural language to SQL
- POST /api/sql/validate - Validate SQL query
- POST /api/sql/schema - Create or update a schema
- GET /api/sql/schema/:id - Get schema by ID
- POST /api/sql/apikey - Generate a new API key
- DELETE /api/sql/apikey/:id - Revoke an API key
- GET /api/sql/usage - Get API usage statistics
Dashboard
Access the API usage dashboard at /api-dashboard.html to monitor:
- Monthly API usage
- Query type breakdown
- API key management
- Usage statistics by API key
Rate Limits
API calls are subject to rate limiting based on your subscription plan:
- Free: 100 API calls per month
- Start: 1,000 API calls per month
- Pro: 5,000 API calls per month
- Business: 20,000 API calls per month
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Your Name - @yourtwitter - [email protected]
Project Link: https://github.com/yourusername/dwagent-ai
