Skip to main content
Glama

format_cell

Set cell formatting in Excel files, including font styles, fill colors, and borders, for precise customization of spreadsheets.

Instructions

セルの書式(フォント、塗りつぶし、罫線)を設定します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cellYesセル位置(例: A1)
filePathYesExcelファイルのパス
formatYesセルの書式設定
sheetNameYesワークシート名

Implementation Reference

  • The core handler function that loads the Excel workbook, retrieves the worksheet and cell, applies font, fill, and border formatting using ExcelJS, saves the file, and returns a success message.
    async function formatCell(filePath: string, sheetName: string, cell: string, format: any): Promise<string> {
      try {
        const workbook = await loadWorkbook(filePath);
        const worksheet = workbook.getWorksheet(sheetName);
        if (!worksheet) {
          throw new Error(`ワークシート '${sheetName}' が見つかりません。`);
        }
        
        const targetCell = worksheet.getCell(cell);
        
        // フォント設定
        if (format.font) {
          const fontFormat: any = {};
          if (format.font.bold !== undefined) fontFormat.bold = format.font.bold;
          if (format.font.size) fontFormat.size = format.font.size;
          if (format.font.color) {
            fontFormat.color = { argb: format.font.color };
          }
          targetCell.font = fontFormat;
        }
        
        // 背景色設定
        if (format.fill) {
          if (format.fill.type === 'pattern') {
            const fillFormat: any = {
              type: 'pattern',
              pattern: format.fill.pattern || 'solid'
            };
            if (format.fill.fgColor) {
              fillFormat.fgColor = { argb: format.fill.fgColor };
            }
            if (format.fill.bgColor) {
              fillFormat.bgColor = { argb: format.fill.bgColor };
            }
            targetCell.fill = fillFormat;
          } else {
            // 簡単な背景色設定
            targetCell.fill = {
              type: 'pattern',
              pattern: 'solid',
              fgColor: { argb: format.fill.fgColor || format.fill }
            };
          }
        }
        
        // 罫線設定
        if (format.border) {
          targetCell.border = format.border;
        }
        
        await workbook.xlsx.writeFile(filePath);
        
        return `セル ${cell} の書式を設定しました。`;
      } catch (error) {
        throw new McpError(ErrorCode.InternalError, `セル書式設定エラー: ${error}`);
      }
    }
  • Zod schema defining the input structure for the format_cell tool, including filePath, sheetName, cell, and detailed format options for font, fill, and border.
    const FormatCellSchema = z.object({
      filePath: z.string().describe("Excelファイルのパス"),
      sheetName: z.string().describe("ワークシート名"),
      cell: z.string().describe("セル位置(例: A1)"),
      format: z.object({
        font: z.object({
          bold: z.boolean().optional().describe("太字設定"),
          italic: z.boolean().optional().describe("斜体設定"),
          size: z.number().optional().describe("フォントサイズ"),
          color: z.string().optional().describe("フォント色(ARGB形式)"),
        }).optional().describe("フォント設定"),
        fill: z.object({
          type: z.literal("pattern").describe("塗りつぶしタイプ"),
          pattern: z.string().describe("パターン(solid等)"),
          fgColor: z.string().describe("前景色(ARGB形式)"),
        }).optional().describe("塗りつぶし設定"),
        border: z.object({
          top: z.object({ style: z.string(), color: z.string() }).optional(),
          left: z.object({ style: z.string(), color: z.string() }).optional(),
          bottom: z.object({ style: z.string(), color: z.string() }).optional(),
          right: z.object({ style: z.string(), color: z.string() }).optional(),
        }).optional().describe("罫線設定"),
      }).describe("セルの書式設定"),
    });
  • src/index.ts:501-505 (registration)
    Tool registration in the ListTools response, providing name, description, and input schema reference.
    {
      name: "format_cell",
      description: "セルの書式(フォント、塗りつぶし、罫線)を設定します",
      inputSchema: zodToJsonSchema(FormatCellSchema)
    },
  • src/index.ts:555-558 (registration)
    Wrapper function in the toolImplementations map that parses input arguments using the schema and delegates to the formatCell handler. Used by the CallToolRequestSchema handler.
    format_cell: async (args: any) => {
      const { filePath, sheetName, cell, format } = FormatCellSchema.parse(args);
      return await formatCell(filePath, sheetName, cell, format);
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While '設定します' implies a write/mutation operation, the description doesn't clarify whether this overwrites existing formatting, requires file write permissions, has side effects on other cells, or provides any confirmation/error response. For a mutation tool with complex nested parameters, this leaves significant behavioral gaps.

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, efficient Japanese sentence that directly states the tool's purpose with zero wasted words. It's appropriately sized for a formatting tool and front-loads the essential information (what formatting aspects are supported). Every word earns its place.

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?

For a mutation tool with complex nested parameters (4 params with deep nesting) and no annotations or output schema, the description is insufficient. It doesn't address behavioral aspects like error conditions, permission requirements, or what happens on success/failure. The agent must rely entirely on the input schema for operational details, which is risky for a write operation.

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 already documents all 4 parameters thoroughly. The description mentions the three formatting aspects (font, fill, border) which map to the 'format' parameter's structure, but adds no additional semantic context beyond what's in the schema descriptions. This meets the baseline for high schema coverage.

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 action ('設定します' - sets/configure) and the resource ('セルの書式' - cell formatting), specifying the three formatting aspects (font, fill, border). It distinguishes this tool from sibling tools like 'set_cell_value' or 'set_range_values' which handle content rather than formatting. However, it doesn't explicitly differentiate from potential formatting alternatives that might exist.

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 prerequisites (like needing an existing workbook), compare with sibling tools like 'set_range_values' for bulk formatting, or indicate when formatting vs content-setting tools are appropriate. The agent must infer usage from the tool name and parameters alone.

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

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/SuperPyonchiX/excel_mcp_server'

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