Skip to main content
Glama
andrewlwn77
by andrewlwn77

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,
    ];
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a write operation ('attach') but doesn't disclose permissions needed, rate limits, error conditions, or what happens if the attachment field doesn't exist. This leaves significant gaps for a mutation tool.

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?

The description is a single, efficient sentence that directly states the tool's function without any wasted words. It's appropriately sized and front-loaded with the core action.

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

Completeness2/5

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

For a mutation tool with 5 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'attached' means operationally, what the response contains, or error handling, leaving too much undefined for reliable agent use.

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

Parameters3/5

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

Schema description coverage is 100%, providing clear documentation for all 5 parameters. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline for adequate but unenhanced coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('attach') and target ('uploaded file to a record'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'upload_attachment' or 'upload_attachment_by_url', which prevents a perfect score.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'upload_attachment' or 'upload_attachment_by_url'. The description assumes the file is already uploaded, but doesn't clarify prerequisites or context for selection among attachment-related tools.

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

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