Skip to main content
Glama

attach_file_to_record

Attach uploaded files to database records in NocoDB by specifying the base, table, record, and attachment field.

Instructions

Attach an uploaded file to a record

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_idYesThe ID of the base/project
table_nameYesThe name of the table
record_idYesThe ID of the record
attachment_fieldYesThe name of the attachment field
file_pathYesPath to the file to upload and attach

Implementation Reference

  • The handler function that implements the core logic of uploading a file to NocoDB storage and attaching it to a specific record by updating the attachment field.
    handler: async ( client: NocoDBClient, args: { base_id: string; table_name: string; record_id: string; attachment_field: string; file_path: string; }, ) => { try { // First upload the file const uploadResult = await client.uploadFile(args.file_path); // Get current record const record = await client.getRecord( args.base_id, args.table_name, args.record_id, ); // Get existing attachments if any const existingAttachments = record[args.attachment_field]; let attachments = []; if (existingAttachments) { attachments = typeof existingAttachments === "string" ? JSON.parse(existingAttachments) : existingAttachments; if (!Array.isArray(attachments)) { attachments = [attachments]; } } // Add new attachment attachments.push(uploadResult); // Update record with new attachment await client.updateRecord( args.base_id, args.table_name, args.record_id, { [args.attachment_field]: attachments, }, ); return { success: true, message: "File uploaded and attached to record", file_name: path.basename(args.file_path), record_id: args.record_id, attachment_field: args.attachment_field, total_attachments: attachments.length, }; } catch (error: any) { return { success: false, error: error.message, file_path: args.file_path, record_id: args.record_id, }; } },
  • The input schema defining parameters for the attach_file_to_record tool: base_id, table_name, record_id, attachment_field, and file_path.
    inputSchema: { type: "object", properties: { base_id: { type: "string", description: "The ID of the base/project", }, table_name: { type: "string", description: "The name of the table", }, record_id: { type: "string", description: "The ID of the record", }, attachment_field: { type: "string", description: "The name of the attachment field", }, file_path: { type: "string", description: "Path to the file to upload and attach", }, }, required: [ "base_id", "table_name", "record_id", "attachment_field", "file_path", ], },
  • src/index.ts:55-62 (registration)
    The attachmentTools array (containing attach_file_to_record) is spread into the allTools array, which is then used to register all tools with the MCP server for listing and calling.
    const allTools = [ ...databaseTools, ...tableTools, ...recordTools, ...viewTools, ...queryTools, ...attachmentTools, ];

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/andrewlwn77/nocodb-mcp'

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