MCP workflow
Investigate a database question with read-only SQL
Use a restricted PostgreSQL connection and a local memory notebook to answer a data question without touching production writes.
The problem
Data questions often start with an ambiguous metric and end with a production database. An agent can inspect schemas, propose queries, and summarize results, but the workflow must enforce read-only access and keep the analysis reproducible.
Why these components
Each server contributes a specific capability. The workflow is the contract between them.
PostgreSQL inspection, safe query execution, index health, and performance analysis.
Schema inspection · SQL queries · Index analysisstdioMemory MCP ServerA local knowledge graph for persistent entities, relations, and observations across sessions.
Create entities · Add observations · Create relationsstdioFilesystem MCP ServerScoped read and write access to local directories for reference and development workflows.
Directory listing · File read · File writePrerequisites
- A read-only PostgreSQL role or a restricted access mode supported by the server.
- Network access to a staging or read replica, not a production primary.
- The metric definition and a place to save the final SQL.
Step-by-step
Write down the question and metric
Define the entity, time window, filters, and denominator before writing SQL. Store the definition in the memory or filesystem server so it can be compared with the final query.
Verify: The definition answers what is counted and what is excluded.
Inspect the schema
List tables and columns, then identify the relevant join paths. Do not let the agent guess table names; require it to cite the inspected schema.
Verify: Every table and column used in the next step appears in the schema output.
Draft and limit the query
Write a query with an explicit row limit and date window. Run it against the read-only connection, then check for duplicates, null joins, and timezone assumptions.
Verify: The query runs with read-only permissions and returns a bounded result.
Cross-check the result
Run a simpler independent count or a second aggregation that should agree. Investigate differences instead of choosing the more convenient number.
Verify: The cross-check either agrees within a stated tolerance or the discrepancy is explained.
Save the reproducible analysis
Record the final SQL, schema assumptions, metric definition, and result date. A future reader should be able to rerun it without reconstructing the conversation.
Verify: The saved file contains the exact SQL and the connection context.
Generate a configuration for this workflow
Choose the client you use. The generator will preload 3 componentsand produce that client's documented format. Review every placeholder before saving.
The workflow does not imply that all components support the same transports in every client. The generator validates each entry and reports incompatibilities.
Permissions and security
- Use a read-only role and a staging or replica database for exploration.
- Query results may contain personal data; do not paste raw rows into public tickets or chats.
- Review generated SQL for performance before running it on any shared database.
Expected outcome
A reproducible SQL analysis with a defined metric, bounded queries, a cross-check, and a saved artifact. No write access is required.
Sources & evidence
- github.com/crystaldba/postgres-mcpRepository · checked Oct 23, 2026 · documented
The project documentation describes restricted access modes and read-oriented database tools.
- github.com/modelcontextprotocol/servers/tree/main/src/memoryRepository · checked Oct 23, 2026 · documented
The reference memory server provides persistent notes for analysis context.