Skip to main content
Glama
handleGetTable.tsâ€ĸ3.54 kB
import { McpError, ErrorCode, getManagedConnection } from '../lib/utils'; import { CrudClient } from '@mcp-abap-adt/adt-clients'; import { XMLParser } from 'fast-xml-parser'; import { writeResultToFile } from '../lib/writeResultToFile'; import * as z from 'zod'; export const TOOL_DEFINITION = { name: "GetTable", description: "Retrieve ABAP table structure.", inputSchema: { table_name: z.string().describe("Name of the ABAP table") } } as const; function parseTableXml(xml: string) { const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '', parseAttributeValue: true, trimValues: true }); const result = parser.parse(xml); // DDIC Table (TABL/DT) if (result['ddic:table']) { const t = result['ddic:table']; const fields = Array.isArray(t['ddic:fields']?.['ddic:field']) ? t['ddic:fields']['ddic:field'] : t['ddic:fields']?.['ddic:field'] ? [t['ddic:fields']['ddic:field']] : []; return { name: t['adtcore:name'], objectType: 'table', description: t['adtcore:description'], package: t['adtcore:packageRef']?.['adtcore:name'] || null, fields: fields.map(f => ({ name: f['ddic:name'], dataType: f['ddic:dataType'], length: parseInt(f['ddic:length'], 10), decimals: parseInt(f['ddic:decimals'] || '0', 10), key: f['ddic:keyFlag'] === 'true', description: f['ddic:description'] })) }; } // fallback: return raw return { raw: result }; } export async function handleGetTable(args: any) { try { if (!args?.table_name) { throw new McpError(ErrorCode.InvalidParams, 'Table name is required'); } const connection = getManagedConnection(); const client = new CrudClient(connection); await client.readTable(args.table_name); const response = client.getReadResult(); if (!response) { throw new McpError(ErrorCode.InternalError, 'Failed to read table'); } // Parse XML responses; fall back to returning the payload as-is if (typeof response.data === 'string' && response.data.trim().startsWith('<?xml')) { const resultObj = parseTableXml(response.data); const result = { isError: false, content: [ { type: "text", text: JSON.stringify(resultObj, null, 2) } ] }; if (args.filePath) { writeResultToFile(JSON.stringify(result, null, 2), args.filePath); } return result; } else { const plainResult = { isError: false, content: [ { type: "text", text: response.data } ] }; if (args.filePath) { writeResultToFile(response.data, args.filePath); } return plainResult; } } catch (error) { return { isError: true, content: [ { type: "text", text: error instanceof Error ? error.message : String(error) } ] }; } }

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/fr0ster/mcp-abap-adt'

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