Skip to main content
Glama
ethanhan2014

SAP ADT MCP Server

by ethanhan2014

execute_sql

Execute ABAP SQL queries on SAP systems. Use standard syntax like SELECT ... UP TO n ROWS to retrieve table results directly.

Instructions

Execute an ABAP SQL query on the SAP system and return results as a table. Use standard ABAP SQL syntax (e.g. SELECT vbeln, erdat FROM vbak UP TO 10 ROWS).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesABAP SQL query
system_idNoSAP system ID (e.g. DEV). Omit to use default system.

Implementation Reference

  • Tool registration in the ListToolsRequestSchema handler, defining the 'execute_sql' tool with a single required 'query' string parameter and an optional 'system_id'.
    {
      name: "execute_sql",
      description: "Execute an ABAP SQL query on the SAP system and return results as a table. Use standard ABAP SQL syntax (e.g. SELECT vbeln, erdat FROM vbak UP TO 10 ROWS).",
      inputSchema: {
        type: "object" as const,
        properties: { query: { type: "string", description: "ABAP SQL query" }, ...SYSTEM_ID_PROP },
        required: ["query"],
      },
    },
  • The CallToolRequestSchema handler for 'execute_sql'. Parses args via SqlSchema, calls client.executeFreestyleSql(), then parses the XML result into a formatted table using parseSqlResultXml().
    case "execute_sql": {
      const { query } = SqlSchema.parse(args);
      const xml = await client.executeFreestyleSql(query);
      const table = parseSqlResultXml(xml);
      return { content: [{ type: "text", text: table }] };
    }
  • Zod schema (SqlSchema) defining the input validation for the execute_sql tool. Expects a single 'query' string.
    const SqlSchema = z.object({ query: z.string() });
  • AdtClient.executeFreestyleSql() - sends the SQL query to the SAP ADT endpoint /sap/bc/adt/datapreview/freestyle via POST with CSRF token handling.
    async executeFreestyleSql(query: string): Promise<string> {
      const response = await this.postWithCsrf(
        "/sap/bc/adt/datapreview/freestyle",
        query,
        "application/vnd.sap.adt.datapreview.table.v1+xml"
      );
      return response.data as string;
    }
  • Helper function that parses the ADT data preview XML response into a formatted text table with column headers, separators, and rows.
    export function parseSqlResultXml(xml: string): string {
      const columns = extractColumns(xml);
      if (columns.length === 0) return "No results returned.";
    
      const totalRows = extractTotalRows(xml);
      const queryTime = extractQueryTime(xml);
      const rowCount = columns[0].values.length;
    
      const maxWidth = 40;
      const colWidths = columns.map((col) => {
        const maxVal = col.values.reduce(
          (max, v) => Math.max(max, v.length),
          col.name.length
        );
        return Math.min(maxVal, maxWidth);
      });
    
      const padRight = (s: string, w: number) =>
        s.length > w ? s.substring(0, w - 1) + "~" : s.padEnd(w);
    
      const header = columns
        .map((col, i) => padRight(col.name, colWidths[i]))
        .join(" | ");
      const separator = colWidths.map((w) => "-".repeat(w)).join("-+-");
    
      const rows: string[] = [];
      for (let r = 0; r < rowCount; r++) {
        const row = columns
          .map((col, i) => padRight(col.values[r] ?? "", colWidths[i]))
          .join(" | ");
        rows.push(row);
      }
    
      const lines = [
        `${rowCount} row(s) returned (${totalRows} total, ${queryTime}s)`,
        "",
        header,
        separator,
        ...rows,
      ];
    
      return lines.join("\n");
    }
Behavior2/5

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

No annotations are provided, so the description bears full responsibility for behavioral disclosure. The description does not specify whether the tool is read-only (only SELECT queries) or allows modifications (INSERT, UPDATE, DELETE). It lacks warnings about destructive potential, security implications, or execution restrictions, which is critical for an SQL execution tool.

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

Conciseness5/5

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

The description is two sentences long, front-loaded with the tool's purpose, and includes a practical example. Every word is functional; no redundancy or filler.

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

Completeness4/5

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

For a simple 2-parameter tool with no output schema, the description sufficiently explains the input and return format ('results as a table'). It could be improved by mentioning error handling, performance limits, or the scope of allowed SQL statements, but it is not critically incomplete.

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?

The input schema covers both parameters with descriptions, but the description adds meaningful context: for 'query', it provides an example and clarifies standard ABAP SQL syntax; for 'system_id', it explains default behavior ('Omit to use default system'). This adds value beyond the schema.

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 clearly states the tool's purpose: 'Execute an ABAP SQL query on the SAP system and return results as a table.' It includes an example of standard ABAP SQL syntax, making it specific and distinguishable from sibling tools like get_table or create_abap_class.

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

Usage Guidelines4/5

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

The description provides a clear example of when to use the tool ('SELECT vbeln, erdat FROM vbak UP TO 10 ROWS') and implies standard SQL syntax usage. However, it does not explicitly state when not to use it or mention alternatives among siblings, which would improve guidance.

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/ethanhan2014/sap-adt-mcp'

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