get_document
Retrieve document content as base64 encoded string by providing a document ID. Validates access permissions before returning the encoded content from the Pega system.
Instructions
Get contents of a document as base64 encoded string. Downloads document content based on the documentID parameter. The API validates the documentID and checks if the user has access to view the document before returning the base64 encoded content.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentID | Yes | Document ID to retrieve content for. This is the unique identifier that identifies the specific document in the Pega system. The document must exist and be accessible to the current user. | |
| sessionCredentials | No | Optional session-specific credentials. If not provided, uses environment variables. Supports two authentication modes: (1) OAuth mode - provide baseUrl, clientId, and clientSecret, or (2) Token mode - provide baseUrl and accessToken. |
Implementation Reference
- Defines the tool schema, name, description, and input schema requiring documentID for the get_document tool.static getDefinition() { return { name: 'get_document', description: 'Get contents of a document as base64 encoded string. Downloads document content based on the documentID parameter. The API validates the documentID and checks if the user has access to view the document before returning the base64 encoded content.', inputSchema: { type: 'object', properties: { documentID: { type: 'string', description: 'Document ID to retrieve content for. This is the unique identifier that identifies the specific document in the Pega system. The document must exist and be accessible to the current user.' }, sessionCredentials: getSessionCredentialsSchema() }, required: ['documentID'] } }; }
- The execute method is the main handler for the get_document tool. It performs parameter validation, session initialization, and calls the pegaClient to retrieve the document content, with comprehensive error handling.async execute(params) { const { documentID } = params; let sessionInfo = null; try { sessionInfo = this.initializeSessionConfig(params); // Basic parameter validation using base class const requiredValidation = this.validateRequiredParams(params, ['documentID']); if (requiredValidation) { return requiredValidation; } // Additional comprehensive parameter validation const validationResult = this.validateParameters(documentID); if (!validationResult.valid) { return { error: validationResult.error }; } // Execute with standardized error handling return await this.executeWithErrorHandling( `Document Content: ${documentID}`, async () => await this.pegaClient.getDocumentContent(documentID), { documentID, sessionInfo } ); } catch (error) { return { content: [{ type: 'text', text: `## Error: Document Content: ${documentID}\n\n**Unexpected Error**: ${error.message}\n\n${sessionInfo ? `**Session**: ${sessionInfo.sessionId} (${sessionInfo.authMode} mode)\n` : ''}*Error occurred at: ${new Date().toISOString()}*` }] }; } }
- src/api/pega-client.js:725-727 (helper)Helper method in PegaClient wrapper that delegates to the underlying client to fetch document content by ID.async getDocumentContent(documentID) { return this.client.getDocumentContent(documentID); }