Skip to main content
Glama
kmexnx

Excel to PDF Converter

by kmexnx

convert_numbers_to_pdf

Convert Apple Numbers files (.numbers) to PDF format for sharing, printing, or archiving documents while preserving formatting and layout.

Instructions

Converts Apple Numbers files (.numbers) to PDF format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_pathYesRelative path to the Numbers file (.numbers) to convert
output_formatNoOutput format (currently only PDF is supported)pdf

Implementation Reference

  • The handler function that performs the actual tool logic: argument validation, LibreOffice check, file reading, conversion to PDF using libreoffice-convert, temp file creation, and response with output path.
    export const handleConvertNumbersFunc = async (
      args: unknown
    ): Promise<{ content: { type: string; text: string }[] }> => {
      // Ensure LibreOffice is installed - reuse function from convertExcel.ts
      const libreOfficeInstalled = await checkLibreOfficeInstalled();
      if (!libreOfficeInstalled) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          'LibreOffice is not installed or not found in PATH. Please install LibreOffice to use this tool.'
        );
      }
    
      // Parse and validate arguments
      let parsedArgs: ConvertNumbersArgs;
      try {
        parsedArgs = ConvertNumbersArgsSchema.parse(args);
      } catch (error) {
        if (error instanceof z.ZodError) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Invalid arguments: ${error.errors.map(e => `${e.path.join('.')} (${e.message})`).join(', ')}`
          );
        }
        const message = error instanceof Error ? error.message : String(error);
        throw new McpError(ErrorCode.InvalidParams, `Argument validation failed: ${message}`);
      }
    
      try {
        // Ensure temp directory exists - now await because the function is async
        const tempDir = await ensureTempDir();
        
        // Resolve input path
        const inputPath = resolvePath(parsedArgs.input_path);
        
        // Check file extension
        const ext = path.extname(inputPath).toLowerCase();
        if (ext !== '.numbers') {
          throw new McpError(
            ErrorCode.InvalidParams,
            'Invalid file format. Only .numbers files are supported.'
          );
        }
        
        // Read the input file
        const fileContent = await fs.readFile(inputPath);
        
        // Create output path
        const outputPath = createTempFilePath(path.basename(inputPath));
        await fs.mkdir(path.dirname(outputPath), { recursive: true });
        
        // Convert to PDF
        const pdfBuffer = await libreConvert(fileContent, '.pdf', undefined);
        
        // Write the output file
        await fs.writeFile(outputPath, pdfBuffer);
        
        // Create a relative path for the result
        const relativeOutputPath = path.relative(process.cwd(), outputPath);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                output_path: relativeOutputPath,
                message: 'Numbers file successfully converted to PDF',
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error('[Excel to PDF MCP] Error in conversion:', error);
        
        // Handle specific errors
        if (error instanceof McpError) {
          throw error; // Re-throw MCP errors
        }
        
        if (error instanceof Error) {
          if ('code' in error && error.code === 'ENOENT') {
            throw new McpError(ErrorCode.InvalidParams, `File not found: ${parsedArgs.input_path}`);
          }
          
          throw new McpError(
            ErrorCode.InvalidRequest,
            `Error converting Numbers to PDF: ${error.message}`
          );
        }
        
        // Generic error
        throw new McpError(
          ErrorCode.InvalidRequest,
          `Unknown error during Numbers to PDF conversion`
        );
      }
    };
  • Zod schema defining the input parameters for the tool: input_path (string) and output_format (enum 'pdf').
    const ConvertNumbersArgsSchema = z.object({
      input_path: z.string().min(1).describe('Relative path to the Numbers file (.numbers) to convert'),
      output_format: z.enum(['pdf']).default('pdf').describe('Output format (currently only PDF is supported)')
    }).strict();
  • The tool definition object that registers the tool name, description, schema, and handler function.
    export const convertNumbersToolDefinition: ToolDefinition = {
      name: 'convert_numbers_to_pdf',
      description: 'Converts Apple Numbers files (.numbers) to PDF format',
      schema: ConvertNumbersArgsSchema,
      handler: handleConvertNumbersFunc,
    };
  • Central registration where convert_numbers_to_pdf tool is included in the array of all tool definitions.
    export const allToolDefinitions: ToolDefinition[] = [
      convertExcelToolDefinition,
      convertNumbersToolDefinition
    ];
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Converts' implies a transformation operation, it doesn't specify whether this is a read-only conversion or modifies files, what permissions are needed, how errors are handled, or what the output looks like (e.g., file location, format details). The description lacks critical behavioral context for a file conversion tool.

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 a single, clear sentence with zero wasted words. It's front-loaded with the core purpose and efficiently specifies the input format (.numbers) and output format (PDF). Every part of the sentence earns its place by conveying essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (file conversion with 2 parameters) and lack of annotations or output schema, the description is minimally adequate. It states what the tool does but omits behavioral details, usage guidelines, and output information. It's complete enough to understand the basic function but leaves significant gaps for effective agent use.

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 description coverage is 100%, so the schema fully documents both parameters (input_path and output_format). The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain path requirements, format constraints, or usage examples. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

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?

The description clearly states the tool's purpose with a specific verb ('Converts') and resource ('Apple Numbers files (.numbers) to PDF format'), making it immediately understandable. However, it doesn't explicitly differentiate from its sibling tool 'convert_excel_to_pdf', which handles a different file format but performs a similar conversion function.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'convert_excel_to_pdf' or clarify that this tool is specifically for Numbers files, not other spreadsheet formats. There's no context about prerequisites, error conditions, or typical use cases.

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/kmexnx/excel-to-pdf-mcp'

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