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
| Name | Required | Description | Default |
|---|---|---|---|
| repository_id | Yes | ID of the repository to upload to | |
| file_path | Yes | Path to the file to upload |
Implementation Reference
- src/index.ts:134-182 (handler)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 }; } }
- src/index.ts:130-133 (schema)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 }; } } );