Repository navigation
Show and tell: Hardening Private Text-to-SQL & MCP Tool Backends — Read-Only Guardrails & Stdio Isolation for Local Models #2433
A7mdMe
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Background: Operating Text-to-SQL & MCP Tools with Local Models
In private enterprise deployments of PrivateGPT, organizations frequently connect local LLMs (Llama 3, Mistral, Qwen) to internal databases and tools via the Model Context Protocol (MCP).
When running Text-to-SQL workflows on local models, two specific operational concerns arise:
Higher SQL Hallucination Variance in Local Weights:
Local open-weights models, while powerful for data sovereignty, have a higher variance in structured output generation than frontier cloud APIs. When synthesizing queries for complex schemas, local models can inadvertently output mutating SQL commands (
DROP TABLE,ALTER,UPDATE, or stacked semicolon statements).Stdio Stream Framing Integrity for Subprocess Tools:
When launching custom TypeScript MCP tools as local subprocesses, arbitrary
console.log()statements write tostdout. Because MCP stdio communication relies entirely on clean JSON-RPC 2.0 frames onstdout, unhandled logging corrupts protocol message boundaries and crashes host client parsers.Layered Defense: Application-Level Query Inspection + Read-Only Database Roles
To enable safe Text-to-SQL exploration for local models without risking schema corruption, the open-source MCP Production Kit implements an application-level token & regex inspection pipeline:
--and/* */SQL comments commonly used to mask stacked injection payloads.status = 'DROP_PENDING') don't trigger false alarms.SELECTorWITH, and validates against 16 mutation keywords (DROP,DELETE,TRUNCATE,ALTER,UPDATE,INSERT,CREATE,REPLACE, etc.).(Note: This application-level guardrail uses token & regex sanitization, not a full SQL AST compiler, and is engineered to work in tandem with database-level read-only permissions like
GRANT SELECT).Dual-Stream Stdio Logging
Redirects all diagnostic, audit, and operational logging strictly to
process.stderr, keepingprocess.stdoutdedicated exclusively to JSON-RPC 2.0 protocol communication:Architecture Comparison: Open-Source Core vs. Pro Pack ($19 USD)
USER nodeMaintainer Disclosure & Community Discussion
Disclosure: I am the maintainer of MCP Production Kit and author of the commercial Pro Pack add-on on Whop.
We'd love feedback from the PrivateGPT community:
All reactions