Skip to main content
Glama

prem_upload_document

Upload documents to a Prem AI repository for storage and retrieval, enabling document management and RAG capabilities.

Instructions

Upload a document to a Prem AI repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repository_idYesID of the repository to upload to
file_pathYesPath to the file to upload

Implementation Reference

  • The main handler function for the prem_upload_document tool. It reads the file, creates a FormData multipart request, and uploads it to the specified Prem AI repository using the Prem SDK's repository.document.create method. Handles errors and logs progress.
    async ({ repository_id, file_path }) => {
      const requestId = uuidv4();
      log(`[${requestId}] Starting document upload to repository ${repository_id}`);
      
      try {
        if (!fs.existsSync(file_path)) {
          throw new Error(`File not found: ${file_path}`);
        }
    
        const formData = new FormData();
        const fileStream = fs.createReadStream(file_path);
        const fileName = path.basename(file_path);
        
        formData.append('file', fileStream, {
          filename: fileName,
          contentType: 'text/plain',
          knownLength: fs.statSync(file_path).size
        });
    
        const response = await this.client.repository.document.create(
          repository_id,
          {
            data: formData,
            headers: {
              ...formData.getHeaders(),
              'Content-Type': 'multipart/form-data'
            }
          }
        );
    
        log(`[${requestId}] Document upload successful: ${JSON.stringify(response)}`);
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify(response, null, 2)
          }]
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        log(`[${requestId}] Document upload error: ${errorMessage}`);
        return {
          content: [{
            type: "text" as const,
            text: `Document upload error: ${errorMessage}`
          }],
          isError: true
        };
      }
    }
  • Zod input schema defining the required parameters: repository_id (string) and file_path (string).
    {
      repository_id: z.string().describe("ID of the repository to upload to"),
      file_path: z.string().describe("Path to the file to upload")
    },
  • src/index.ts:127-183 (registration)
    The tool registration call using McpServer.tool() method, specifying the tool name, description, input schema, and handler function.
    this.server.tool(
      "prem_upload_document",
      "Upload a document to a Prem AI repository",
      {
        repository_id: z.string().describe("ID of the repository to upload to"),
        file_path: z.string().describe("Path to the file to upload")
      },
      async ({ repository_id, file_path }) => {
        const requestId = uuidv4();
        log(`[${requestId}] Starting document upload to repository ${repository_id}`);
        
        try {
          if (!fs.existsSync(file_path)) {
            throw new Error(`File not found: ${file_path}`);
          }
    
          const formData = new FormData();
          const fileStream = fs.createReadStream(file_path);
          const fileName = path.basename(file_path);
          
          formData.append('file', fileStream, {
            filename: fileName,
            contentType: 'text/plain',
            knownLength: fs.statSync(file_path).size
          });
    
          const response = await this.client.repository.document.create(
            repository_id,
            {
              data: formData,
              headers: {
                ...formData.getHeaders(),
                'Content-Type': 'multipart/form-data'
              }
            }
          );
    
          log(`[${requestId}] Document upload successful: ${JSON.stringify(response)}`);
          return {
            content: [{
              type: "text" as const,
              text: JSON.stringify(response, null, 2)
            }]
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          log(`[${requestId}] Document upload error: ${errorMessage}`);
          return {
            content: [{
              type: "text" as const,
              text: `Document upload error: ${errorMessage}`
            }],
            isError: true
          };
        }
      }
    );
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'Upload' which implies a write operation, but doesn't disclose behavioral traits like authentication requirements, file size limits, supported formats, error handling, or what happens on success. This leaves significant gaps for an upload 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, clear sentence with zero waste—it directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded for an upload operation.

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?

Given no annotations, no output schema, and a mutation tool (upload), the description is incomplete. It lacks details on permissions, return values, error cases, or operational limits, which are critical for safe and effective 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%, so the schema already documents both parameters (repository_id, file_path). The description doesn't add any meaning beyond what the schema provides, such as examples or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('Upload') and target resource ('document to a Prem AI repository'), making the purpose immediately understandable. It doesn't differentiate from sibling tools (chat, prem_chat_with_template), which are unrelated communication tools, so it doesn't need explicit sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It simply states what the tool does without context about appropriate scenarios or constraints.

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/ucalyptus/prem-mcp-server'

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