What is the MCP? A simple explanationBuilding an AI chatbot in PostgreSQLThe retriever: api.sf_similar_itemsThe narrator: api.sf_answer_with_openaiThe orchestrator: api.sf_chatThe first working conversationMaking it more robust: Using embeddings.sf_get_query_embeddingThe dynamic SQL chatbotWhat does "dynamic" mean in our schemaA safe dynamic SQL executor (SELECT-only + LIMIT + Allowlist)What "safe" means in practiceA minimal "safe" query runner: api.sf_safe_selectTurning a question into SQL (the model proposes, the database enforces)How it works, step by stepThe dynamic chatbot: api.sf_dynamic_chatWhy don't we add embeddings.sf_get_query_embedding at this pointTeaching the assistant when to use semantic search vs.dynamic SQLThe two-lane mental modelA simple router: api.sf_route_chatHandling the hybrid question (the real world)A hybrid chat: Semantic candidates and SQL filtersWhy this still isn't "production-safe enough" (and why MCPh exists)Introducing the MCP: The contract between models and toolsWhat is the MCP?Why the MCP matters for database assistantsThe MCP and the core idea: One system, two truthsHow the MCP maps to what we've already builtThe practical payoff: Fewer prompts, more systemsWhere we go nextMCP-ready tool design for PostgreSQL: inputs, outputs, limits, and auditabilityWhat "MCP-ready" means for a database toolMaking api.sf_similar_items MCP-readyImprovement A: Separate "embedding computation" from "search execution"Improvement B: Make the row limit and safety explicitPlugging in embeddings.sf_get_query_embeddingMaking the narration tool MCP-readyThe final MCP-ready surface: the semantic tool and the dynamic toolThe MCP-ready semantic chat toolThe MCP-ready dynamic chat toolAdding an audit logWhy this is the correct setup for the MCPImplementing MCP tool routing for our PostgreSQL AI assistantThe MCP tool set we will route betweenA simple routing policyAdding production controls for MCP tools: Roles, timeouts, row caps, and cost guardsMCP tool contracts and safe views: Turning "function calls" into a reliable interfaceOperational checklists and the extension pathOperational checklist: Running the AI chatbot successfullyExtension path: What you can build beyond thisSummaryGet this book's PDF copy, code bundle, and more