-
Notifications
You must be signed in to change notification settings - Fork 157
feat: add format_cells tool for cell formatting #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
|
This looks super useful, any change of this getting tested/merged? |
There was a problem hiding this 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 |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
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).
| # 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) |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
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.
| [tool.uv-dynamic-versioning] | ||
| pattern = "default" | ||
| strict = true | ||
| strict = false |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
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.
| strict = false | |
| strict = true |
| # 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 |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
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.
| 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} |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
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}}
| 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. |
Summary
This PR adds a new
format_cellstool to the MCP server that enables comprehensive cell formatting in Google Sheets.Features Added
Changes
format_cells()function insrc/mcp_google_sheets/server.py(121 lines)Usage Examples
Test plan