feat: add pcm_update_save tool for writing changes to a new .cdb file - #15
Merged
Conversation
There was a problem hiding this comment.
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_savetool with single-statement write enforcement and output serialization. - Refactored
pcm_query_saveto reuse sharedparseSingleStatement+explainQueryErrorhelpers. - Extended
withSaveDbwith an opt-in write mode and addedwriteSaveDb, 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.
…les and validate output directory
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
pcm_update_saveMCP tool that runs a single write statement (INSERT/UPDATE/DELETE) against a Pro Cycling Manager.cdbsave and serializes the result to a new.cdbfile. The source save is never modified.What's new
pcm_update_savetool (src/tools/update-save.ts) — executes exactly one data-mutating statement and writes the edited database tooutputPath(which must differ fromsavePath). ReturnsoutputPath,rowsModified, and the normalizedstatement. SELECT, DDL (DROP/CREATE/ALTER), and stacked statements are rejected.save-db.ts—withSaveDbgains an opt-in{ queryOnly: false }config; a newwriteSaveDbhelper re-encodes the sql.js database to PCM's compressed.cdbformat viasqlToCdband refuses to overwrite the source save.parseSingleStatement(statement normalization + single-statement enforcement usingsql-query-identifier, so a;inside a string literal isn't mistaken for a separator) andexplainQueryError(actionable messages for missing table/column and read-only violations). Both are now shared by the read and write tools, andpcm_query_savewas refactored to reuse them.Safety
.cdbis only ever read; writes always go to a separate output file.writeSaveDbthrows ifoutputPathisn't a.cdbor resolves to the source path.INSERT/UPDATE/DELETEis allowed — schema changes are blocked to keep thesqlToCdbround-trip intact.