Skip to main content
Glama

Upload File Attachment

upload_file

Attach files to MantisBT issues by uploading local files or providing Base64-encoded content with optional MIME type specification.

Instructions

Upload a file as an attachment to a MantisBT issue via multipart/form-data.

Two input modes (exactly one must be provided):

  • file_path: absolute path to a local file — filename is derived from the path automatically

  • content: Base64-encoded file content — filename must be supplied explicitly via the filename parameter

The optional content_type parameter sets the MIME type (e.g. "image/png"). If omitted, "application/octet-stream" is used.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that performs the file upload logic, processing the input parameters and interacting with the MantisClient to upload the file.
      async ({ issue_id, file_path, content, filename, content_type, description }) => {
        try {
          if (!file_path && !content) {
            return { content: [{ type: 'text', text: 'Error: Either file_path or content must be provided' }], isError: true };
          }
          if (file_path && content) {
            return { content: [{ type: 'text', text: 'Error: Only one of file_path or content may be provided' }], isError: true };
          }
    
          let fileBuffer: Buffer;
          let fileName: string;
    
          if (file_path) {
            if (normalizedUploadDir) {
              const normalizedPath = resolve(file_path);
              if (!normalizedPath.startsWith(normalizedUploadDir)) {
                return { content: [{ type: 'text', text: errorText('file_path is not allowed — access restricted to the designated upload directory') }], isError: true };
              }
            }
            fileBuffer = await readFile(file_path);
            fileName = filename ?? basename(file_path);
          } else {
            if (!filename) {
              return { content: [{ type: 'text', text: 'Error: filename is required when using content' }], isError: true };
            }
            fileBuffer = Buffer.from(content!, 'base64');
            fileName = filename;
          }
    
          const blob = new Blob([new Uint8Array(fileBuffer)], { type: content_type ?? 'application/octet-stream' });
          const formData = new FormData();
          formData.append('file', blob, fileName);
          if (description) {
            formData.append('description', description);
          }
          const result = await client.postFormData<unknown>(`issues/${issue_id}/files`, formData);
          return {
            content: [{ type: 'text', text: JSON.stringify(result ?? { success: true }, null, 2) }],
          };
        } catch (error) {
          const msg = error instanceof Error ? error.message : String(error);
          return { content: [{ type: 'text', text: errorText(msg) }], isError: true };
        }
      }
    );
  • The input validation schema for the upload_file tool using Zod, including custom validation to ensure only one of file_path or content is provided.
    inputSchema: z.object({
      issue_id: z.coerce.number().int().positive().describe('Numeric issue ID'),
      file_path: z.string().min(1).optional().describe('Absolute path to the local file to upload (mutually exclusive with content)'),
      content: z.string().min(1).optional().describe('Base64-encoded file content (mutually exclusive with file_path)'),
      filename: z.string().min(1).optional().describe('File name for the attachment (required when using content; overrides the derived name when using file_path)'),
      content_type: z.string().optional().describe('MIME type of the file, e.g. "image/png" (default: "application/octet-stream")'),
      description: z.string().optional().describe('Optional description for the attachment'),
    }).refine(d => !!(d.file_path ?? d.content), {
      message: 'Either file_path or content must be provided',
    }).refine(d => !(d.file_path && d.content), {
      message: 'Only one of file_path or content may be provided',
    }).refine(d => !d.content || !!d.filename, {
      message: 'filename is required when using content',
    }),
  • The registration of the upload_file tool in the McpServer.
      server.registerTool(
        'upload_file',
        {
          title: 'Upload File Attachment',
          description: `Upload a file as an attachment to a MantisBT issue via multipart/form-data.
    
    Two input modes (exactly one must be provided):
    - file_path: absolute path to a local file — filename is derived from the path automatically
    - content: Base64-encoded file content — filename must be supplied explicitly via the filename parameter
    
    The optional content_type parameter sets the MIME type (e.g. "image/png"). If omitted, "application/octet-stream" is used.`,
          inputSchema: z.object({
            issue_id: z.coerce.number().int().positive().describe('Numeric issue ID'),
            file_path: z.string().min(1).optional().describe('Absolute path to the local file to upload (mutually exclusive with content)'),
            content: z.string().min(1).optional().describe('Base64-encoded file content (mutually exclusive with file_path)'),
            filename: z.string().min(1).optional().describe('File name for the attachment (required when using content; overrides the derived name when using file_path)'),
            content_type: z.string().optional().describe('MIME type of the file, e.g. "image/png" (default: "application/octet-stream")'),
            description: z.string().optional().describe('Optional description for the attachment'),
          }).refine(d => !!(d.file_path ?? d.content), {
            message: 'Either file_path or content must be provided',
          }).refine(d => !(d.file_path && d.content), {
            message: 'Only one of file_path or content may be provided',
          }).refine(d => !d.content || !!d.filename, {
            message: 'filename is required when using content',
          }),
          annotations: {
            readOnlyHint: false,
            destructiveHint: false,
            idempotentHint: false,
          },
        },
        async ({ issue_id, file_path, content, filename, content_type, description }) => {
          try {
            if (!file_path && !content) {
              return { content: [{ type: 'text', text: 'Error: Either file_path or content must be provided' }], isError: true };
            }
            if (file_path && content) {
              return { content: [{ type: 'text', text: 'Error: Only one of file_path or content may be provided' }], isError: true };
            }
    
            let fileBuffer: Buffer;
            let fileName: string;
    
            if (file_path) {
              if (normalizedUploadDir) {
                const normalizedPath = resolve(file_path);
                if (!normalizedPath.startsWith(normalizedUploadDir)) {
                  return { content: [{ type: 'text', text: errorText('file_path is not allowed — access restricted to the designated upload directory') }], isError: true };
                }
              }
              fileBuffer = await readFile(file_path);
              fileName = filename ?? basename(file_path);
            } else {
              if (!filename) {
                return { content: [{ type: 'text', text: 'Error: filename is required when using content' }], isError: true };
              }
              fileBuffer = Buffer.from(content!, 'base64');
              fileName = filename;
            }
    
            const blob = new Blob([new Uint8Array(fileBuffer)], { type: content_type ?? 'application/octet-stream' });
            const formData = new FormData();
            formData.append('file', blob, fileName);
            if (description) {
              formData.append('description', description);
            }
            const result = await client.postFormData<unknown>(`issues/${issue_id}/files`, formData);
            return {
              content: [{ type: 'text', text: JSON.stringify(result ?? { success: true }, null, 2) }],
            };
          } catch (error) {
            const msg = error instanceof Error ? error.message : String(error);
            return { content: [{ type: 'text', text: errorText(msg) }], isError: true };
          }
        }
      );
Behavior3/5

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

With annotations already declaring readOnlyHint=false and destructiveHint=false, the description adds valuable behavioral context including the multipart/form-data transport, default MIME type behavior ('application/octet-stream'), and filename derivation logic. However, it omits discussion of side effects (e.g., notifications triggered), rate limits, or failure modes.

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?

The description is optimally structured with the purpose front-loaded, followed by clearly demarcated input modes with bullet points, and finishing with optional parameter details. Every sentence conveys essential information without redundancy.

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?

Despite the detailed conceptual explanation of upload modes, the tool definition is critically incomplete due to the empty input schema. The description references parameters that do not exist in the schema, preventing correct agent invocation. Without an output schema, the description also fails to mention return values or error conditions.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

While the description provides rich semantic detail for four parameters (file_path, content, filename, content_type) including format expectations and dependencies, the input schema is completely empty (zero properties). This creates a critical disconnect where the agent cannot determine the actual JSON structure or parameter types for invocation.

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?

The description clearly states the specific action ('Upload a file'), resource type ('attachment to a MantisBT issue'), and transport mechanism ('via multipart/form-data'). It effectively distinguishes this from sibling tools like create_issue or add_note by specifying the attachment context.

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?

The description provides clear internal usage guidelines by defining two mutually exclusive input modes ('exactly one must be provided') and explaining the conditional requirement for the filename parameter ('must be supplied explicitly via the filename parameter' when using content mode). However, it lacks explicit comparison to sibling alternatives.

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/dpesch/mantisbt-mcp-server'

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