ajan-sql is an MCP (Model Context Protocol) server that provides safe, read-only SQL access to PostgreSQL, MySQL, and SQLite databases for AI agents. Version 0.3.0 (as of this entry) enforces strict guardrails: only SELECT queries allowed, no INSERT/UPDATE/DELETE, no DDL, no multi-statement, no comments, result limit of 100 rows, and a 5-second timeout. It offers tools like list_tables, describe_table, run_readonly_query, and explain_query. Its key differentiator is that safety rules are enforced at the server level and cannot be bypassed, making it ideal for AI copilots and automation. Human approval flows are delegated to the MCP host. The package ships TypeScript types and can be run via npx or global install.
npm install ajan-sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to run ajan-sql via npx with environment variables and programmatic usage with runReadonlyQuery.
Use pagination or aggregate queries to work within the limit. There is no way to increase it.
Send each statement as a separate request.
Remove comments from SQL before sending.
Optimize queries or break them into smaller chunks.
Use environment variables (DATABASE_URL, DATABASE_DIALECT, etc.) instead of config file.
Set DATABASE_DIALECT to 'postgres', 'mysql', or 'sqlite'.
Ensure the SQL statement is a SELECT or use other tools like describe_table.
Shorten the query or break it into smaller parts.
Use dynamic import: const { runReadonlyQuery } = await import('ajan-sql'); or ensure 'type': 'module' in package.json.