Skip to content

Conversation

@dsuarezf
Copy link

Summary

This PR adds a new format_cells tool to the MCP server that enables comprehensive cell formatting in Google Sheets.

Features Added

  • Number Formatting: Support for currency, percent, date, time, and custom number formats
  • Background Colors: Apply RGB colors (0-1 range) to cell backgrounds
  • Text Formatting: Control bold, italic, font size, foreground color, and more
  • Alignment: Set horizontal alignment (left, center, right)

Changes

  • Added format_cells() function in src/mcp_google_sheets/server.py (121 lines)
  • Updated README.md with tool documentation and example prompts
  • Updated pyproject.toml version

Usage Examples

"Format cells A1:E1 in Sheet1 with orange background, bold black text."
"Apply currency formatting to cells E2:E10 in the 'Sales' sheet."
"Center align the text in cells B1:D1 and make them bold."

Test plan

  • Test number formatting with different format types (currency, percent, date)
  • Test background color application
  • Test text formatting (bold, italic, font size)
  • Test horizontal alignment options
  • Verify A1 notation parsing for single cells and ranges

Added a new MCP tool that enables formatting of spreadsheet cells including:
- Number formats (currency, percent, date, time, etc.)
- Background colors (RGB with 0-1 range)
- Text formatting (bold, italic, font size, foreground color)
- Horizontal alignment (left, center, right)

Updated documentation with:
- Tool description and parameters in Available Tools section
- New feature highlight in Key Features
- Example prompts demonstrating cell formatting usage
@slhck
Copy link
Contributor

slhck commented Nov 21, 2025

This looks super useful, any change of this getting tested/merged?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive cell formatting capabilities to the Google Sheets MCP server through a new format_cells tool. The implementation enables users to apply number formats, colors, text styles, and alignment to spreadsheet cells using natural language prompts.

Key Changes

  • New format_cells() function with support for number formatting (currency, percent, date, etc.), background colors, text formatting (bold, italic, font size, foreground color), and horizontal alignment
  • A1 notation parser for cell range handling (e.g., 'A1:C10', 'E17')
  • Documentation updates with tool reference and usage examples

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/mcp_google_sheets/server.py Implements the format_cells() function (121 lines) with A1 range parsing, Google Sheets API integration via repeatCell request, and format option handling
README.md Adds documentation for the new tool in the tools list and provides three example prompts demonstrating formatting use cases
pyproject.toml Changes dynamic versioning from strict to non-strict mode (unrelated to feature)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Parse A1 notation to get row/column indices
# Simple parser for ranges like 'A1', 'A1:B2', 'E17', etc.
import re
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import re statement should be moved to the top of the file with other imports (around line 1-25). Local imports within functions are generally discouraged unless there's a specific reason (e.g., optional dependencies, circular imports).

Copilot uses AI. Check for mistakes.
# Parse A1 notation to get row/column indices
# Simple parser for ranges like 'A1', 'A1:B2', 'E17', etc.
import re
match = re.match(r'([A-Z]+)(\d+)(?::([A-Z]+)(\d+))?', range)
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern doesn't account for lowercase column letters. Google Sheets A1 notation can be case-insensitive in practice. Consider using r'([A-Za-z]+)(\d+)(?::([A-Za-z]+)(\d+))?' and converting to uppercase, or add the re.IGNORECASE flag.

Copilot uses AI. Check for mistakes.
[tool.uv-dynamic-versioning]
pattern = "default"
strict = true
strict = false
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change from strict = true to strict = false appears unrelated to the cell formatting feature. Consider removing this change or documenting the reason for it in the PR description. Disabling strict mode for dynamic versioning can allow version tag mismatches to pass silently.

Suggested change
strict = false
strict = true

Copilot uses AI. Check for mistakes.
Comment on lines +974 to +996
# Parse A1 notation to get row/column indices
# Simple parser for ranges like 'A1', 'A1:B2', 'E17', etc.
import re
match = re.match(r'([A-Z]+)(\d+)(?::([A-Z]+)(\d+))?', range)
if not match:
return {"error": f"Invalid range format: {range}"}

def col_to_index(col: str) -> int:
"""Convert column letter to 0-based index"""
result = 0
for char in col:
result = result * 26 + (ord(char) - ord('A') + 1)
return result - 1

start_col = col_to_index(match.group(1))
start_row = int(match.group(2)) - 1

if match.group(3) and match.group(4):
end_col = col_to_index(match.group(3)) + 1
end_row = int(match.group(4))
else:
end_col = start_col + 1
end_row = start_row + 1
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the A1 notation parsing logic (lines 974-996) into a separate module-level helper function. This would make it reusable for other tools that might need to parse A1 ranges in the future and easier to test independently.

Copilot uses AI. Check for mistakes.
background_color: Optional background color with 'red', 'green', 'blue' keys (0-1 range).
Example: {'red': 1, 'green': 1, 'blue': 1} for white
text_format: Optional text format with keys like 'bold', 'italic', 'fontSize', etc.
Example: {'bold': True, 'fontSize': 11}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing more specific documentation for the text_format parameter. For example, mention that foregroundColor should be an object with red, green, blue keys (0-1 range), similar to background_color. Example: {'bold': True, 'fontSize': 11, 'foregroundColor': {'red': 0, 'green': 0, 'blue': 0}}

Suggested change
Example: {'bold': True, 'fontSize': 11}
You can specify text color using the 'foregroundColor' key, which should be an object with 'red', 'green', 'blue' keys (0-1 range), similar to background_color.
Example: {'bold': True, 'fontSize': 11, 'foregroundColor': {'red': 0, 'green': 0, 'blue': 0}} for black text.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants