Skip to main content
Glama
rspace-os

RSpace MCP Server

Official
by rspace-os

uploadAndAttachFile

Upload files to RSpace documents and attach them as proper file attachments in one step. Supports all file types including images, PDFs, and data files.

Instructions

Uploads a file to RSpace and attaches it to a document as a proper file attachment

Usage: One-step process to upload any file and attach it to an RSpace document File types: Supports all file types (images, PDFs, data files, protocols, etc.) Attachment: Creates proper RSpace file attachment, not just a link

Parameters:

  • document_id: RSpace document ID (numeric or global ID like "SD12345")

  • file_path: Path to the file to upload (e.g., "data/results.pdf")

  • caption: Optional caption that appears with the attachment

  • description: Optional description for the uploaded file

Returns: Upload confirmation and document update information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
document_idYes
file_pathYes
captionNo
descriptionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • main.py:651-732 (handler)
    Handler function for uploadAndAttachFile tool. Uploads a file using eln_cli.upload_file, attaches it to the specified document by updating the first field with RSpace native attachment format <fileId={file_id}>, includes optional caption and description. Handles errors like file not found.
    @mcp.tool(tags={"rspace", "files"})
    def uploadAndAttachFile(
        document_id: Union[int, str],
        file_path: str,
        caption: Optional[str] = None,
        description: Optional[str] = None
    ) -> dict:
        """
        Uploads a file to RSpace and attaches it to a document as a proper file attachment
        
        Usage: One-step process to upload any file and attach it to an RSpace document
        File types: Supports all file types (images, PDFs, data files, protocols, etc.)
        Attachment: Creates proper RSpace file attachment, not just a link
        
        Parameters:
        - document_id: RSpace document ID (numeric or global ID like "SD12345")
        - file_path: Path to the file to upload (e.g., "data/results.pdf")
        - caption: Optional caption that appears with the attachment
        - description: Optional description for the uploaded file
        
        Returns: Upload confirmation and document update information
        """
        try:
            # Step 1: Upload the file to RSpace
            with open(file_path, 'rb') as file:
                upload_result = eln_cli.upload_file(file, caption=description)
            
            file_id = upload_result.get('id')
            if not file_id:
                return {"error": "File upload failed - no file ID returned"}
            
            # Step 2: Get the current document
            document = eln_cli.get_document(document_id)
            if not document.get('fields'):
                return {"error": f"Document {document_id} has no fields to attach file to"}
            
            # Step 3: Create proper RSpace file attachment
            # This is the key fix - use RSpace's native attachment format
            attachment_html = f'<fileId={file_id}>'
            
            # Add caption as separate paragraph if provided
            if caption:
                attachment_html = f'<p><strong>{caption}</strong></p>\n{attachment_html}'
            
            # Step 4: Update the document with the file attachment
            first_field = document['fields'][0]
            current_content = first_field.get('content', '')
            updated_content = current_content + '\n' + attachment_html
            
            # Update the document
            update_result = eln_cli.update_document(
                document_id=document_id,
                fields=[{
                    'id': first_field['id'],
                    'content': updated_content
                }]
            )
            
            return {
                "success": True,
                "message": "File uploaded and attached successfully",
                "file_info": {
                    "file_id": file_id,
                    "name": upload_result.get('name'),
                    "size": upload_result.get('size'),
                    "globalId": upload_result.get('globalId'),
                    "description": description
                },
                "attachment_info": {
                    "document_id": str(document_id),
                    "caption": caption,
                    "attachment_format": "rspace_native",
                    "field_updated": first_field['id']
                },
                "updated_document": update_result
            }
            
        except FileNotFoundError:
            return {"error": f"File not found: {file_path}"}
        except Exception as e:
            return {"error": f"Failed to upload and attach file: {str(e)}"}
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that this is a write operation (upload and attach), mentions it supports all file types, and creates proper attachments. However, it doesn't cover important behavioral aspects like authentication requirements, file size limits, error conditions, or whether the operation is idempotent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, usage, file types, attachment type, parameters, returns) and every sentence adds value. It could be slightly more concise by combining some bullet points, but overall it's efficiently organized and front-loaded with the core purpose.

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

Completeness4/5

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

Given this is a write operation with 4 parameters, 0% schema coverage, but with an output schema present, the description does a good job. It covers the purpose, usage context, parameters semantics, and return information. The main gap is lack of behavioral warnings or constraints that would be important for a file upload tool (size limits, supported formats beyond 'all file types', etc.).

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing clear semantic explanations for all 4 parameters. It explains what 'document_id' represents (RSpace document ID with format examples), 'file_path' (path to upload), and clarifies that 'caption' and 'description' are optional with their specific purposes.

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

Purpose5/5

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

The description clearly states the specific action ('uploads a file to RSpace and attaches it to a document') and distinguishes it from siblings by specifying it's a 'proper file attachment, not just a link'. It explicitly mentions the resource (RSpace document) and the one-step process nature.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool ('one-step process to upload any file and attach it to an RSpace document') and mentions supported file types. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools (like 'update_document' or other 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/rspace-os/rspace-mcp'

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