feat(mcp): add edit_file/append_file for partial writes - #3188
Conversation
Updating one section of a long document required resending the whole file through codekeeper_save_file. Add two server-side write tools so the client only sends the changed part: - codekeeper_edit_file: exact find-and-replace (old_string -> new_string, optional replace_all) with native-Edit-tool semantics — no_match / ambiguous_match (with occurrence count) / identical-strings guards, nothing saved on error. - codekeeper_append_file: append to the end of an existing file, inserting a newline separator when the body doesn't end with one. Both fetch the latest version, apply the change in-process, and persist through the same append-only versioned save path (pre-edit version stays recoverable via list_versions). Language, description and tags are carried over so an edit never resets metadata; the save_file size gate applies to the resulting body (extracted as _max_code_size and reused). Both tools require the write scope, same as save_file. Tests cover _apply_edit semantics, metadata preservation, size gates, not-found/empty guards, and tool registration; docs updated (README, mcp-server.rst, FEATURE doc). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WNFuSyshwpRcxozVZEui5K
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
🧯 Dangerous deletes guard reportPolicy: see .cursorrules — dangerous deletions are blocked unless wrapped safely. Summary:
Flagged findings (file:line:snippet): Excluded matches (by path pattern) |
|
Warning Review limit reached
Next review available in: 8 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughנוספו כלי MCP לעריכה ולהוספת תוכן לקבצים קיימים. ה-handlers מבצעים החלפה מדויקת או append, שומרים גרסה חדשה עם מטא-דאטה, אוכפים הרשאת Changesכלי כתיבת MCP
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Claude
participant MCPServer
participant Handlers
participant Backend
Claude->>MCPServer: בקשת edit או append
MCPServer->>MCPServer: require_write
MCPServer->>Handlers: העברת הבקשה והמשתמש המאומת
Handlers->>Backend: טעינת הגרסה האחרונה
Handlers->>Handlers: שינוי התוכן ובדיקת מגבלת הגודל
Handlers->>Backend: שמירת גרסה חדשה עם מטא-דאטה
Backend-->>Claude: תוצאת הפעולה
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⏱️ Performance report(No performance test durations collected. Mark tests with |
📖 Documentation PreviewThe documentation has been built successfully!
To view locally:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@FEATURE_SUGGESTIONS/FEATURE_MCP_CLAUDE_INTEGRATION.md`:
- Line 215: יישר את טבלאות מפת הדרכים וכלי MCP עם הסטטוס הקנוני בשורה זו: בפאזה
3 הצג רק save ו־edit/append, והסר או סמן כטרם מומש את delete_file בכל המקומות
הרלוונטיים, כולל טבלת מפת הדרכים וטבלת הכלים.
- Around line 13-15: עדכנו את ניסוח אכיפת הרשאת ה־write בתיאור, והחליפו את
הביטוי „אכיפה ידנית” בתיאור מפורש שהשרת mcp_server/server.py מפעיל
require_write(ctx) לפני העברת הבקשה ל-handler.
In `@mcp_server/handlers.py`:
- Around line 186-205: The edit-save flow lacks optimistic concurrency
validation, allowing parallel edits from the same base version to overwrite one
another. Thread the expected base version through edit_file, append_file, and
_resave_edited into Repository.save_code_snippet, then reject or retry when the
current latest version no longer matches; preserve the existing behavior for
successful saves and return an explicit conflict result for stale edits.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f7de7005-37d4-42f0-9a88-00bbe36191c4
📒 Files selected for processing (7)
FEATURE_SUGGESTIONS/FEATURE_MCP_CLAUDE_INTEGRATION.mddocs/mcp-server.rstmcp_server/README.mdmcp_server/handlers.pymcp_server/server.pytests/test_mcp_edit_append.pytests/test_mcp_server_build.py
MAX_CODE_SIZE is a configurable field (default 100K chars, raisable via env), so a fixed "100KB" in the tool docs is stale for any deployment that raised it. Reference the config knob and its default instead, and state the unit as characters (matching the actual len(code) gate). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WNFuSyshwpRcxozVZEui5K
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
הוספת שלושה סעיפים למדיניות הצוות: - "תהליך עבודה" — קודם מציגים תוכנית ומחכים לאישור, אחר כך מממשים את הכל בלי לדלג על חלקים. - "כלל חשוב" — תמיד מחפשים פתרון שורשי לבאג, לא טלאי. - "שפה" — צ'אט, מחשבות, תיאורי commit/PR והערות קוד בעברית; שמות משתנים/פונקציות/טבלאות באנגלית כמקובל. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WNFuSyshwpRcxozVZEui5K
בעקבות סבב ביקורת: - יישור טבלת הכלים ומפת הדרכים עם הסטטוס הקנוני: פאזה 3 מציגה כעת save + edit/append כמומשים, ו-delete_file מסומן "טרם מומש". - דיוק ניסוח אכיפת ה-write: השרת (server.py) קורא require_write(ctx) לפני מסירת הבקשה ל-handler (במקום "אכיפה ידנית ב-handler"). - הוספת non-goal מפורש: דפדפן הריפו הוא קריאה בלבד לצמיתות — אין ולא תתווסף כתיבה/commit/push ל-GitHub (גם ב-FEATURE וגם ב-mcp-server.rst). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WNFuSyshwpRcxozVZEui5K
מה נבנה — עריכה חלקית בלי לשלוח את כל הקובץ
שני כלים חדשים, שניהם מאחורי הרשאת
writeכמוsave_file:1.
codekeeper_edit_file— מצא‑והחלף מדויק:old_stringלא נמצא →no_match; מופיע כמה פעמים →ambiguous_match+ כמה מופעים + רמז (להאריך את הקטע אוreplace_all=true); זהים → שגיאה. בשום מקרה של שגיאה לא נשמר כלום2.
codekeeper_append_file— הוספה לסוף:הבטיחות המובנית בשניהם:
list_versions. עריכה שגויה היא הפיכההתוצאה בפועל: עדכון סעיף במסמך של 314 שורות = שליחת הקטע הישן + החדש בלבד (עשרות תווים במקום ~6,800). וגם עריכה שנכשלת על הרשאה עולה כמעט כלום.
אומת: 169 טסטים (כולל 18 חדשים), black/flake8 נקיים, doc8 + Sphinx על עמוד התיעוד (האזהרה היחידה בבנייה היא ארטיפקט מקומי של בנייה אינקרמנטלית — לא קשורה לתוכן).
אחרי שתמזג ל‑main ו‑Render יעשה דפלוי — הכלים יופיעו אוטומטית בחיבור הקיים (אין צורך בחיבור מחדש; ה‑scope כבר כולל write). 🚀