Skip to main content
Glama
MarioDeFelipe

SAP Datasphere MCP Server

smart_query

Automatically routes SQL queries to the best execution method for reliable results. Handles aggregations, filtering, and complex queries with automatic fallback to alternative methods.

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

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

No annotations provided, so description carries full burden. Details internal routing logic, fallback behavior, performance characteristics, error handling, and response structure. Describes how it analyzes queries and chooses methods.

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

Conciseness4/5

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

Well-structured with headers, lists, and examples. Front-loaded with main purpose. Slightly verbose with some redundant explanations, but still efficient for a composite tool of this complexity.

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 (composite, routing, fallback) and lack of output schema, description is exhaustive. Covers usage, behavior, parameters, examples, performance, error handling, and sibling differentiation. Provides everything an agent needs.

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

Parameters5/5

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

Schema covers all parameters (100%), but description adds substantial value: explains mode options with examples, provides query patterns, shows parameter usage in examples, and clarifies default values and ranges.

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?

Clearly states it is an intelligent query router that combines multiple methods. Differentiates itself from siblings by being a composite tool with automatic routing and fallback. Uses specific verbs and resources.

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?

Explicitly provides when to use smart_query vs individual tools, including conditions and alternatives. Contains sections 'Use this tool when' and 'When to use individual tools instead'.

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/MarioDeFelipe/sap-datasphere-mcp'

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