execute_program
Execute an ABAP program on the SAP system and retrieve its WRITE output as plain text. Requires the program to be activated before running.
Instructions
Execute an ABAP program/report on the SAP system and return the list output. The program must be activated. Returns the WRITE output as plain text.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Program name to execute (e.g. ZHANZ_MCP_HELLO) | |
| system_id | No | SAP system ID (e.g. DEV). Omit to use default system. |
Implementation Reference
- src/adt-client.ts:633-648 (handler)The executeProgram method on AdtClient that actually executes an ABAP program on the SAP system via POST to /sap/bc/adt/programs/programrun/{name}. It uses a stateful session (fetches CSRF token, posts, then ends session).
async executeProgram(name: string): Promise<string> { await this.fetchStatefulCsrf(); try { const resp = await this.http.post( `/sap/bc/adt/programs/programrun/${encodeURIComponent(name.toLowerCase())}`, "", { headers: this.statefulHeaders({ Accept: "text/plain" }), responseType: "text", } ); return resp.data as string; } finally { await this.endStatefulSession(); } } - src/mcp-server.ts:1285-1289 (handler)The CallToolRequestSchema handler case for 'execute_program' — parses the name argument via NameSchema and delegates to client.executeProgram(progName), returning the output or '(no output)'.
case "execute_program": { const { name: progName } = NameSchema.parse(args); const output = await client.executeProgram(progName); return { content: [{ type: "text", text: output || "(no output)" }] }; } - src/mcp-server.ts:13-28 (schema)NameSchema used by execute_program: a Zod object requiring a 'name' string.
const NameSchema = z.object({ name: z.string() }); const FunctionModuleSchema = z.object({ function_group: z.string(), function_name: z.string(), }); const SqlSchema = z.object({ query: z.string() }); const SearchObjectSchema = z.object({ query: z.string(), max_results: z.number().optional(), }); const CreateProgramSchema = z.object({ name: z.string(), description: z.string(), source: z.string(), package: z.string().optional(), }); - src/mcp-server.ts:249-257 (registration)Tool registration/definition of 'execute_program' in ListToolsRequestSchema — defines name, description, and inputSchema with only a 'name' parameter.
{ name: "execute_program", description: "Execute an ABAP program/report on the SAP system and return the list output. The program must be activated. Returns the WRITE output as plain text.", inputSchema: { type: "object" as const, properties: { name: { type: "string", description: "Program name to execute (e.g. ZHANZ_MCP_HELLO)" }, ...SYSTEM_ID_PROP }, required: ["name"], }, }, - src/adt-client.ts:633-648 (helper)Helper methods used by executeProgram: fetchStatefulCsrf() obtains CSRF token in stateful session mode; endStatefulSession() ends the session. These are also used by the executeProgram method.
async executeProgram(name: string): Promise<string> { await this.fetchStatefulCsrf(); try { const resp = await this.http.post( `/sap/bc/adt/programs/programrun/${encodeURIComponent(name.toLowerCase())}`, "", { headers: this.statefulHeaders({ Accept: "text/plain" }), responseType: "text", } ); return resp.data as string; } finally { await this.endStatefulSession(); } }