Skip to main content
Glama

Upload Blob

upload_blob

Upload files or blobs to AFFiNE workspace storage by providing workspace ID and base64-encoded content.

Instructions

Upload a file or blob to workspace storage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspaceIdYesWorkspace ID
contentYesBase64 encoded content or text
filenameNoFilename
contentTypeNoMIME type

Implementation Reference

  • The uploadBlobHandler function that executes the upload_blob tool logic. It accepts workspaceId, content (base64 or text), filename, and contentType, then performs a multipart/form-data GraphQL mutation upload (setBlob) to the endpoint.
    const uploadBlobHandler = async ({ workspaceId, content, filename, contentType }: { workspaceId: string; content: string; filename?: string; contentType?: string }) => {
      try {
        const endpoint = gql.endpoint;
        const headers = gql.headers;
        const cookie = gql.cookie;
        const payload = decodeBlobContent(content);
        const safeFilename = filename || `blob-${Date.now()}.bin`;
        const mime = contentType || "application/octet-stream";
    
        const form = new FormData();
        form.append("operations", JSON.stringify({
          query: `mutation SetBlob($workspaceId: String!, $blob: Upload!) {
            setBlob(workspaceId: $workspaceId, blob: $blob)
          }`,
          variables: {
            workspaceId,
            blob: null
          }
        }));
        form.append("map", JSON.stringify({ "0": ["variables.blob"] }));
        form.append("0", payload, { filename: safeFilename, contentType: mime });
    
        const response = await fetch(endpoint, {
          method: "POST",
          headers: {
            ...headers,
            Cookie: cookie,
            ...form.getHeaders(),
          },
          body: form as any,
        });
        const result = await response.json() as any;
        if (result.errors?.length) {
          throw new Error(result.errors[0].message);
        }
        const blobKey = result.data?.setBlob;
        if (!blobKey) {
          throw new Error("Upload succeeded but no blob key was returned.");
        }
    
        return text({
          id: blobKey,
          key: blobKey,
          workspaceId,
          filename: safeFilename,
          contentType: mime,
          size: payload.length,
          uploadedAt: new Date().toISOString()
        });
      } catch (error: any) {
        return text({ error: error.message });
      }
    };
  • Registration of upload_blob tool with input schema: workspaceId (string), content (string/base64), filename (optional string), contentType (optional string).
    "upload_blob",
    {
      title: "Upload Blob",
      description: "Upload a file or blob to workspace storage.",
      inputSchema: {
        workspaceId: z.string().describe("Workspace ID"),
        content: z.string().describe("Base64 encoded content or text"),
        filename: z.string().optional().describe("Filename"),
        contentType: z.string().optional().describe("MIME type")
      }
  • The server.registerTool('upload_blob', ...) call that registers the tool with the MCP server.
    server.registerTool(
      "upload_blob",
      {
        title: "Upload Blob",
        description: "Upload a file or blob to workspace storage.",
        inputSchema: {
          workspaceId: z.string().describe("Workspace ID"),
          content: z.string().describe("Base64 encoded content or text"),
          filename: z.string().optional().describe("Filename"),
          contentType: z.string().optional().describe("MIME type")
        }
      },
      uploadBlobHandler as any
    );
  • Helper function decodeBlobContent that tries to decode the content as base64, falling back to UTF-8 text.
    function decodeBlobContent(content: string): Buffer {
      const normalized = content.trim().replace(/\s+/g, "");
      const base64Like = normalized.length > 0 && normalized.length % 4 === 0 && /^[A-Za-z0-9+/=]+$/.test(normalized);
      if (base64Like) {
        try {
          const decoded = Buffer.from(normalized, "base64");
          if (decoded.length > 0) {
            return decoded;
          }
        } catch {
          // Fallback to UTF-8 text below.
        }
      }
      return Buffer.from(content, "utf8");
    }
  • Permission/group configuration mapping upload_blob to ['blobs', 'blobs.write', 'write'] scopes.
      upload_blob: ["blobs", "blobs.write", "write"],
    };
Behavior2/5

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

No annotations provided, so description must carry full burden. Only states 'upload' without disclosing behavioral traits like file overwrite behavior, size limits, or repercussions. Inadequate for a mutation operation.

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?

Single sentence with no wasted words. Appropriately sized for the tool's simplicity.

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?

No output schema provided, and description does not explain return values or side effects. Lacks information about result (e.g., blob ID) and does not mention any constraints or prerequisites.

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 coverage is 100%, so baseline is 3. Description adds no extra meaning beyond schema parameter descriptions.

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?

Description clearly states the action (upload) and target (file/blob to workspace storage). However, it doesn't explicitly differentiate from sibling tools like delete_blob or cleanup_blobs, but the purpose is distinct enough.

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?

No guidance on when to use this tool vs alternatives. There are no other upload sibling tools, but the description does not mention prerequisites or context for 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/DAWNCR0W/affine-mcp-server'

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