Skip to main content
Glama
ethanhan2014

SAP ADT MCP Server

by ethanhan2014

change_cds_view

Modify an existing CDS view in SAP systems. Locks the object, replaces the DDL source, activates, and releases the lock. Requires the view name and full new source code.

Instructions

Modify an existing CDS view (DDL source) in the SAP system. Locks the object, writes the new source, activates, and unlocks. Use get_cds_view first to read the current source.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesCDS view name (e.g. ZHANZ_MY_VIEW)
sourceYesComplete new CDS DDL source code including all annotations and define view statement
system_idNoSAP system ID (e.g. DEV). Omit to use default system.

Implementation Reference

  • The `changeCdsView` method in `AdtClient` class implements the core logic to modify an existing CDS view. It: 1) Fetches a stateful CSRF token, 2) Locks the DDL source object, 3) Writes the new source code, 4) Unlocks the object, 5) Activates the CDS view via activation API.
      async changeCdsView(name: string, source: string): Promise<string> {
        await this.fetchStatefulCsrf();
        const log: string[] = [];
        const nameLower = name.toLowerCase();
        const nameUpper = name.toUpperCase();
    
        try {
          // 1. Lock
          const lockResp = await this.http.post(
            `/sap/bc/adt/ddic/ddl/sources/${nameLower}?_action=LOCK&accessMode=MODIFY`,
            "",
            { headers: this.statefulHeaders({ Accept: "application/vnd.sap.as+xml" }), responseType: "text", validateStatus: () => true }
          );
          const lockData = lockResp.data as string;
          const lockMatch = lockData.match(/<LOCK_HANDLE>([^<]+)<\/LOCK_HANDLE>/);
    
          if (!lockMatch?.[1]) {
            log.push(`Failed to lock DDL source ${nameUpper} (HTTP ${lockResp.status})`);
            log.push(lockData.substring(0, 500));
            return log.join("\n");
          }
    
          const lockHandle = lockMatch[1];
          log.push(`Locked ${nameUpper} for editing`);
    
          // 2. Write source
          await this.http.put(
            `/sap/bc/adt/ddic/ddl/sources/${nameLower}/source/main?lockHandle=${encodeURIComponent(lockHandle)}`,
            source,
            {
              headers: this.statefulHeaders({ "Content-Type": "text/plain; charset=utf-8" }),
              responseType: "text",
            }
          );
          log.push("Source code written");
    
          // 3. Unlock (must unlock before activation)
          await this.http.post(
            `/sap/bc/adt/ddic/ddl/sources/${nameLower}?_action=UNLOCK&lockHandle=${encodeURIComponent(lockHandle)}`,
            "",
            { headers: this.statefulHeaders({ Accept: "application/vnd.sap.as+xml" }), responseType: "text" }
          );
          log.push("Unlocked");
    
          // 4. Activate
          const activateBody = `<?xml version="1.0" encoding="UTF-8"?>
    <adtcore:objectReferences xmlns:adtcore="http://www.sap.com/adt/core">
      <adtcore:objectReference adtcore:uri="/sap/bc/adt/ddic/ddl/sources/${nameLower}" adtcore:name="${nameUpper}"/>
    </adtcore:objectReferences>`;
    
          const actResp = await this.http.post(
            "/sap/bc/adt/activation?method=activate&preauditRequested=true",
            activateBody,
            {
              headers: this.statefulHeaders({
                "Content-Type": "application/xml",
                Accept: "application/xml",
              }),
              responseType: "text",
              validateStatus: () => true,
            }
          );
    
          const actData = actResp.data as string;
          if (actData.includes('activationExecuted="true"')) {
            log.push("Activated successfully");
          } else {
            const msgMatch = actData.match(/<msg:shortText>([\s\S]*?)<\/msg:shortText>/);
            log.push(`Activation: ${msgMatch?.[1] ?? `HTTP ${actResp.status}`}`);
          }
        } finally {
          await this.endStatefulSession();
        }
    
        return log.join("\n");
      }
  • The `change_cds_view` tool handler in the MCP server's CallToolRequestSchema handler. Parses input via ChangeCdsViewSchema, calls `client.changeCdsView()`, and returns the log.
    case "change_cds_view": {
      const { name: cdsName, source } = ChangeCdsViewSchema.parse(args);
      const log = await client.changeCdsView(cdsName, source);
      return { content: [{ type: "text", text: log }] };
    }
  • Zod schema `ChangeCdsViewSchema` defining input validation for the change_cds_view tool: requires `name` (string) and `source` (string).
    const ChangeCdsViewSchema = z.object({
      name: z.string(),
      source: z.string(),
    });
  • Tool registration in the ListToolsRequestSchema handler: defines 'change_cds_view' with name, description, and input schema listing properties (name, source, system_id).
    {
      name: "change_cds_view",
      description: "Modify an existing CDS view (DDL source) in the SAP system. Locks the object, writes the new source, activates, and unlocks. Use get_cds_view first to read the current source.",
      inputSchema: {
        type: "object" as const,
        properties: {
          name: { type: "string", description: "CDS view name (e.g. ZHANZ_MY_VIEW)" },
          source: { type: "string", description: "Complete new CDS DDL source code including all annotations and define view statement" },
          ...SYSTEM_ID_PROP,
        },
        required: ["name", "source"],
      },
    },
Behavior3/5

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

With no annotations, description carries full burden. It discloses locking, writing, activating, and unlocking, which are key behaviors. However, missing details on error handling, permissions, or impact on dependent objects, making it only adequate.

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?

Two concise sentences front-load the action and steps, then provide usage guidance. No wasted words.

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

Completeness3/5

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

For a modification tool with no output schema, description covers the core process but lacks details on failure scenarios (e.g., activation errors), locking conflicts, or post-modification validation. Adequate for basic use but incomplete for robust agent understanding.

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

Parameters3/5

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

Input schema has 100% description coverage, so baseline is 3. Description adds no new meaning beyond repeating the schema's description for 'source' parameter. No extra context for 'name' or 'system_id'.

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 modifies an existing CDS view (DDL source) and lists the steps: lock, write, activate, unlock. This specific verb+resource distinguishes it from sibling tools like get_cds_view (read) and create_cds_view (create).

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?

Explicitly advises to use get_cds_view first to read current source, providing clear context for when to use this tool. Lacks explicit 'when not to use' but the single guideline is effective.

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