cubrid-mcp-server bridges a CUBRID database and any MCP-speaking LLM client. Treat every query coming from the model as untrusted input: the LLM may hallucinate destructive SQL, and a malicious prompt may try to exfiltrate data the bot was never meant to see. Defence in depth is the design intent.
Run the server as a dedicated CUBRID user that has only the privileges you want the model to use. The code-level safety checker is not a substitute for this.
Minimum recommended setup for an exploration/analytics workload:
-- 1. Create the user
CREATE USER mcp_reader PASSWORD 'replace-me';
-- 2. Grant SELECT only on the specific tables you want exposed.
-- CUBRID grants privileges per table (there is no schema-wide `db.*` grant).
GRANT SELECT ON customers TO mcp_reader;
GRANT SELECT ON orders TO mcp_reader;
-- ...repeat for each table the model may read.
-- 3. Do NOT grant CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, GRANT, or any DBA role.Additional hardening:
- Use a long, randomly generated password. Store it in a secret manager — never commit
.envfiles. - Rotate the password on the same cadence as the rest of your database credentials.
- If the LLM only needs a subset of tables, grant
SELECTon those tables specifically rather than the whole schema. - Restrict network reachability: run CUBRID on a private network and only expose it to the host running the MCP server.
A
SELECT-only grant does not stop every write. CUBRID lets a user who may onlySELECTfrom a table change data through the read itself:INCR(col)andDECR(col)update the row they read, the click counterSELECT ... WITH INCREMENT FOR col(orWITH DECREMENT FOR col) does the same, andserial.NEXT_VALUE,serial.NEXTVALandSERIAL_NEXT_VALUE(serial, n)advance a serial, even one the user was granted nothing on. These changes persist: the rollback that ends every read does not undo them. The read-only checks (Layer 2) reject these forms, andexecute_queryrejects them withCUBRID_MCP_READONLY=0too.
When CUBRID_MCP_READONLY=1 (the default) the server parses every statement with sqlparse and rejects anything that is not SELECT, SHOW, DESC, DESCRIBE, or WITH (CTE). CUBRID has no EXPLAIN statement; use the explain_query tool for execution plans. Multi-statement input is rejected. Comments, quotes and statement boundaries are read with CUBRID's rules, not sqlparse's: --, // and /* ... */ are comments (block comments do not nest), # is not a comment, and a backslash is an ordinary character inside quotes. Input whose quote boundaries depend on whether a backslash escapes a quote (the server parameter no_backslash_escapes), or that has an unterminated quote, is rejected. The first word of the statement must itself be an allowed keyword, so KILL (SELECT 1) or EVALUATE (SELECT 1) is not read as a SELECT.
Read-only mode also rejects the CUBRID forms that change data inside a SELECT, which a SELECT-only grant does not prevent (see Layer 1): the functions INCR and DECR, the serial advances NEXT_VALUE, NEXTVAL and SERIAL_NEXT_VALUE, and the click counter WITH INCREMENT FOR / WITH DECREMENT FOR. A name is matched when it is called (followed by () or used as an attribute (after ., as in owner.serial.NEXT_VALUE), in any case, bare or quoted ("INCR", [incr], `incr`), with any whitespace or comments in between, anywhere in the statement, including subqueries and CTEs. String literals and longer names such as incr_total are not matched. CURRENT_VALUE, CURRVAL and SERIAL_CURRENT_VALUE only read a serial and stay allowed. A column that has one of these names is rejected when it is qualified (t.next_value); select it unqualified instead.
These keyword checks are a guardrail and defense-in-depth, not a security boundary. The primary control is a dedicated least-privilege database account (Layer 1): grant SELECT only on the tables the model needs, do not reuse dba or the owner account, and keep the account to the minimum privileges required, with no DDL rights.
You can disable this layer by setting CUBRID_MCP_READONLY=0, but only do so when:
- the underlying DB user is already read-only (Layer 1 is in place), and
- you genuinely need statements outside the whitelist (for example, CUBRID administrative
SHOWvariants that confuse the parser).
With CUBRID_MCP_READONLY=0, execute_query still rejects statements that lead with a write, DDL or transaction-control keyword, method calls (CALL, EVALUATE) and KILL. CALL login(...) ON CLASS db_user would otherwise switch the user of the cached shared session for every later tool call; execute_write and explain_query reject it too, so no tool can change the session user. It also rejects INCR, DECR, serial advances and the click counter, as read-only mode does: they change data although the statement returns a result set.
explain_query always applies the read-only checks, independent of CUBRID_MCP_READONLY; only execute_query honors CUBRID_MCP_READONLY=0. Note that explain_query executes the SELECT/WITH statement under SET TRACE ON to produce the trace and then rolls the transaction back as best-effort cleanup, so it uses real database resources.
Write access is off by default. Setting CUBRID_MCP_WRITE=1 registers a separate execute_write tool that accepts a single INSERT/UPDATE/DELETE statement and runs it in an explicit transaction (commit on success, rollback on any failure). Design constraints that bound the blast radius:
- DML only. Standalone reads, DDL, transaction-control, and multi-statement input are rejected by a dedicated whitelist (
ensure_write_allowed), separate from the read-only path. (A single DML statement may still legally embed subqueries, e.g.INSERT ... SELECT.) - DDL is intentionally unsupported.
execute_writeis a DML tool (INSERT/UPDATE/DELETE) andexecute_queryis read-only, soCREATE/ALTER/DROP/TRUNCATEare rejected by both. (The server runs pycubrid with autocommit off; on the CUBRID versions tested (10.2, 11.2, 11.4) DDL is transactional and is rolled back if it is not committed, so the exclusion rests on the tool contracts, not on DDL auto-commit.) - Not registered when disabled. With write mode off,
execute_writeis absent from MCP capability discovery — the tool is simply not offered. The database account remains what actually limits writes. execute_querystays read-only regardless of the write flag.
As with the read-only layer, this is defense-in-depth: still run the server as a CUBRID user granted only the privileges the model needs.
execute_query caps the number of rows returned at CUBRID_MCP_MAX_ROWS (default 1000) and truncates rendered output once the cumulative character count exceeds CUBRID_MCP_MAX_CHARS (default 4000). Together these protect the model's context window and limit how much data a single probing query can exfiltrate in one shot. Binary values are base64-encoded when small and summarized (<binary N bytes>) when large, so raw blobs never flood the output.
Set CUBRID_MCP_AUDIT_LOG=1 to emit a structured JSON record on stderr for every executed statement (execute_query, explain_query, execute_write), for observability and after-the-fact security review. It is off by default and honoured per connection (CUBRID_<NAME>_MCP_AUDIT_LOG), so with audit logging off, write-mode statements are not audited either.
Audit records are deliberately redaction-safe and share the same sanitization guarantees as client-facing errors:
- Only the statement category (leading keyword, read after comments and string literals are stripped) and table identifiers (extracted via a strict identifier regex) are recorded — never the raw SQL text.
- Bound parameters and literal values are never logged, so a secret embedded in a query (
WHERE token = '…') does not appear in the audit stream. - Failures record the exception class name only (via
sanitize_error), never the raw driver message. - Records go to
stderronly;stdoutremains reserved for the MCP protocol stream.
This complements — but does not replace — CUBRID's own server-side query logging.
Because this server exposes database access to an LLM via MCP, the threat surface differs from a conventional database client. Operators must understand what the safety checker prevents and what it does not.
- Data mutation —
INSERT,UPDATE,DELETE,REPLACE,MERGE - Schema changes —
CREATE,DROP,ALTER,TRUNCATE,RENAME - Privilege escalation —
GRANT,REVOKE - Transaction control —
COMMIT,ROLLBACK - Server-side procedures and methods —
CALL,EXECUTE,EVALUATE, includingCALL login(...) ON CLASS db_user, which would change the session user - Ending other sessions' transactions —
KILL - Row-level locking —
SELECT ... FOR UPDATE,LOCK - Multi-statement injection —
;separated batches are rejected outright - Comment-based obfuscation — SQL comments (
--,//,/* ... */, read with CUBRID's rules) are stripped before the keyword scan, so a comment cannot hide the real leading keyword
- Data exfiltration —
SELECT password_hash FROM usersis allowed. The checker only blocks mutation; it cannot know which columns are sensitive. - Information disclosure — Schema metadata, table names, row counts, and index definitions are all readable.
- Resource exhaustion — An LLM can be instructed to run expensive full-table scans repeatedly. There is no per-query cost limit.
- Dedicated read-only DB user — Create a CUBRID user with
SELECT-only grants at the table level (see Layer 2 above). - Restrict sensitive tables — Exclude tables containing credentials, PII, or other secrets from the user's grants.
- Network isolation — Run the MCP server in a network segment where the LLM cannot reach the database directly.
- Audit logging — Enable CUBRID query logging and monitor for unusual
SELECTpatterns.
A planned enhancement will allow operators to restrict which tables the LLM can query via an allow-list environment variable. This will provide defense-in-depth against data exfiltration at the application layer, complementing (not replacing) database-level grants.
Please do not open a public GitHub issue for security-sensitive reports. Instead, email paikend@gmail.com with:
- A description of the issue and its impact.
- The smallest reproduction you can share.
- Any suggested mitigation.
You should receive an acknowledgement within three business days. Coordinated disclosure is appreciated — please give the maintainers a reasonable window to ship a fix before going public.
Only the latest published release receives security fixes. Upgrade to the latest release before reporting an issue, or state the exact version you reproduced it on.