Skip to content

Add --readonly CLI flag to prevent all write operations#30

Open
noxymon-mekari wants to merge 1 commit intoexecuteautomation:mainfrom
noxymon-mekari:feature/readonly-mode
Open

Add --readonly CLI flag to prevent all write operations#30
noxymon-mekari wants to merge 1 commit intoexecuteautomation:mainfrom
noxymon-mekari:feature/readonly-mode

Conversation

@noxymon-mekari
Copy link

Summary

  • Add --readonly CLI flag that acts as a hard safety toggle to prevent all write operations when connecting to databases
  • Hide write tools from AI agent's tool list entirely in readonly mode (defense in depth)
  • Reject write tool calls with a clear error message if called directly despite being hidden
  • Fix SQLite path parsing to handle flags in any position (--readonly /path/to/db previously broke because args[0] picked up the flag instead of the path)

Motivation

AI agents using this MCP server can execute arbitrary write operations (INSERT, UPDATE, DELETE, CREATE/ALTER/DROP TABLE). When connecting to production or shared databases, users need a hard guarantee that no writes can occur regardless of what the
agent attempts.

How it works

# Append --readonly to any database command
node dist/src/index.js --readonly /path/to/database.db
node dist/src/index.js --readonly --postgresql --host localhost --database mydb

Write tools blocked in readonly mode:

┌────────────────┬────────────────────────────┐
│      Tool      │         Operation          │
├────────────────┼────────────────────────────┤
│ write_query    │ INSERT, UPDATE, DELETE     │
├────────────────┼────────────────────────────┤
│ create_table   │ CREATE TABLE               │
├────────────────┼────────────────────────────┤
│ alter_table    │ ALTER TABLE                │
├────────────────┼────────────────────────────┤
│ drop_table     │ DROP TABLE                 │
├────────────────┼────────────────────────────┤
│ append_insight │ INSERT (business insights) │
└────────────────┴────────────────────────────┘

Read-only tools always available:
read_query, export_query, list_tables, describe_table, list_insights

Defense in depth:
1. Write tools are removed from ListTools response — the AI agent never sees them
2. If a write tool is called directly anyway, it returns isError: true with a clear message

When the server is started with --readonly, write tools (write_query,
create_table, alter_table, drop_table, append_insight) are hidden from
the AI agent's tool list and rejected with a clear error if called
directly. This provides a hard safety toggle for connecting to
production databases.

Also fixes SQLite path parsing to handle flags in any position
(previously args[0] broke if --readonly came before the db path).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants