Skip to main content
Glama
Raistlin82

SAP OData to MCP Server

by Raistlin82

get-entity-schema

Retrieve detailed schema information for SAP OData entities, including properties, types, keys, and constraints to understand data structure.

Instructions

Get detailed schema information for a specific entity including properties, types, keys, and constraints.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serviceIdYesThe SAP service ID
entityNameYesThe entity name

Implementation Reference

  • Zod input validation schema for the get-entity-schema tool defining serviceId, entityName, and optional flags
    export const EntitySchemaSchema = z.object({
      serviceId: serviceName,
      entityName: entitySetName,
      includeNavigations: z.boolean().optional(),
      includeConstraints: z.boolean().optional(),
    });
  • get-entity-schema registered as public discovery tool that does not require authentication (requiresAuth returns false)
      'get-entity-schema',
    
      // System tools
      'sap_service_discovery',
      'sap_metadata',
      'sap_health_check',
      'system_info',
    ];
  • Core helper function to fetch and parse service $metadata XML, used by get-entity-schema to retrieve full entity schema
    private async getServiceMetadata(service: ODataService): Promise<ServiceMetadata> {
      try {
        const destination = await this.sapClient.getDestination({
          type: 'design-time',
          operation: 'discovery',
        });
    
        const response = await executeHttpRequest(destination, {
          method: 'GET',
          url: service.metadataUrl,
          headers: {
            Accept: 'application/xml',
          },
        });
        return this.parseMetadata(response.data, service.odataVersion);
      } catch (error) {
        this.logger.error(`Failed to get metadata for service ${service.id}:`, error);
        throw error;
      }
    }
  • Extracts EntityType details including properties, keys, and capabilities from $metadata XML - core logic for entity schema retrieval
    private extractEntityTypes(
      xmlDoc: Document,
      entitySets: Array<{ [key: string]: string | null }>
    ): EntityType[] {
      const entityTypes: EntityType[] = [];
      const nodes = xmlDoc.querySelectorAll('EntityType');
    
      nodes.forEach((node: Element) => {
        const entitySet = entitySets.find(
          entitySet => entitySet.entitytype?.split('.')[1] === node.getAttribute('Name')
        );
        const entityType: EntityType = {
          name: node.getAttribute('Name') || '',
          namespace: node.parentElement?.getAttribute('Namespace') || '',
          entitySet: entitySet?.name,
          creatable: entitySet?.creatable?.toLowerCase() === 'true',
          updatable: entitySet?.updatable?.toLowerCase() === 'true',
          deletable: entitySet?.deletable?.toLowerCase() === 'true',
          addressable: entitySet?.addressable?.toLowerCase() === 'true',
          properties: [],
          navigationProperties: [],
          keys: [],
        };
    
        // Extract properties
        const propNodes = node.querySelectorAll('Property');
        propNodes.forEach((propNode: Element) => {
          entityType.properties.push({
            name: propNode.getAttribute('Name') || '',
            type: propNode.getAttribute('Type') || '',
            nullable: propNode.getAttribute('Nullable') !== 'false',
            maxLength: propNode.getAttribute('MaxLength') ?? undefined,
          });
        });
    
        // Extract keys
        const keyNodes = node.querySelectorAll('Key PropertyRef');
        keyNodes.forEach((keyNode: Element) => {
          entityType.keys.push(keyNode.getAttribute('Name') || '');
        });
    
        entityTypes.push(entityType);
      });
    
      return entityTypes;
    }
  • Calls registerDiscoveryTools() on HierarchicalSAPToolRegistry which likely registers get-entity-schema and other discovery tools
    await this.toolRegistry.registerDiscoveryTools();

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/Raistlin82/btp-sap-odata-to-mcp-server-optimized'

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