@gsb-core/mcp-docs
Version:
Documentation for GSB MCP implementations
173 lines (143 loc) • 5.38 kB
JavaScript
/**
* Documentation for the getDefinition operation
*/
/**
* Returns documentation for the getDefinition operation
* @return {string} markdown documentation
*/
export function getDefinitionDocs() {
return `
# GetDefinition Operation
## General Description
The \`getDefinition\` operation retrieves an entity definition, providing metadata about an entity type's structure, properties, and relationships.
## Detailed Description
This operation allows you to fetch the complete definition of an entity type, including its properties, relationships, validation rules, and other metadata. Entity definitions are the schema that define how entities are structured in the database. This operation is useful when you need to understand the structure of an entity type programmatically, such as for building dynamic forms, validating data, or exploring available properties.
## Input Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| request | object | Yes | The definition request object specifying which entity definition to retrieve. |
| token | string | No | Authentication token for your request. If not provided, the system will use the default API key from environment variables. |
| tenantCode | string | No | Tenant code to specify which tenant's data to access. If not provided, the system will extract it from the token or use the default tenant code from environment variables. |
### Request Object Structure
| Property | Type | Required | Description |
|----------|------|----------|-------------|
| entDefName | string | Yes* | Name of the entity definition to retrieve. Required if entDefId is not provided. |
| entDefId | string | Yes* | ID of the entity definition to retrieve. Required if entDefName is not provided. |
## Response
### Success Response
\`\`\`json
{
"success": true,
"data": {
// The complete entity definition object
"id": "string",
"name": "string",
"displayName": "string",
"properties": [
{
"name": "string",
"displayName": "string",
"type": "string",
"required": boolean,
"searchable": boolean,
// Additional property metadata
}
],
// Additional definition metadata
}
}
\`\`\`
### Error Response
\`\`\`json
{
"success": false,
"error": "Error message describing what went wrong"
}
\`\`\`
## Example Usage
### Get Definition by Name
\`\`\`typescript
const result = await getDefinition({
request: {
entDefName: "Customer"
},
token: "your-auth-token"
});
if (result.success) {
const entityDef = result.data;
console.log("Entity definition:", entityDef.name);
console.log("Properties:", entityDef.properties.map(p => p.name).join(", "));
} else {
console.error("Error:", result.error);
}
\`\`\`
### Get Definition by ID
\`\`\`typescript
const result = await getDefinition({
request: {
entDefId: "customer-definition-id"
},
token: "your-auth-token"
});
if (result.success) {
const entityDef = result.data;
// Process the entity definition
}
\`\`\`
### Using Definition to Validate Data
\`\`\`typescript
const result = await getDefinition({
request: { entDefName: "Product" },
token: "your-auth-token"
});
if (result.success) {
const entityDef = result.data;
// Extract required properties
const requiredProps = entityDef.properties
.filter(prop => prop.required)
.map(prop => prop.name);
// Validate a product object
function validateProduct(product) {
const missingProps = requiredProps.filter(prop => !product.hasOwnProperty(prop));
if (missingProps.length > 0) {
return \`Missing required properties: \${missingProps.join(", ")}\`;
}
return null; // No validation errors
}
}
\`\`\`
## Additional Information
- Entity definitions contain the complete metadata about an entity type, including:
- Basic information (name, display name, description)
- Properties (name, type, constraints, validation rules)
- Relationships to other entity types
- Indexes and search configuration
- Security and access control settings
- This operation is particularly useful for building dynamic UIs that adapt to the entity structure.
- For querying multiple entity definitions, use the queryEntityDefs operation instead.
- For creating or modifying entity definitions, use the createEntityDef and updateEntityDef operations.
- Access permissions are enforced based on the provided token.
- The structure of entity definitions may vary based on the entity type and system configuration.
`;
}
/**
* Returns a brief summary of the getDefinition operation.
* @return {string} A short description of the function.
*/
export function getDefinitionSummary() {
return `
**Purpose**: Retrieves complete metadata for a specific entity type (schema).
**When to use**:
- Need entity structure details
- Building dynamic forms
- Validating entity data
- Exploring available properties
**Inputs**:
- request: Object with either entDefName or entDefId {entDefName/entDefId: string}
- token (optional)
- tenantCode (optional)
**Returns**: Complete entity definition with properties, relationships, and constraints.
`;
}
export default getDefinitionDocs;
//# sourceMappingURL=getDefinition.js.map