Skip to main content
Glama

upload_file

Transfer files such as images and documents to the Emlog blog system via API, specifying the file path and resource category ID for efficient content management.

Instructions

Upload a file (image, document, etc.)

Input Schema

NameRequiredDescriptionDefault
file_pathYesLocal path to the file to upload
sidNoResource category ID

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "file_path": { "description": "Local path to the file to upload", "type": "string" }, "sid": { "description": "Resource category ID", "type": "number" } }, "required": [ "file_path" ], "type": "object" }

Implementation Reference

  • MCP tool handler for 'upload_file' that invokes emlogClient.uploadFile and formats the response or error.
    async ({ file_path, sid }) => { try { const result = await emlogClient.uploadFile(file_path, sid); return { content: [{ type: "text", text: `Successfully uploaded file: ${result.url}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • Input schema using Zod for validating tool parameters: file_path (required string) and sid (optional number).
    inputSchema: { file_path: z.string().describe("Local path to the file to upload"), sid: z.number().optional().describe("Resource category ID") }
  • src/index.ts:513-542 (registration)
    Registration of the 'upload_file' tool with server.registerTool, including title, description, schema, and handler.
    server.registerTool( "upload_file", { title: "Upload File", description: "Upload a file (image, document, etc.)", inputSchema: { file_path: z.string().describe("Local path to the file to upload"), sid: z.number().optional().describe("Resource category ID") } }, async ({ file_path, sid }) => { try { const result = await emlogClient.uploadFile(file_path, sid); return { content: [{ type: "text", text: `Successfully uploaded file: ${result.url}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Core file upload logic in EmlogClient class: checks file existence, prepares FormData, posts to API, returns media object.
    async uploadFile(filePath: string, sid?: number): Promise<EmlogMedia> { if (!fs.existsSync(filePath)) { throw new Error(`File not found: ${filePath}`); } const formData = new FormData(); formData.append('file', fs.createReadStream(filePath)); if (sid) formData.append('sid', String(sid)); formData.append('api_key', this.apiKey); const response = await this.api.post('/?rest-api=upload', formData, { headers: { ...formData.getHeaders() } }); return response.data.data; }

Other Tools

Related 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/eraincc/emlog-mcp'

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