Skip to content

feat: add pcm_update_save tool for writing changes to a new .cdb file - #15

Merged
mpicciolli merged 8 commits into
mainfrom
feat/pcm-update-save
Jul 2, 2026
Merged

feat: add pcm_update_save tool for writing changes to a new .cdb file#15
mpicciolli merged 8 commits into
mainfrom
feat/pcm-update-save

Conversation

@mpicciolli

@mpicciolli mpicciolli commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a new pcm_update_save MCP tool that runs a single write statement (INSERT/UPDATE/DELETE) against a Pro Cycling Manager .cdb save and serializes the result to a new .cdb file. The source save is never modified.

What's new

  • pcm_update_save tool (src/tools/update-save.ts) — executes exactly one data-mutating statement and writes the edited database to outputPath (which must differ from savePath). Returns outputPath, rowsModified, and the normalized statement. SELECT, DDL (DROP/CREATE/ALTER), and stacked statements are rejected.
  • Write path in save-db.tswithSaveDb gains an opt-in { queryOnly: false } config; a new writeSaveDb helper re-encodes the sql.js database to PCM's compressed .cdb format via sqlToCdb and refuses to overwrite the source save.
  • Shared SQL helpers (src/helpers.ts) — extracted parseSingleStatement (statement normalization + single-statement enforcement using sql-query-identifier, so a ; inside a string literal isn't mistaken for a separator) and explainQueryError (actionable messages for missing table/column and read-only violations). Both are now shared by the read and write tools, and pcm_query_save was refactored to reuse them.

Safety

  • The source .cdb is only ever read; writes always go to a separate output file.
  • writeSaveDb throws if outputPath isn't a .cdb or resolves to the source path.
  • Only a single INSERT/UPDATE/DELETE is allowed — schema changes are blocked to keep the sqlToCdb round-trip intact.

Copilot AI review requested due to automatic review settings July 2, 2026 22:39

Copilot AI left a comment

Copy link
Copy Markdown

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 introduces the first write-capable MCP tool in the repo (pcm_update_save) to apply a single INSERT/UPDATE/DELETE to an in-memory PCM save DB and serialize the result to a separate .cdb file, while refactoring shared SQL parsing/error-mapping helpers and updating documentation accordingly.

Changes:

  • Added pcm_update_save tool with single-statement write enforcement and output serialization.
  • Refactored pcm_query_save to reuse shared parseSingleStatement + explainQueryError helpers.
  • Extended withSaveDb with an opt-in write mode and added writeSaveDb, plus added vitest coverage and README updates.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/tools/update-save.test.ts Adds vitest coverage for pcm_update_save behavior and statement validation.
src/tools/update-save.ts Implements and registers the new pcm_update_save MCP tool and assertWriteStatement.
src/tools/query-save.ts Refactors query parsing/error handling to shared helper utilities.
src/tools/index.ts Registers the new tool in the server tool registry.
src/save-db.ts Adds opt-in write mode to withSaveDb and introduces writeSaveDb for .cdb serialization.
src/helpers.ts Adds shared parseSingleStatement and explainQueryError.
README.md Updates readme to describe the new guarded write tool and revised safety story.

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

Comment thread src/save-db.ts Outdated
Comment thread src/save-db.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/save-db.ts
Comment thread src/save-db.ts
Comment thread src/save-db.ts
mpicciolli and others added 3 commits July 2, 2026 19:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mpicciolli
mpicciolli merged commit ddafc34 into main Jul 2, 2026
2 checks passed
@mpicciolli
mpicciolli deleted the feat/pcm-update-save branch July 2, 2026 23:06
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