Skip to main content
Glama
marco-looy

Pega DX MCP Server

by marco-looy

get_attachment

Retrieve attachment content from Pega by providing an attachment ID, returning files as Base64, URLs as links, or correspondence as HTML after validating access permissions.

Instructions

Get the attachment content based on the attachmentID. Returns different content types: Base64 data for file type attachments, URL for URL type attachments, and HTML data for correspondence type attachments. The API validates the attachmentID and checks if the user has access to view the attachment before returning the content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
attachmentIDYesLink-Attachment instance pzInsKey (attachment ID) to retrieve content for. Format example: "LINK-ATTACHMENT MYCO-PAC-WORK E-47009!20231016T062800.275 GMT". This is the complete instance handle key that uniquely identifies the attachment in the Pega system. The attachment must exist and be accessible to the current user.
sessionCredentialsNoOptional 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

  • The main execute method implementing the get_attachment tool. Validates attachmentID, initializes session, and calls pegaClient.getAttachmentContent(attachmentID) with error handling.
    async execute(params) {
      const { attachmentID } = params;
    
      let sessionInfo = null;
      try {
        sessionInfo = this.initializeSessionConfig(params);
    
        // Basic parameter validation using base class
        const requiredValidation = this.validateRequiredParams(params, ['attachmentID']);
        if (requiredValidation) {
          return requiredValidation;
        }
    
        // Additional comprehensive parameter validation for complex logic
        const validationResult = this.validateParameters(attachmentID);
        if (!validationResult.valid) {
          // Return proper MCP error response format
          return {
            content: [
              {
                type: 'text',
                text: `## Parameter Validation Error\n\n**Error**: ${validationResult.error}\n\n**Solution**: Please provide a valid Link-Attachment instance pzInsKey and try again.`
              }
            ]
          };
        }
    
        // Execute with standardized error handling
        return await this.executeWithErrorHandling(
          `Attachment Content: ${attachmentID}`,
          async () => await this.pegaClient.getAttachmentContent(attachmentID),
          { attachmentID, sessionInfo }
        );
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `## Error: Attachment Content\n\n**Unexpected Error**: ${error.message}\n\n${sessionInfo ? `**Session**: ${sessionInfo.sessionId} (${sessionInfo.authMode} mode)\n` : ''}*Error occurred at: ${new Date().toISOString()}*`
          }]
        };
      }
    }
  • Static getDefinition method providing the tool name, description, and inputSchema for MCP protocol validation.
    static getDefinition() {
      return {
        name: 'get_attachment',
        description: 'Get the attachment content based on the attachmentID. Returns different content types: Base64 data for file type attachments, URL for URL type attachments, and HTML data for correspondence type attachments. The API validates the attachmentID and checks if the user has access to view the attachment before returning the content.',
        inputSchema: {
          type: 'object',
          properties: {
            attachmentID: {
              type: 'string',
              description: 'Link-Attachment instance pzInsKey (attachment ID) to retrieve content for. Format example: "LINK-ATTACHMENT MYCO-PAC-WORK E-47009!20231016T062800.275 GMT". This is the complete instance handle key that uniquely identifies the attachment in the Pega system. The attachment must exist and be accessible to the current user.'
            },
            sessionCredentials: getSessionCredentialsSchema()
          },
          required: ['attachmentID']
        }
      };
    }
  • validateParameters helper method for comprehensive attachmentID validation including format checks.
    validateParameters(attachmentID) {
      // Validate attachmentID
      if (!attachmentID || typeof attachmentID !== 'string' || attachmentID.trim() === '') {
        return {
          valid: false,
          error: 'Invalid attachmentID parameter. Attachment ID must be a non-empty string containing the full Link-Attachment instance handle (Example: "LINK-ATTACHMENT MYCO-PAC-WORK E-47009!20231016T062800.275 GMT").'
        };
      }
    
      // Basic format validation for Link-Attachment instance key
      if (!attachmentID.includes('LINK-ATTACHMENT')) {
        return {
          valid: false,
          error: 'Invalid attachmentID format. Expected Link-Attachment instance pzInsKey format (Example: "LINK-ATTACHMENT MYCO-PAC-WORK E-47009!20231016T062800.275 GMT").'
        };
      }
    
      return { valid: true };
    }
  • Dynamic registration in ToolLoader: finds GetAttachmentTool class, validates, instantiates, and registers by name 'get_attachment' in loadedTools map.
      const ToolClass = this.findToolClass(module);
      if (!ToolClass) {
        console.warn(`No valid tool class found in ${filename}`);
        return null;
      }
      
      // Validate tool class
      if (!this.validateToolClass(ToolClass, category, filename)) {
        return null;
      }
      
      // Create and register tool instance
      const toolInstance = new ToolClass();
      const toolName = ToolClass.getDefinition().name;
      
      this.loadedTools.set(toolName, {
        instance: toolInstance,
        class: ToolClass,
        category: category,
        filename: filename
      });
      
      return toolInstance;
    } catch (error) {
  • PegaClient.getAttachmentContent method called by the tool handler to fetch attachment content from Pega API.
    async getAttachmentContent(attachmentID) {
      return this.client.getAttachmentContent(attachmentID);
    }
    
    /**
     * Delete attachment
     * @param {string} attachmentID - Attachment ID
     * @returns {Promise<Object>} Deletion result
     */
    async deleteAttachment(attachmentID) {
      return this.client.deleteAttachment(attachmentID);
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by disclosing key behaviors: it returns different content types (Base64, URL, HTML) based on attachment type, validates the attachmentID, and checks user access before returning content. It doesn't mention error handling, rate limits, or performance characteristics, but covers the essential operational behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two well-structured sentences: first states purpose and return types, second describes validation and access control. Every word earns its place with no redundancy or fluff. The description is appropriately sized for its complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description provides good coverage of what the tool does, return value variations, and security behaviors. It could be more complete by mentioning error cases or the optional sessionCredentials parameter, but overall it gives the agent sufficient context to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description mentions 'attachmentID' but adds no additional semantic context beyond what the schema provides about format, uniqueness, or accessibility. It doesn't mention the optional sessionCredentials parameter at all.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and resource 'attachment content' with specific identification via 'attachmentID'. It distinguishes from siblings like get_case_attachments (list) and delete_attachment/update_attachment by focusing on content retrieval rather than metadata or modifications.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when needing attachment content rather than metadata, but doesn't explicitly state when to use this vs. get_case_attachments (which lists attachments) or other attachment-related tools. It mentions validation and access checks as prerequisites but doesn't provide clear alternatives or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/marco-looy/pega-dx-mcp'

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