How We Automated SQL Standards Forever with a 48-Line MCP Server

How We Automated SQL Standards Forever with a 48-Line MCP Server
Every data team has been there. A new engineer joins, writes their first dbt model, and the PR review turns into a documentation seminar. "Please follow our staging patterns." "Check the CTE structure guide." "We use different naming conventions." Thirty minutes later, you're still posting links to the same four documentation pages you shared last week.
We solved this problem permanently with 48 lines of code. Here's how.
The Hidden Cost of SQL Standards
Let's do the math that nobody wants to do. A typical mid-market data team:
- Reviews 50+ dbt models monthly
- Spends 20-30 minutes per review on standards compliance
- Has 3-5 engineers writing SQL daily
- Maintains 100+ pages of documentation that nobody reads
That's 25 hours monthly just enforcing standards. Not improving logic. Not catching bugs. Just ensuring people follow the patterns your team agreed on two years ago.
The real cost isn't even the time. It's the inconsistency. Despite all the documentation, every engineer develops their own style. Your staging folder looks like five different teams built it. Your marts have three different CTE patterns. And every new hire adds their own flavor to the mix.
Why Documentation Always Fails
We've tried everything:
- Comprehensive wikis that nobody updates
- SQL linting rules that catch syntax but miss patterns
- PR templates that get ignored
- Team workshops that work for a week
The problem isn't the documentation.
It's the gap between knowing the standard and applying it consistently.
Developers using AI assistants like Claude face an additional challenge: the AI doesn't know your team's patterns. It writes functional SQL, sure, but it's generic. Every query needs manual cleanup to match your standards.
Enter MCP: Making Standards Executable
Model Context Protocol (MCP) servers change the game entirely. Instead of documenting your standards, you encode them. Instead of reviewing for compliance, you prevent violations from being written. Think of MCP as a knowledge layer between your AI assistant and your code. When Claude tries to write SQL, the MCP server intercepts and says: "Here's how we actually do things here."
We built our MCP server to enforce:
- dbt's official best practices for staging/intermediate/marts
- Our specific CTE naming patterns
- Import structures that match our project layout
- Column naming conventions
- Documentation requirements
The beauty? It's not a linter that complains after the fact. It's a guide that ensures correct output from the start.
Building the Solution with FastMCP
The server intercepts every SQL generation request and injects our standards. Claude doesn't even know it's being guided—it just naturally produces SQL that matches our patterns perfectly.
Key components we implemented:
- Pattern Templates: Pre-structured staging, intermediate, and marts patterns
- Naming Conventions: Automatic prefixing and standardized CTE names
- Import Management: Correct ref() structures based on model location
- Documentation Stubs: Auto-generated column descriptions and tests
Implementation: From Idea to Production
The rollout was surprisingly smooth: Week 1: Built and tested the MCP server with one developer. Immediate feedback: "This is how I always wanted Claude to work." Week 2: Extended to the full data team. Added team-specific patterns for different data sources (Shopify, GA4, internal systems). Week 3: Refined based on edge cases. Added support for incremental models and snapshots. Week 4: Open-sourced the base framework. Three other Danish tech companies are now using variations.
The technical setup is straightforward:
- Install FastMCP
- Configure your standards in JSON/YAML
- Point your AI assistant to the local MCP server
- Start writing SQL
No infrastructure changes. No CI/CD modifications. Just better SQL from day one.
Results: 25 Hours Saved Monthly
The numbers after two months: Review time: Down from 30 minutes to 5 minutes per model Consistency score: 95% adherence to standards (up from 60%) Onboarding time: New engineers productive in 2 days vs 2 weeks Documentation updates: Zero (the code IS the documentation) But the real win is psychological. Senior engineers stopped dreading PR reviews. Junior developers gained confidence knowing their code matches team standards. The entire team started experimenting more because the basics were guaranteed correct.
What This Means for Data Teams This isn't just about SQL standards. It's about the future of team knowledge. Every mature data team has "the way we do things." Until now, that knowledge lived in documentation, Slack threads, and senior engineers' heads. MCP servers make that knowledge executable and shareable.
Imagine:
- Your transformation patterns encoded and reusable
- Your debugging approaches built into the tools
- Your optimization strategies applied automatically
- Your entire team's expertise available to every member instantly
We're moving from teaching standards to embedding them. From reviewing for compliance to preventing violations. From tribal knowledge to executable expertise.
