Upload Asset
upload_assetUpload a local file as an asset by providing its absolute file path.
Instructions
Upload a local file as an asset. Provide the absolute file path.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Absolute path to the file to upload |
Implementation Reference
- src/tools/assets.ts:92-106 (handler)Handler function for the upload_asset tool. Reads the file from disk, derives filename and MIME type, then calls client.uploadFile() and returns the result.
}, async ({ file_path }) => { const fileBuffer = await readFile(file_path); const filename = basename(file_path); const mimeType = getMimeType(file_path); const result = await client.uploadFile( "/files", fileBuffer, filename, mimeType ); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }); - src/tools/assets.ts:83-91 (schema)Registration and input schema for the upload_asset tool. Defines a single required 'file_path' string parameter.
server.registerTool("upload_asset", { title: "Upload Asset", description: "Upload a local file as an asset. Provide the absolute file path.", inputSchema: { file_path: z .string() .describe("Absolute path to the file to upload"), }, - src/tools/assets.ts:83-91 (registration)Registration of the upload_asset tool on the MCP server via registerTool().
server.registerTool("upload_asset", { title: "Upload Asset", description: "Upload a local file as an asset. Provide the absolute file path.", inputSchema: { file_path: z .string() .describe("Absolute path to the file to upload"), }, - src/tools/assets.ts:31-34 (helper)Helper function that maps file extensions to MIME types, used by upload_asset to set the Content-Type.
function getMimeType(filePath: string): string { const ext = extname(filePath).toLowerCase(); return MIME_TYPES[ext] ?? "application/octet-stream"; } - src/client.ts:148-172 (helper)Helper method on ElmapiClient that performs the multipart/form-data file upload via fetch.
async uploadFile( path: string, fileBuffer: Buffer, filename: string, mimeType: string ): Promise<unknown> { const blob = new Blob([new Uint8Array(fileBuffer)], { type: mimeType }); const formData = new FormData(); formData.append("file", blob, filename); const headers: Record<string, string> = { Accept: "application/json", Authorization: `Bearer ${this.token}`, "project-id": this.projectId, // Do NOT set Content-Type — fetch sets it with the boundary automatically }; const response = await fetch(`${this.baseUrl}${path}`, { method: "POST", headers, body: formData, }); return this.handleResponse(response); }