Skip to main content
Glama
crazyrabbitLTC

Brex MCP Server

upload_receipt

Upload receipt images to match with business expenses in the Brex financial platform. Submit base64-encoded image data with file name and content type for expense tracking.

Instructions

Upload a receipt image to match with expenses

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
receipt_dataYesBase64-encoded image data
receipt_nameYesName of the receipt file (e.g., 'receipt.jpg')
content_typeYesMIME type of the receipt (e.g., 'image/jpeg')

Implementation Reference

  • Core execution handler for the upload_receipt tool: validates input, decodes base64 receipt, uploads via helper, returns JSON response with receipt ID.
    registerToolHandler("upload_receipt", async (request: ToolCallRequest) => {
      try {
        // Validate parameters
        const params = validateParams(request.params.arguments);
        logDebug(`Uploading receipt named: ${params.receipt_name}`);
        
        // Get Brex client
        const brexClient = getBrexClient();
        
        try {
          // Upload receipt to Brex using our helper function
          const uploadResult = await uploadReceipt(brexClient, {
            file: Buffer.from(params.receipt_data, 'base64'),
            filename: params.receipt_name,
            contentType: params.content_type
          });
          
          if (!uploadResult || !uploadResult.id) {
            throw new Error("Invalid response from receipt upload");
          }
          
          logDebug(`Successfully uploaded receipt with ID: ${uploadResult.id}`);
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                status: "success",
                receipt_id: uploadResult.id,
                message: `Receipt uploaded successfully with ID: ${uploadResult.id}`
              }, null, 2)
            }]
          };
        } catch (apiError) {
          logError(`Error uploading receipt: ${apiError instanceof Error ? apiError.message : String(apiError)}`);
          throw new Error(`Failed to upload receipt: ${apiError instanceof Error ? apiError.message : String(apiError)}`);
        }
      } catch (error) {
        logError(`Error in upload_receipt tool: ${error instanceof Error ? error.message : String(error)}`);
        throw error;
      }
    });
  • Official MCP input schema for upload_receipt tool, defining required base64 data, filename, and content type.
    name: "upload_receipt",
    description: "Upload a receipt image to match with expenses",
    inputSchema: {
      type: "object",
      properties: {
        receipt_data: {
          type: "string",
          description: "Base64-encoded image data"
        },
        receipt_name: {
          type: "string",
          description: "Name of the receipt file (e.g., 'receipt.jpg')"
        },
        content_type: {
          type: "string",
          description: "MIME type of the receipt (e.g., 'image/jpeg')"
        }
      },
      required: ["receipt_data", "receipt_name", "content_type"]
    }
  • Top-level registration call for the upload_receipt tool during server setup.
    registerUploadReceipt(server);
  • Helper function implementing the receipt upload logic to Brex (simulated for demo).
    async function uploadReceipt(client: BrexClient, options: UploadReceiptOptions): Promise<UploadReceiptResult> {
      // This is a fake implementation since the actual method doesn't exist
      // In a real implementation, you would use the proper Brex API endpoint
      logDebug(`Simulating receipt upload for ${options.filename} (${options.contentType})`);
      
      try {
        // Here we would use the proper Brex API method
        // For example, it might be something like client.api.post('/receipts/upload', formData)
        
        // Simulate API delay
        await new Promise(resolve => setTimeout(resolve, 500));
        
        // Return a fake successful result
        return {
          id: `receipt-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`,
          url: `https://api.brex.com/receipts/download/${Date.now()}`
        };
      } catch (error) {
        logError(`Failed to upload receipt: ${error instanceof Error ? error.message : String(error)}`);
        throw new Error(`Receipt upload failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Parameter validation helper ensuring required receipt_data and receipt_name are present.
    function validateParams(input: any): UploadReceiptParams {
      if (!input) {
        throw new Error("Missing parameters");
      }
      
      if (!input.receipt_data) {
        throw new Error("Missing required parameter: receipt_data");
      }
      
      if (!input.receipt_name) {
        throw new Error("Missing required parameter: receipt_name");
      }
      
      const params: UploadReceiptParams = {
        receipt_data: input.receipt_data,
        receipt_name: input.receipt_name,
        content_type: input.content_type || 'application/pdf'
      };
      
      return params;
    }

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/crazyrabbitLTC/mcp-brex-server'

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