Skip to main content
Glama

Attach Document To Case

pega.attach_document_to_case

Attach files or URLs to an existing case by providing the case ID and document data, supporting direct payload or base64 upload methods.

Instructions

Use this tool to attach files or URLs to an existing case. Required input: caseId. Attachment input mode 1: attachments array payload. Attachment input mode 2: fileName + fileContentBase64 (optional mimeType) for upload-then-attach flow. Returns: { ok: true, data: } on success. Standard failure format: { ok: false, error: { code, message, suggestion? } }.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
caseIdYesUnique case identifier/handle.
attachmentsNoOptional direct attachment payload array sent to the case attachments endpoint.
fileNameNoFile name including extension.
mimeTypeNoOptional MIME type for base64 upload mode.
fileContentBase64NoOptional document bytes encoded as base64. Used for upload-then-attach mode.
originChannelNoOptional channel hint, for example Web or Mobile.

Implementation Reference

  • The tool definition's execution handler for 'pega.attach_document_to_case'. It calls the underlying client method.
    execute: async ({ pegaClient }, input) => {
      return withCaseAccessGuard(pegaClient, input, async () => {
        return pegaClient.attachDocumentToCase(input);
      });
    }
  • The core logic in PegaClient that implements document attachment, including potential temporary file upload if base64 content is provided.
    async attachDocumentToCase(input: {
      caseId: string;
      attachments?: Array<Record<string, unknown>>;
      fileName?: string;
      mimeType?: string;
      fileContentBase64?: string;
      originChannel?: string;
    }): Promise<DocumentAttachResult> {
      const originChannel = input.originChannel ?? "Web";
      let attachments = input.attachments;
    
      if ((!attachments || attachments.length === 0) && input.fileName && input.fileContentBase64) {
        const uploadedAttachmentId = await this.uploadTemporaryAttachmentFromBase64({
          fileName: input.fileName,
          mimeType: input.mimeType ?? "application/octet-stream",
          fileContentBase64: input.fileContentBase64,
          originChannel
        });
        attachments = [{ type: "File", category: "File", ID: uploadedAttachmentId }];
      }
    
      if (!attachments || attachments.length === 0) {
        throw new Error("Attachment payload is missing. Provide attachments[] or base64 file fields.");
      }
    
      const result = await this.request<unknown>(
        `${this.getCasesApiBasePath()}/cases/${encodeURIComponent(input.caseId)}/attachments`,
        {
          method: "POST",
          headers: {
            "x-origin-channel": originChannel
          },
          body: JSON.stringify({
            attachments
          })
        }
      );
    
      return {
        success: true,
        caseId: input.caseId,
        documentName: input.fileName,
        message: "Attachment request completed",
        details: result
      };
    }
  • Definition and registration of the 'pega.attach_document_to_case' tool.
    export const attachDocumentToCaseToolDefinition = defineTool({
      name: "pega.attach_document_to_case",
      title: "Attach Document To Case",
      description: [
        "Use this tool to attach files or URLs to an existing case.",
        "Required input: caseId.",
        "Attachment input mode 1: attachments array payload.",
        "Attachment input mode 2: fileName + fileContentBase64 (optional mimeType) for upload-then-attach flow.",
        "Returns: { ok: true, data: <attachment result> } on success."
      ].join(" "),
      inputSchema: attachDocumentToCaseSchema,
      invalidInputMessage: "caseId is required, plus attachments[] or fileName+fileContentBase64",
      validateInput: (input) => {
        const hasAttachments = Array.isArray(input.attachments) && input.attachments.length > 0;
        const hasUploadFields = Boolean(input.fileName && input.fileContentBase64);
    
        if (!hasAttachments && !hasUploadFields) {
          return {
            code: "INVALID_INPUT",
            message: "attachments[] or fileName+fileContentBase64 is required",
            suggestion: "Provide either an attachments array or base64 upload fields."
          };
        }
    
        return null;
      },
      execute: async ({ pegaClient }, input) => {
        return withCaseAccessGuard(pegaClient, input, async () => {
          return pegaClient.attachDocumentToCase(input);
        });
      }
    });
Behavior4/5

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

No annotations provided, so description carries full burden. Discloses return format structure for both success and failure cases ({ ok: true/false, ... }), compensating for lack of output schema. Explains the dual-mode upload flow behavior, though could explicitly state this modifies the case.

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?

Efficient structure: purpose statement, required input highlight, two mode explanations, then return formats. Every sentence conveys essential information; the JSON return examples are compact and informative rather than verbose.

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

Completeness5/5

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

Comprehensive for a 6-parameter tool with dual invocation patterns. Covers return values (absent output schema), required fields, optional variations, and the channel hint parameter. Addresses the complexity of base64 vs direct attachmentpayloads adequately.

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

Parameters4/5

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

Schema coverage is 100% (baseline 3). Description adds significant value by grouping parameters into 'Mode 1' vs 'Mode 2' patterns, explaining the semantic relationship that attachments array is mutually exclusive with fileName/fileContentBase64 parameters.

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?

Excellent clarity: specific verb 'attach' with resources 'files or URLs' and target 'existing case'. Clearly distinguishes from sibling 'get_*' tools (read operations) and 'submit_case_action' by focusing specifically on document attachment.

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

Usage Guidelines4/5

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

Provides clear guidance on two mutually exclusive input modes (attachments array vs fileName/fileContentBase64), which is crucial for correct invocation. Lacks explicit contrast with sibling tools, though the attachment-specific purpose makes this relatively clear.

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/amirmcs/Pega-MCP'

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