From SQL Generation to Tool Selection: A Domain-Oriented Pattern for MCP Servers
Abstract
Agents built on Large Language Models (LLMs) increasingly reach enterprise data through the Model Context Protocol (MCP), and many MCP database servers maximize flexibility by exposing a single generic SQL execution tool. This paper proposes the Domain-Oriented Tooling Pattern: instead of generating SQL at query time, the model selects from a small set of domain-aligned tools whose parameterized queries encapsulate schema navigation, joins and business rules on the server side. We formalize the pattern around three architectural invariants and introduce Model Demotion, the observation that replacing SQL synthesis with intent classification lowers the model tier required to serve routine requests. As a reference implementation we present MCP Blueprint, an open-source framework in which domain tools are defined declaratively as YAML metadata plus external parameterized SQL files. We evaluate the pattern with a public reproducibility benchmark comparing three MCP server designs - raw SQL execution, a thin generic tool pack, and a verticalized domain pack - on four local models (3B-8B) across seventeen customer-facing tasks over the Sakila database (609 completed cells; temperature 0; three repetitions per cell). The verticalized pack reaches a pooled mean score of 0.939 versus 0.666 for raw SQL and 0.605 for the generic pack; the smallest model improves from 0.583 to 0.929, matching or exceeding every larger configuration while cutting cost per correct answer by an order of magnitude. All harness code, prompts, gold answers, frozen packs and per-cell results are publicly available.
Figures & tables
| Dimension | Generic SQL interface | Domain-oriented interface |
|---|---|---|
| Tool granularity | execute_sql() | customer_account_summary() , recommend_films() |
| Schema knowledge | Discovered from context per request | Implicit in reviewed tool contracts |
| Joins | Generated per request | Pre-authored and optimized |
| Business rules | Re-derived by the model | Embedded in server-side SQL |
| Model tier | Frontier models typical | Small models frequently sufficient |
| Output shape | Varies per run | Stable, documented columns |
| Approach | Surface | |
|---|---|---|
| A | Raw SQL | A single execute_sql tool; the DDL of the six task-relevant tables ( customer , film , category , film_category , inventory , rental ) is embedded in the system prompt. The schema fits entirely in context, so A is not handicapped by prompt size; schema understanding, SQL synthesis and multi-step orchestration are left to the model. |
| B | Verticalized pack | MCP Blueprint loading packs/sakila v0.5.0: five domain tools ( customer_account_summary , rental_history , recommend_films , film_stock , search_customer ) that accept human-readable identifiers (names, titles) and encapsulate all joins and business rules in pre-authored SQL. |
| C | Generic thin-tool pack | MCP Blueprint loading a deliberately shallow pack ( search_customer , search_films , get_customer_rentals , get_film ): table-oriented tools with minimal descriptions — a first-pass surface a developer might ship before verticalizing. C isolates the contribution of tool design from tool existence . |
| Model | Params | Tier |
|---|---|---|
| llama3.2:3b | 3B | SLM |
| qwen2.5:3b | 3B | SLM |
| qwen2.5:7b | 7B | Medium |
| llama3.1:8b | 8B | Medium |
| Category | Tasks |
|---|---|
| Customer lookup | find_customer , not_found |
| Rental state & standing | rental_history , return_verify , service_case , overdue_report , good_standing_recommend |
| Recommendation | recommend_category , recommend_rating , g_available , avoid_on_loan , upsell_seen , not_rented |
| Catalog details | film_details , store_availability |
| Multi-step workflow | customer_workflow |
| Edge cases | rental_empty |
| Metric | A (Raw SQL) | B (Verticalized) | C (Generic) |
|---|---|---|---|
| Mean score | 0.666 | 0.939 | 0.605 |
| Fully-correct cells | 67/201 (33%) | 174/204 (85%) | 63/204 (31%) |
| Zero-score cells | 7 (3%) | 3 (1%) | 19 (9%) |
| Model | A | B | C |
|---|---|---|---|
| llama3.2:3b | 0.583 (6/51) | 0.929 (42/51) | 0.419 (0/51) |
| qwen2.5:3b | 0.684 (17/48) | 0.902 (42/51) | 0.602 (14/51) |
| qwen2.5:7b | 0.647 (20/51) | 0.958 (45/51) | 0.631 (19/51) |
| llama3.1:8b | 0.750 (24/51) | 0.966 (45/51) | 0.769 (30/51) |
| Approach | Mean tokens/cell | vs B | Tokens per correct answer | Seconds per correct answer |
|---|---|---|---|---|
| B (Verticalized) | 3,056 | — | 3,582 | 5.2 |
| C (Generic) | 2,894 | –5.3% | 9,372 | 20.7 |
| A (Raw SQL) | 3,953 | +29.4% | 11,858 | 51.9 |
| Model | A: tokens/correct | B: tokens/correct | A: s/correct | B: s/correct | Reduction |
|---|---|---|---|---|---|
| llama3.2:3b | 31,476 | 2,723 | 49.5 s | 3.4 s | 11.6 |
| qwen2.5:3b | 17,467 | 4,766 | 125.1 s | 5.0 s | 3.7 |
| qwen2.5:7b | 8,464 | 4,331 | 33.2 s | 5.6 s | 2.0 |
| llama3.1:8b | 5,808 | 2,531 | 16.3 s | 6.7 s | 2.3 |
| Dimension | B (Verticalized) | C (Generic) |
|---|---|---|
| Tool semantics | Domain operations ( customer_account_summary , recommend_films ) | Table-oriented ( search_films , get_customer_rentals ) |
| Parameter contracts | Human-readable names; descriptions tuned for matching | Bare IDs or minimal labels |
| Business logic | Encapsulated server-side (standing flag, overdue detection) | Re-derived by the model |
| Descriptions | Rich guidance steering correct workflows | Minimal, forcing multi-step composition |
| Task | A | B | C | (B–A) |
|---|---|---|---|---|
| recommend_category | 0.500 | 1.000 | 0.833 | +50.0pp |
| avoid_on_loan | 0.500 | 1.000 | 0.667 | +50.0pp |
| upsell_seen | 0.500 | 1.000 | 0.750 | +50.0pp |
| film_details | 0.562 | 1.000 | 0.375 | +43.8pp |
| customer_workflow | 0.584 | 1.000 | 0.688 | +41.6pp |
| rental_history | 0.361 | 0.694 | 0.417 | +33.4pp |
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
| # | Task id | Prompt |
|---|---|---|
| 1 | find_customer | Find the customer whose last name is Smith. Report the customer’s full name and customer ID. |
| 2 | rental_history | Mary Smith wants to know what she has rented. What films has she rented, and does she currently have any rentals outstanding? |
| 3 | good_standing_recommend | Check whether customer Maria Miller has any overdue rentals. If she is in good standing, recommend two Sci-Fi movies. |
| 4 | overdue_report | Check whether customer Tammy Sanders has any overdue rentals. If she does, list the films she still has to return. |
| 5 | recommend_category | Recommend three popular Family movies for a family movie night. |
| 6 | recommend_rating | Recommend two movies rated G, suitable for all ages. |
LLM Tool Use
Large language model tool use studies how models select, call, and coordinate external tools to extend their reasoning and take actions.
See all 293 papers