Skip to main content
Glama

upload_receipt

Upload receipt images to automatically match them with corresponding expense records in the Brex financial platform for accurate expense tracking.

Instructions

Upload a receipt image to match with expenses

Input Schema

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

Implementation Reference

  • Main execution handler for the 'upload_receipt' tool. Validates input, decodes base64 receipt data to Buffer, calls upload helper with BrexClient, handles errors, and 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; } });
  • TypeScript interfaces defining the input parameters, upload options, and expected result structure for the upload_receipt tool.
    /** * Interface for upload_receipt tool input parameters */ interface UploadReceiptParams { receipt_data: string; receipt_name: string; content_type: string; } /** * Interface for receipt upload options */ interface UploadReceiptOptions { file: Buffer; filename: string; contentType: string; } /** * Interface for upload result */ interface UploadReceiptResult { id: string; url?: string; }
  • Helper function implementing the receipt upload logic using BrexClient (currently a placeholder simulation).
    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)}`); } }
  • Validates and normalizes input parameters for the upload_receipt tool, ensuring required fields and setting default content_type.
    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; }
  • Registration call for the upload_receipt tool within the main registerTools function.
    registerGetAccountDetails(server); registerUploadReceipt(server);
  • JSON input schema for 'upload_receipt' tool exposed in the MCP list_tools response.
    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"] } },

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