UNPKG

@gsb-core/mcp-docs

Version:

Documentation for GSB MCP implementations

8 lines (7 loc) 8.63 kB
export declare const createOrUpdateSchema = "\n# createOrUpdateSchema\n\nCreates or updates multiple entity definitions and their properties in a single operation, with intelligent handling of reference properties between entities.\n\n## Parameters\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| entityDefs | GsbEntityDef[] | Array of entity definitions to create or update |\n| token | string | (Optional) Authentication token |\n| tenantCode | string | (Optional) Tenant code |\n\n## Returns\n\n```typescript\n{\n createdEntities: GsbEntityDef[]; // List of entities created\n updatedEntities: GsbEntityDef[]; // List of entities updated\n errors: string[]; // Any errors that occurred during processing\n success: boolean; // Whether the operation succeeded\n}\n```\n\n## Example\n\n```typescript\n// Define multiple related entities\nconst customerDef = {\n id: \"customer-entity-definition-id\",\n name: \"Customer\",\n title: \"Customer Information\",\n description: \"Stores customer data\",\n permissions:[{id:\"all-users-read-permission-id\"}, {id:\"sales-team-write-permission-id\"}] // If you don't pass permissions, all users can read and write\n properties: [\n {\n id:\"customer-id-property-id\",\n name: \"id\",\n title: \"ID\",\n description: \"Unique identifier for the customer\",\n definition_id: \"5c0aa76f-9c32-4e7e-a4bc-b56e93877883\", // Every definition must have an id property\n isRequired: true,\n },\n {\n id:\"customer-name-property-id\",\n name: \"name\",\n title: \"Name\",\n description: \"Customer name\",\n definition_id: \"c6c34bf3-f51b-4e69-a689-b09847be74b9\", // String type\n isRequired: true,\n isSearchable: true\n },\n {\n id:\"customer-password-property-id\",\n name: \"password\",\n title: \"Password\",\n description: \"Customer password\",\n definition_id: \"c6c34bf3-f51b-4e69-a689-b09847be74b9\", // String type,\n isEncrypted: true, // Encrypted property\n permissions:[{id:\"only-self-read-permission-id\"}] // only the owner can read the property\n }\n ]\n};\n\nconst orderDef = {\n id: \"order-entity-definition-id\",\n name: \"Order\",\n title: \"Order Information\",\n description: \"Stores order data\",\n permissions:[{id:\"all-users-read-permission-id\"}, {id:\"sales-team-write-permission-id\"}] // If you don't pass permissions, all users can read and write\n properties: [\n {\n id:\"order-id-property-id\",\n name: \"id\",\n title: \"ID\",\n description: \"Unique identifier for the order\",\n definition_id: \"5c0aa76f-9c32-4e7e-a4bc-b56e93877883\", // Id type\n isRequired: true,\n isSearchable: true\n },\n {\n id:\"order-notes-property-id\",\n name: \"notes\",\n title: \"Notes\",\n description: \"Notes of the order\",\n definition_id: \"e07f578e-2705-49c1-b97f-3ca5963c67c0\", // RichText type\n isRequired: true,\n isSearchable: true,\n fullTextIndex: true // Create vector index for full text search\n },\n {\n id:\"order-customer-property-id\",\n name: \"customer\",\n title: \"Customer\",\n description: \"Customer who placed the order\",\n definition_id: \"924acba8-58c5-4881-940d-472ec01eba5f\", // Reference type\n refEntDef_id: \"customer-entity-definition-id\", // Will be replaced with actual Customer entity ID\n refEntPropName: \"orders\", // Creates a back-reference property in Customer\n refType: 2 // OneToMany relationship\n },\n { \n id:\"order-items-property-id\",\n name:\"items\",\n title:\"Items\",\n description:\"Items in the order\",\n definition_id:\"924acba8-58c5-4881-940d-472ec01eba5f\", // Reference type\n refEntDef_id:\"item-entity-definition-id\", // Will be replaced with actual Item entity ID\n refEntPropName:\"order\", // Creates a back-reference property in Item\n refType: 3, // ManyToOne relationship\n cascadeReference: true // Cascade delete, also include in copy operation\n },\n {\n id:\"order-tags-property-id\",\n name:\"tags\",\n title:\"Tags\",\n description:\"Tags in the order\",\n definition_id:\"924acba8-58c5-4881-940d-472ec01eba5f\", // Reference type\n refEntDef_id:\"tag-entity-definition-id\", // Will be replaced with actual Tag entity ID\n refEntPropName:\"orders\", // Creates a back-reference property in Tag\n refType: 4 // ManyToMany relationship\n },\n {\n id:\"order-invoice-property-id\",\n name:\"invoice\",\n title:\"Invoice\",\n description:\"Invoice in the order\",\n definition_id:\"924acba8-58c5-4881-940d-472ec01eba5f\", // Reference type\n refEntDef_id:\"invoice-entity-definition-id\", // Will be replaced with actual Invoice entity ID\n refEntPropName:\"order\", // Creates a back-reference property in Invoice\n refType: 1 // OneToOne relationship\n }\n ]\n};\n\n// Create or update both entity definitions with reference handling in one operation\nconst result = await mcp.createOrUpdateSchema({\n entityDefs: [customerDef, orderDef]\n});\n\nif (result.success) {\n console.log(`Created ${result.createdEntities.length} entities`);\n console.log(`Updated ${result.updatedEntities.length} entities`);\n} else {\n console.error(\"Errors:\", result.errors);\n}\n```\n\n## Description\n\nThe `createOrUpdateSchema` tool provides a way to create or update multiple entity definitions in a single operation. This is particularly useful when creating a set of related entities with reference properties between them.\n\n### Schema Creation Best Practices\n\nWhen creating an initial schema with multiple related entity definitions:\n\n1. **Define all entity definitions in a single operation**:\n - Using createOrUpdateSchema, you can define the entire schema structure at once\n - The service will manage dependency order and relationships automatically\n - \u0130f its first time to create the schema, its essential to pass all entity definitions in a single operation, so GSB can manage the dependencies between entities correctly.\n - If you want to add new entity definitions to the schema, you can use the createEntityDef method.\n\n2. **Reference Property Management**:\n - Specify the correct `refEntDef_id`, `refEntPropName` and `refType`\n - For single relationships (OneToOne, ManyToOne), foreign keys properties(ending with _id) are automatically created\n - For example, adding `customer` ref property to an Order as OneToMany relationship(refType: 2) with refentpropname: orders\n * `customer_id` field will be automatically created in the Order entity definition\n * `orders` field will be automatically created in the Customer entity definition\n\n3. **ID management**:\n - Every definition and property must have an id property.\n - If you don't pass an id, it will be generated by the system, and will be included in the response.\n - Its essential that every ID you provide is globally unique.\n\n4. **Caching and availability**:\n - Upon creation or editing of an entity definition, the system will initiate a cache update process across all redundant servers.\n - The cache update process is asynchronous and may take up to 5 seconds to complete.\n - During this time, the new or updated entity definitions may not be immediately available for use.\n - Its also important to wait for the cache update process to complete before adding new properties or referencing the new entity definitions.\n\n5. **Permissions**:\n - If you don't pass permissions, all users can read and write the entity definitions and properties.\n - If you pass permissions, the permissions will act as policies, if users cridentials match any policy, they will be able to execute the operation of the policy.\n - Permissions can be defined in the Admin UI, or with API by using the entity definition named : \"GsbPermission\"\n - Dont pass permision ids that dont exist in the system, instead you can pass a fully defined GsbPermission object.\n\n### Reference Types\n\nThe `refType` property defines the relationship type:\n\n```typescript\nenum RefType {\n OneToOne = 1,\n OneToMany = 2,\n ManyToOne = 3,\n ManyToMany = 4\n}\n```\n"; /** * Returns a brief summary of the createOrUpdateSchema operation. * @return {string} A short description of the function. */ export declare function createOrUpdateSchemaSummary(): string; export default function (): string;