Add border-map and compare-ranges tools | increase tests coverage#125
Conversation
Add comprehensive unit tests for many tools and utils (append-values, batch-update-values, create-chart enhancements, insert-rows edge cases, update-values fallback, google-auth, json-parser, response-helpers, validation-helpers, error-messages, and range-helpers including colIndexToLetter). Also simplify axis title assignment in create-chart and add /* v8 ignore next 3 */ hints to avoid optimizer warnings in create-chart and google-auth. These changes increase test coverage, handle several edge cases, and make minor defensive code adjustments.
Introduce two new tools to inspect formatting: sheets_get_border_map (visual border grids) and sheets_compare_ranges (cell-format diffs). Register and export the tools, and wire their handlers in src/index.ts and src/tools/index.ts. Add a new utility (src/utils/formula-locale.ts) that normalizes conditional-format formulas to English locale and integrate it into conditional-formatting and full-sheet-snapshot flows (new normalizeFormulas option for conditional format tool; includeConditionalFormatting and compactMode default changes in full-sheet-snapshot). Also adjust conditional-formatting tool to return a _formulaLocaleRaw field when normalization runs. Error handling, field filtering, and formatting outputs added for the new tools.
# Conflicts: # src/tools/get-conditional-formatting-data.ts # tests/unit/utils/range-helpers.test.ts
There was a problem hiding this comment.
Pull request overview
This PR expands the Sheets MCP server’s formatting-inspection capabilities by adding two new analysis tools (border mapping and range formatting diff), and improves conditional formatting handling via formula locale normalization. It also includes a broad set of new/expanded unit tests to raise coverage and minor refactors in chart creation.
Changes:
- Added
sheets_get_border_mapandsheets_compare_rangestools and registered them in the tool registry/exports. - Added formula locale normalization utilities and integrated them into conditional-formatting related tools/snapshots.
- Increased unit test coverage across validators, helpers, auth, formatters, and multiple tools.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/index.ts | Registers the new tools in the handler map and tool list. |
| src/tools/index.ts | Exports the new tool modules for consumption by the main index. |
| src/tools/get-border-map.ts | New tool to produce compact horizontal/vertical border line grids for a range. |
| src/tools/compare-ranges.ts | New tool to diff formatting between two same-sized ranges. |
| src/utils/formula-locale.ts | New utility to normalize Sheets formulas to comma-separated (English) locale. |
| src/tools/get-conditional-formatting-data.ts | Adds optional formula normalization and raw-formula metadata in CF output. |
| src/tools/get-full-sheet-snapshot.ts | Changes snapshot defaults (compact mode on) and adds conditional formatting inclusion toggle + normalization. |
| src/tools/create-chart.ts | Minor refactor of axis title assignment + coverage ignore annotations. |
| src/utils/google-auth.ts | Adds coverage ignore annotations for an unreachable private-key validation branch. |
| tests/unit/utils/validators.test.ts | Adds additional validator test cases for edge conditions and new validators. |
| tests/unit/utils/validation-helpers.test.ts | New tests for shared validation helper utilities (with validators mocked). |
| tests/unit/utils/response-helpers.test.ts | New tests for response helper formatting utilities. |
| tests/unit/utils/range-helpers.test.ts | Adds tests for additional edge cases and colIndexToLetter. |
| tests/unit/utils/json-parser.test.ts | New tests for JSON input parsing helper. |
| tests/unit/utils/google-auth.test.ts | New tests for auth validation and client creation/caching behavior. |
| tests/unit/utils/formatters.test.ts | Adds an edge-case test for null first-row values. |
| tests/unit/utils/error-messages.test.ts | New tests validating error message constants/factories. |
| tests/unit/tools/update-values.test.ts | Adds edge-case test for missing updatedCells. |
| tests/unit/tools/insert-rows.test.ts | Adds multiple edge-case tests around range parsing and sheet name handling. |
| tests/unit/tools/create-chart.test.ts | Adds extensive branch/edge-case coverage for chart creation. |
| tests/unit/tools/batch-update-values.test.ts | New tests for batch update values tool. |
| tests/unit/tools/append-values.test.ts | New tests for append values tool. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use extractSheetName and case-insensitive column parsing across compare-ranges and get-border-map to accept quoted sheet names and lowercase A1 refs; normalize column letters with toUpperCase and make range regex case-insensitive. Harden null/optional checks and formatting extraction (safe returns when no format). Fix border-map logic to correctly prioritize bottom/top and left/right checks and ensure encodeBorder/includeStyle handling. Also add unit tests for compare-ranges, get-border-map, and formula-locale to cover quoted sheet names, lowercase ranges, field filtering, border resolution, and formula locale normalization.
Minor formatting updates across three files: aligned multiline destructuring in src/tools/compare-ranges.ts, normalized inline comment spacing for endRow in src/tools/compare-ranges.ts and src/tools/get-border-map.ts, and collapsed the function signature onto one line in src/utils/formula-locale.ts. No functional changes; purely readability/formatting cleanup.
Change compactMode default to false and update docs and behavior accordingly. The input schema and help text now state that full per-cell formatting is returned by default and compactMode:true enables run-length encoded collapsing. Introduce a local `compact` boolean (compactMode === true) and use it in conditional logic and in the returned formatting payload to normalize handling of the flag. Notes that compacting only applies when includeFormattingRange is set.
Update package.json version from 1.7.1 to 1.7.2 to prepare a patch release. No other changes were made in this commit.
|
@freema In this PR I have added border-map and compare-ranges tools. I also increased tests coverage. |
|
Hi Marcin, thank you so much for this great contribution! 🧙♂️ The two new tools are genuinely useful — The test coverage bump is also a huge win — google-auth, validation-helpers, response-helpers, formula-locale, plus edge cases for append/batch-update/create-chart/insert-rows. That's exactly the kind of foundation work that pays dividends over time. The coverage chart went from "we have tests" to "we HAVE tests" 📈. Merging now and shipping as part of v1.8.0. I'll follow up with a small cleanup commit in main (tightening the Thanks again for the effort and care! 🚀 |
Ship the merged contributions from #125 and #126 as 1.8.0: - delete-columns / delete-rows tools (#126, @master-nevi) - border-map / compare-ranges tools + locale normalization + coverage (#125, @marcin-uliasz) Cleanup: - Remove unused `mode` parameter from sheets_compare_ranges schema (the tool always compared position-by-position — kept doc honest) - Bump server version string in src/index.ts to match package version
After working with this MCP Server there was a need to create two additional tools: border-map & compare-ranges for AI Agent to better understand the Google Spreadsheet it was analysing.
I also increased tests coverage:
Detailed summary of changes in PR: