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
| Name | Required | Description | Default |
|---|---|---|---|
| base_id | Yes | The ID of the base/project | |
| table_name | Yes | The name of the table | |
| record_id | Yes | The ID of the record | |
| attachment_field | Yes | The name of the attachment field | |
| file_path | Yes | Path to the file to upload and attach |
Implementation Reference
- src/tools/attachment.ts:139-203 (handler)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, }; } },
- src/tools/attachment.ts:107-138 (schema)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, ];