Repository navigation
feat: expose reader user state through MCP - #1052
Conversation
Problem: #867 durable user-state APIs were available to the daemon reader, but MCP write-role clients still had no typed way to list or mutate conversation marks or saved views. That kept agent-facing recall workflows behind the web surface.\n\nWhat changed: add typed MCP payloads plus list/add/remove mark tools and list/save/delete saved-view tools. Saved-view writes validate strict ConversationQuerySpec JSON before storing canonical query JSON. The MCP envelope registry and tool-schema witness are updated, and user-state tool tests live in a focused file to keep the large MCP contract test under budget.\n\nRemaining: annotations, message/range targets, recall-pack MCP shape, and CLI parity remain open under #867.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR implements MCP mutation tools for user marks and saved views, enabling clients to list, create, modify, and delete conversation marks and saved-view definitions through the MCP interface. ChangesMCP User-State Parity Launch
Sequence DiagramsequenceDiagram
participant Client
participant list_marks
participant add_mark
participant remove_mark
participant list_saved_views
participant save_saved_view
participant delete_saved_view
Client->>list_marks: mark_type?, conversation_id?
list_marks-->>Client: MCPUserMarkListPayload {items, total}
Client->>add_mark: conversation_id, mark_type
add_mark-->>Client: MutationResultPayload {status: added|unchanged}
Client->>remove_mark: conversation_id, mark_type
remove_mark-->>Client: MutationResultPayload {status: removed|not_found}
Client->>list_saved_views: (no params)
list_saved_views-->>Client: MCPSavedViewListPayload {items, total}
Client->>save_saved_view: name, query_json, view_id?
save_saved_view-->>Client: MutationResultPayload {status: ok|error}
Client->>delete_saved_view: view_id
delete_saved_view-->>Client: MutationResultPayload {status: deleted|not_found}
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd889a975d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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 `@polylogue/mcp/server_mutation_tools.py`:
- Around line 228-231: The response currently mixes the save result (`created`
from save_view) with the subsequent lookup (`saved = get_view(saved_id)`),
causing contradictory values when save_view reports created but get_view returns
None; update the logic in the block that constructs the response so it is
consistent: either (A) treat a missing saved (saved is None) as an error—set
status="error" and detail="saved_view_not_found" when saved is None (override
created/outcome accordingly), or (B) remove the extra get_view(saved_id)
verification entirely and rely solely on the `created` boolean from save_view to
set status ("ok"/"unchanged") and outcome ("added"/"updated") and always leave
detail None; apply this change to the code that builds status/detail/outcome
using the symbols save_view, get_view, created, saved, saved_id, status, detail,
outcome.
- Around line 216-219: The except block for
ConversationQuerySpec.from_params(query, strict=True) currently returns only the
exception type; change it to include the exception message (or both type and
message) in the hooks.error_json detail so users see the specific validation
error (use the caught exc from the except clause and include str(exc) alongside
type(exc).__name__ in the detail passed to hooks.error_json).
- Around line 170-190: The remove_mark tool lacks the upfront mark_type
validation that add_mark performs; add the same validation check for mark_type
at the start of remove_mark (before calling _resolve_or_error or
poly.remove_mark) and return the same validation error payload/format used by
add_mark so callers get a clear validation error instead of a generic not_found;
update the remove_mark function (and its inner run closure if validation lives
there) to call the same validation helper or inline checks and return the
matching error response via hooks.json_payload/MutationResultPayload when
mark_type is invalid.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e965d63b-72d2-454c-959b-ae112db8e5c1
📒 Files selected for processing (6)
docs/plans/mk3-execution-log.mdpolylogue/mcp/payloads.pypolylogue/mcp/server_mutation_tools.pytests/data/witnesses/mcp-tool-schemas.jsontests/unit/mcp/test_envelope_contracts.pytests/unit/mcp/test_user_state_tools.py
Problem: review found inconsistent saved-view mutation responses and asymmetric mark validation in the new MCP user-state tools.\n\nWhat changed: validate remove_mark mark types with the same path as add_mark, include the concrete query-spec validation message in error detail, generate collision-resistant default saved-view IDs, and return ok for successful saved-view updates. Tests now cover those paths.
|
Review follow-up: the current branch validates mark_type in both add_mark and remove_mark through _mark_type_error; the remaining inline marker is attached to the async-safe-call return line after the fix. Query validation details, saved-view ID generation, and saved-view update status were also addressed in 9b52a82. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Expose the durable reader user-state substrate through write-role MCP tools for conversation marks and saved views, using typed payloads and existing Polylogue facade methods.
Problem
#867 user state was now available through daemon HTTP and the reader UI, but MCP clients still could not list or mutate marks or saved views. That left agent-facing recall workflows behind the web surface and kept the MCP wire schema stale relative to the product state now exposed elsewhere.
Solution
list_marks,add_mark, andremove_markmutation tools.list_saved_views,save_saved_view, anddelete_saved_viewmutation tools.ConversationQuerySpecconstruction.Remaining #867 scope: annotations, message/range targets, recall-pack MCP shape, and CLI parity.
Ref #867
Verification
pytest -q tests/unit/mcp/test_tool_contracts.py -k "mark or saved_view"-> 37 passedpytest -q tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py tests/unit/mcp/test_tool_schema_witness.py-> 33 passedpytest -q tests/unit/mcp-> 188 passedruff format --check polylogue/mcp/server_mutation_tools.py polylogue/mcp/payloads.py tests/unit/mcp/test_tool_contracts.py tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py-> 5 files already formattedruff check polylogue/mcp/server_mutation_tools.py polylogue/mcp/payloads.py tests/unit/mcp/test_tool_contracts.py tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py-> All checks passedmypy polylogue/mcp/server_mutation_tools.py polylogue/mcp/payloads.py tests/unit/mcp/test_tool_contracts.py tests/unit/mcp/test_user_state_tools.py tests/unit/mcp/test_envelope_contracts.py-> Successdevtools verify --quick-> exit_code 0devtools verify --affected --skip-slow-> exit_code 0; pytest affected count 8Summary by CodeRabbit
Release Notes
New Features
Tests
Documentation