Skip to main content
Glama
ethanhan2014

SAP ADT MCP Server

by ethanhan2014

change_abap_program

Modify an existing ABAP program in SAP systems by locking, writing new source code, activating, and unlocking the object. Use after retrieving current source to apply changes safely.

Instructions

Modify an existing ABAP program/report in the SAP system. Locks the object, writes the new source, activates, and unlocks. Use get_abap_program first to read the current source.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesProgram name (e.g. ZHANZ_TEST)
sourceYesComplete new ABAP source code. Must start with REPORT statement.
system_idNoSAP system ID (e.g. DEV). Omit to use default system.

Implementation Reference

  • Tool 'change_abap_program' is registered in the ListToolsRequestSchema handler with its name, description, and input schema. It requires 'name' (program name) and 'source' (complete new ABAP source code).
      name: "change_abap_program",
      description: "Modify an existing ABAP program/report in the SAP system. Locks the object, writes the new source, activates, and unlocks. Use get_abap_program first to read the current source.",
      inputSchema: {
        type: "object" as const,
        properties: {
          name: { type: "string", description: "Program name (e.g. ZHANZ_TEST)" },
          source: { type: "string", description: "Complete new ABAP source code. Must start with REPORT statement." },
          ...SYSTEM_ID_PROP,
        },
        required: ["name", "source"],
      },
    },
  • The CallToolRequestSchema switch case for 'change_abap_program' parses args with ChangeAbapProgramSchema, then calls client.changeAbapProgram(progName, source) and returns the result as text content.
    case "change_abap_program": {
      const { name: progName, source } = ChangeAbapProgramSchema.parse(args);
      const log = await client.changeAbapProgram(progName, source);
      return { content: [{ type: "text", text: log }] };
    }
  • ChangeAbapProgramSchema defines validation: name (string) and source (string) are required.
    const ChangeAbapProgramSchema = z.object({
      name: z.string(),
      source: z.string(),
    });
  • The AdtClient.changeAbapProgram method implements the actual SAP ADT REST API logic: fetches CSRF token, locks the program, writes the new source (with optional auto-detected transport), unlocks, and activates the program. Returns a log of all steps.
      async changeAbapProgram(name: string, source: string, transport?: 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/programs/programs/${nameLower}?_action=LOCK&accessMode=MODIFY`,
            "",
            { headers: this.statefulHeaders(), 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 program ${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 (auto-detect transport if not provided)
          let corrNr = transport ?? "";
          let writeResp = await this.http.put(
            `/sap/bc/adt/programs/programs/${nameLower}/source/main?lockHandle=${encodeURIComponent(lockHandle)}&corrNr=${corrNr}`,
            source,
            {
              headers: this.statefulHeaders({ "Content-Type": "text/plain; charset=utf-8" }),
              responseType: "text",
              validateStatus: () => true,
            }
          );
          if (writeResp.status >= 400 && !transport) {
            const trMatch = (writeResp.data as string).match(/request\s+([A-Z]{3}K\d{6})/);
            if (trMatch) {
              corrNr = trMatch[1];
              log.push(`Auto-detected transport ${corrNr}`);
              writeResp = await this.http.put(
                `/sap/bc/adt/programs/programs/${nameLower}/source/main?lockHandle=${encodeURIComponent(lockHandle)}&corrNr=${corrNr}`,
                source,
                {
                  headers: this.statefulHeaders({ "Content-Type": "text/plain; charset=utf-8" }),
                  responseType: "text",
                  validateStatus: () => true,
                }
              );
            }
          }
          if (writeResp.status >= 400) {
            log.push(`Write failed (HTTP ${writeResp.status}): ${(writeResp.data as string).substring(0, 500)}`);
          } else {
            log.push("Source code written");
          }
    
          // 3. Unlock (must unlock before activation)
          await this.http.post(
            `/sap/bc/adt/programs/programs/${nameLower}?_action=UNLOCK&lockHandle=${encodeURIComponent(lockHandle)}`,
            "",
            { headers: this.statefulHeaders(), responseType: "text", validateStatus: () => true }
          );
          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/programs/programs/${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");
      }
Behavior4/5

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

Discloses locking, writing, activating, and unlocking—key behaviors for a modification tool. No annotations provided, so description carries full burden. Lacks mention of error handling or required authorizations.

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; first states purpose, second gives prerequisite guidance. No wasted words.

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?

Adequate for a complicated tool: mentions lifecycle steps. Lacks return value description (e.g., transport request, success indicator). However, no output schema exists, so burden is higher. Still, the core workflow is clear.

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?

Schema coverage is 100%, but description adds value: source must start with REPORT, system_id defaults to default system. These details help correct invocation beyond 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?

Clear verb 'Modify' and resource 'existing ABAP program/report'. Distinguishes from siblings like 'create_abap_program' and 'change_abap_class' by specifying the resource type.

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 advises to use 'get_abap_program first to read the current source', guiding the agent to a necessary prerequisite step. Implicitly distinguishes from creation tools.

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