Building and Operating an MCP Server for LLM-Powered Cloud Infrastructure Queries
cloudquery · Tech · 2025 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.4 (schema v2)
Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.
Problem
Domain: MCP cloud-infrastructure querying
CloudQuery wanted Claude and Cursor to query a cloud infrastructure database through an MCP server, but production use exposed brittle tool selection, context-window overload, and nondeterministic SQL/tool behavior.
Constraints:
- LLMs choose tools based heavily on name and description semantics.
- Cloud infrastructure schemas can exceed context windows.
- Even temperature-zero calls can choose different tools or SQL.
- The server had to expose complex database discovery safely through tool workflows.
Architecture
CloudQuery built a Go MCP server exposing cloud-infrastructure database tools to Claude and Cursor. They expanded terse tool descriptions from about 50 to about 400 characters, renamed ambiguous tools, embedded multi-tool workflow instructions, filtered schema output with Go regexes and ranking heuristics, and reduced schema tokens so the model could follow a discovery-to-execution path.
Diagram confidence: explicit (topology described by the source).
flowchart LR claude-or-cursor[Claude Or Cursor] --> mcp-server[MCP Server] mcp-server --> tool-descriptions[Tool Descriptions] tool-descriptions --> workflow-instructions[Workflow Instructions] workflow-instructions --> claude-or-cursor[Claude Or Cursor] mcp-server --> schema-filter[Schema Filter] schema-filter --> cloud-infrastructure-database[Cloud Infrastructure Database] mcp-server --> cloud-infrastructure-database[Cloud Infrastructure Database]
Components
| Component | Role | Interacts with |
|---|---|---|
Claude Or Cursor |
LLM client that calls MCP tools to answer infrastructure questions. | MCP Server |
MCP Server |
Go server registering tools and handlers for infrastructure database access. | Tool Descriptions, Workflow Instructions, Schema Filter, Cloud Infrastructure Database |
Tool Descriptions |
Long domain-specific descriptions used by LLMs to choose the right tool. | Claude Or Cursor, MCP Server |
Workflow Instructions |
Embedded ordered steps for discovery-to-execution tool use. | Tool Descriptions, Claude Or Cursor |
Schema Filter |
Trims schema output before sending it to the LLM. | MCP Server, Cloud Infrastructure Database |
Cloud Infrastructure Database |
Cloud asset inventory tables queried by the LLM through MCP tools. | MCP Server, Schema Filter |
Data flow
Claude or Cursor reads MCP tool schemas, starts with plugin discovery, searches for relevant tables, retrieves detailed schemas and columns, filters large schema output before context insertion, then executes SQL against CloudQuery infrastructure data.
Why this architecture
CloudQuery found that software-engineer-style concise tool docs were invisible or ambiguous to LLMs. The MCP server needed verbose semantic descriptions, explicit workflows, and schema filtering so the LLM could discover data structures rather than hallucinate tables or drown in raw schemas.
Models used: Claude · Cursor · GPT
Scale
- Tool description length increased from about 50 to about 400 characters.“The character count increased from ~50 to ~400, and response quality improved dramatically. Instead of guessing, Claude systematically queried the tool to understand the data structure before proceeding.”article, stated
- A raw CloudQuery schema dump can exceed 50,000 tokens.“We learned this the hard way: a single raw CloudQuery schema dump can easily exceed 50,000 tokens. Some of our more complex tables contain hundreds of columns and foreign keys.”article, stated
- Schema filtering reduced token usage by about 90%.“We observed on average about a 90% reduction in token usage after filtering, which allowed Claude to handle over 20 table schemas at once rather than choking after 3 to 4.”article, stated
- Filtering let Claude handle over 20 table schemas instead of choking after 3 to 4.“We observed on average about a 90% reduction in token usage after filtering, which allowed Claude to handle over 20 table schemas at once rather than choking after 3 to 4.”article, stated
Alternatives considered (roads not taken)
Concise engineer-style tool descriptions.
Rejected because: Claude ignored or misinterpreted terse descriptions and hallucinated alternatives.
Let the LLM infer tool order from individual descriptions.
Rejected because: Claude skipped steps, called tools out of order, or assumed data structure.
Send raw schemas to the model.
Rejected because: Large schemas consumed context and caused selective forgetting.
Patterns
tool-use-orchestration (MCP)
The MCP server exposes Go functions with names, descriptions, parameters, and handlers for LLM calls.
prompt-versioning (tool descriptions)
Tool descriptions are treated as prompt-like artifacts whose wording determines behavior.
context-compaction (schema management)
Schema filtering trims irrelevant columns so tool output fits in context.
query-rewriting (tool workflow)
Recommended workflows rewrite broad user questions into a sequence of plugin, table, schema, column, and query steps.
Tradeoffs
Tool documentation length
Chose Verbose semantic descriptions over Short context-saving descriptions.
Rationale: Longer descriptions improved tool selection even though they used more context.
Schema exposure
Chose Filtered schema output over Full raw schema dumps.
Rationale: Filtering preserved enough context for query planning and more tables.
Workflow guidance
Chose Embedded multi-tool workflows over Assuming the model will infer tool order.
Rationale: Explicit steps stopped random calls and hallucinated table structures.
Gotchas (what bit them)
Concise tool descriptions are often invisible to LLMs.
Root cause: LLMs rank tool choice semantically from names and descriptions, not from engineer intuition.
Resolution: Write long, domain-specific tool descriptions that explain when and why to call each tool.
MCP tool chains need explicit sequencing.
Root cause: The LLM skipped discovery steps or hallucinated schema knowledge when asked broad questions.
Resolution: Embed the recommended workflow directly in the tool description.
Raw schemas can saturate context windows.
Root cause: Cloud tables can have hundreds of columns and foreign keys.
Resolution: Filter and rank columns before handing schemas to the LLM.
Temperature zero does not guarantee deterministic tool behavior.
Root cause: Claude still chose different tools or SQL for the same input.
Resolution: Design for nondeterminism with stronger workflows and validation.
temperature=0, which is supposed to make the model always pick the most likely next word at every step”article, statedEvaluation
CloudQuery evaluated behavior by observing tool invocation, hallucinated queries, workflow ordering, schema token reduction, number of schemas handled, and repeated nondeterministic outputs.
Metrics: Tool invocation rate · Description length · Token reduction · Number of schemas handled · Hallucinated table/query frequency
Outcomes
- Longer tool descriptions improved Claude's discovery behavior.
- Workflow instructions turned random tool use into a discovery-to-execution pipeline.
- Schema filtering reduced token use by about 90% and let Claude handle over 20 schemas at once.
The source reports ~50 to ~400 character description expansion, raw schema dumps above 50,000 tokens, ~90% token reduction, and support for 20+ schemas rather than 3 to 4.