Skip to main content
Glama

upload_media

Upload a local file to get a media key. Automatically detects content type, obtains a signed URL, and returns the media key and type for post creation.

Instructions

Upload a local file to PostFast and get back a media key for use in create_posts. Handles the full flow: detects content type, gets a signed URL, uploads the file, and returns the key and type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the local file (e.g. /Users/me/photo.jpg)

Implementation Reference

  • The upload_media tool handler: reads a local file, detects content type, gets a signed upload URL from PostFast API, PUTs the file to that URL, and returns the media key, type (VIDEO/IMAGE), and content type.
    server.tool(
      'upload_media',
      'Upload a local file to PostFast and get back a media key for use in create_posts. Handles the full flow: detects content type, gets a signed URL, uploads the file, and returns the key and type.',
      {
        filePath: z
          .string()
          .describe(
            'Absolute path to the local file (e.g. /Users/me/photo.jpg)',
          ),
      },
      async (input) => {
        const contentType = detectContentType(input.filePath);
        const isVideo = contentType.startsWith('video/');
    
        const [uploadUrl] = await client.post<SignedUploadUrl[]>(
          '/file/get-signed-upload-urls',
          { contentType, count: 1 },
        );
    
        const fileBuffer = await readFile(input.filePath);
    
        const uploadResponse = await fetch(uploadUrl.signedUrl, {
          method: 'PUT',
          headers: { 'Content-Type': contentType },
          body: fileBuffer,
        });
    
        if (!uploadResponse.ok) {
          throw new Error(
            `Upload failed (${uploadResponse.status}): ${await uploadResponse.text()}`,
          );
        }
    
        const result = {
          key: uploadUrl.key,
          type: isVideo ? 'VIDEO' : 'IMAGE',
          contentType,
        };
    
        return {
          content: [
            { type: 'text' as const, text: JSON.stringify(result, null, 2) },
          ],
        };
      },
    );
  • Input schema for upload_media: requires a single string filePath parameter validated with Zod, described as absolute path to a local file.
    {
      filePath: z
        .string()
        .describe(
          'Absolute path to the local file (e.g. /Users/me/photo.jpg)',
        ),
    },
  • Tool registration via server.tool() in the registerFileTools function, which is called from src/index.ts.
    server.tool(
      'upload_media',
      'Upload a local file to PostFast and get back a media key for use in create_posts. Handles the full flow: detects content type, gets a signed URL, uploads the file, and returns the key and type.',
      {
        filePath: z
          .string()
          .describe(
            'Absolute path to the local file (e.g. /Users/me/photo.jpg)',
          ),
      },
      async (input) => {
        const contentType = detectContentType(input.filePath);
        const isVideo = contentType.startsWith('video/');
    
        const [uploadUrl] = await client.post<SignedUploadUrl[]>(
          '/file/get-signed-upload-urls',
          { contentType, count: 1 },
        );
    
        const fileBuffer = await readFile(input.filePath);
    
        const uploadResponse = await fetch(uploadUrl.signedUrl, {
          method: 'PUT',
          headers: { 'Content-Type': contentType },
          body: fileBuffer,
        });
    
        if (!uploadResponse.ok) {
          throw new Error(
            `Upload failed (${uploadResponse.status}): ${await uploadResponse.text()}`,
          );
        }
    
        const result = {
          key: uploadUrl.key,
          type: isVideo ? 'VIDEO' : 'IMAGE',
          contentType,
        };
    
        return {
          content: [
            { type: 'text' as const, text: JSON.stringify(result, null, 2) },
          ],
        };
      },
    );
  • Helper function detectContentType maps file extensions to MIME types (jpg/png/gif/webp/mp4/webm/mov). Used by upload_media to determine the Content-Type.
    function detectContentType(filePath: string): string {
      const ext = extname(filePath).toLowerCase();
      const mime = MIME_MAP[ext];
      if (!mime) {
        throw new Error(
          `Unsupported file extension "${ext}". Supported: ${Object.keys(MIME_MAP).join(', ')}`,
        );
      }
      return mime;
    }
Behavior4/5

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

Discloses full internal flow: content type detection, signed URL acquisition, file upload, and return of key/type. No annotations provided, so description carries burden well.

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?

Two sentences, no wasted words. First sentence states purpose, second explains process. Efficient and front-loaded.

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?

Covers purpose, flow, and output for a simple single-parameter tool. Lacks security/error details but sufficient for typical usage given no output schema needed.

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 has 100% coverage for 'filePath'. Tool description adds behavioral context but not additional parameter details beyond what schema provides.

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?

Clearly states verb 'Upload', resource 'local file to PostFast', and purpose 'get back a media key for use in create_posts'. Distinguishes from sibling 'get_upload_urls' by describing the full upload flow.

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?

Explicitly connects to 'create_posts' workflow, indicating when to use. Lacks explicit exclusions or alternatives, but context is clear enough for typical use.

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/peturgeorgievv-factory/postfast-mcp'

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