Skip to main content
Glama
DimiDR

SAP Datasphere MCP Server

by DimiDR

smart_query

Intelligently routes SQL queries to the most suitable execution endpoint (relational, analytical, or SQL) with automatic fallback and diagnostic logs.

Instructions

🚀 SMART QUERY - Intelligent query router that automatically selects the best execution method for your query.

NEW in v1.0.5 - This is a composite tool combining execute_query, query_relational_entity, and query_analytical_data with intelligent routing and fallback logic.

Why use smart_query instead of individual query tools?

  • ✅ Automatic routing to the most reliable method

  • ✅ Fallback handling if primary method fails

  • ✅ No need to understand different query methods

  • ✅ Better error recovery and diagnostics

  • ✅ Performance optimization based on query type

How it works:

  1. Analyzes your query - Detects SQL syntax, aggregations, complexity

  2. Routes intelligently - Chooses the best execution method:

    • Aggregations (SUM, COUNT, GROUP BY) → Analytical endpoint

    • Simple SELECT → Relational endpoint (most reliable)

    • Complex SQL → SQL parsing with OData conversion

  3. Falls back gracefully - If primary method fails, tries alternatives

  4. Returns detailed logs - Shows routing decisions and execution path

Query Modes:

  • auto (default) - Intelligent routing based on query analysis

  • relational - Force use of relational endpoint (most reliable)

  • analytical - Force use of analytical endpoint (for aggregations)

  • sql - Force use of SQL parsing method

Use this tool when:

  • You want reliable query execution without worrying about method selection

  • You're unsure which query method to use

  • You need fallback handling for production reliability

  • You want to see execution diagnostics

Supported query patterns:

  • Simple SELECT: SELECT * FROM SAP_SC_FI_V_ProductsDim LIMIT 10

  • Filtering: SELECT * FROM table WHERE PRICE > 1000

  • Column selection: SELECT PRODUCTID, PRICE FROM table

  • Aggregations: SELECT COMPANYNAME, SUM(GROSSAMOUNT) FROM table GROUP BY COMPANYNAME

  • Sorting: SELECT * FROM table ORDER BY PRICE DESC LIMIT 5

Parameters:

  • space_id - Space ID (e.g., "SAP_CONTENT")

  • query - SQL query or natural language request

  • mode - Routing mode: "auto", "relational", "analytical", "sql" (default: "auto")

  • limit - Max rows to return (default: 1000)

  • include_metadata - Include routing logs and decisions (default: true)

  • fallback - Enable fallback to alternative methods (default: true)

Example queries:

# Auto-routing - simple SELECT
smart_query(space_id="SAP_CONTENT", query="SELECT * FROM SAP_SC_FI_V_ProductsDim LIMIT 5")

# Auto-routing - aggregation
smart_query(space_id="SAP_CONTENT", query="SELECT COMPANYNAME, SUM(GROSSAMOUNT) FROM SAP_SC_SALES_V_SalesOrders GROUP BY COMPANYNAME")

# Force relational mode
smart_query(space_id="SAP_CONTENT", query="SELECT * FROM SAP_SC_FI_V_ProductsDim", mode="relational")

# Disable fallback (fail fast)
smart_query(space_id="SAP_CONTENT", query="SELECT * FROM table", fallback=False)

Response includes:

  • Query results (data)

  • Method used (relational, analytical, sql, or fallback)

  • Execution time

  • Rows returned

  • Routing decision log (if include_metadata=true)

  • Detected query characteristics

Error handling:

  • If primary method fails, automatically tries fallbacks

  • Returns detailed error log showing all attempted methods

  • Provides suggestions for fixing query issues

  • Shows routing decisions for debugging

Performance:

  • Relational: 1-5 seconds, up to 50K records

  • Analytical: Fast for aggregations

  • SQL: 1-5 seconds, up to 1K records

When to use individual tools instead:

  • Use query_relational_entity when you need specific entity_name control

  • Use query_analytical_data when you know you need analytical consumption

  • Use execute_query when you need exact SQL syntax control

  • Use smart_query for everything else (recommended for most use cases)

Note: This tool provides the same functionality as the individual query tools but with better reliability through intelligent routing and fallback handling.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modeNoQuery execution mode. Use 'auto' for intelligent routing (recommended). Default: 'auto'auto
limitNoMaximum number of rows to return. Default: 1000. Range: 1-50000
queryYesSQL query to execute. Examples: 'SELECT * FROM table LIMIT 10', 'SELECT col1, SUM(col2) FROM table GROUP BY col1'
fallbackNoEnable fallback to alternative query methods if primary fails. Default: true
space_idYesThe Datasphere space ID (e.g., 'SAP_CONTENT', 'SALES'). Must match existing space.
include_metadataNoInclude execution logs and routing decisions in response. Useful for debugging. Default: true
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden and meets it exceptionally. It discloses automatic routing, fallback behavior, response contents (method used, execution time, routing logs), error handling, and performance characteristics. This goes beyond a simple 'executes queries' statement and provides rich behavioral context for an AI agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections, emojis, and bullet points, but it is overly verbose and includes redundant content. For instance, the advantages of smart_query are repeated in both the 'Why use' list and the later 'When to use individual tools' section, and the final note restates the same message. While front-loaded, it would benefit from trimming to make every sentence earn its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity, the absence of annotations, and the lack of an output schema, the description is remarkably complete. It covers query modes, supported query patterns, response fields, error handling, performance expectations, and when to use alternatives. An agent would have sufficient context to select and invoke the tool correctly and to interpret its output.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Although schema coverage is 100%, the description adds meaningful context beyond the schema: it explains each parameter in a dedicated 'Parameters' section with added semantics like mode examples, default behavior of fallback, and the purpose of include_metadata. This enriches the bare schema definitions and provides practical usage guidance. A score of 4 reflects this added value while acknowledging the schema already covers the basics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description begins with a specific verb+resource: 'Intelligent query router that automatically selects the best execution method for your query.' It clearly identifies what the tool does and differentiates itself from sibling query tools by positioning as a composite router with fallback logic. The scope is explicit and not a tautology or vague.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit 'Use this tool when' and 'When to use individual tools instead' sections, naming exact alternatives like query_relational_entity, query_analytical_data, and execute_query. This gives clear guidance on when to choose smart_query versus alternatives, satisfying all rubric criteria for usage guidelines.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DimiDR/SAP-Datasphere-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server