Skip to content

feat(mcp): add people cleanup tools - #8346

Closed
Git-on-my-level wants to merge 10 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/issue-8204-mcp-people-cleanup
Closed

Git-on-my-level wants to merge 10 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/issue-8204-mcp-people-cleanup

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds hosted MCP rename_person and delete_person tools for people/contact cleanup.
  • Introduces people.write OAuth metadata/security scheme for the new mutation tools while keeping get_people read-only.
  • Validates required person ids and 2–40 char trimmed names; checks person existence before mutating.
  • Adds unit coverage for descriptors, scope metadata, validation, 404 handling, rename behavior, and delete behavior.

Testing

cd backend
ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 25 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py
git diff --check

Notes:

  • Scope intentionally excludes merge/dismiss. Those need product semantics and/or DB primitives beyond existing hard-delete/rename behavior.
  • Local test venv was bootstrapped with pytest/fastapi/pydantic because this worktree had no backend .venv.

Review in cubic

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60d6cb30ca

ℹ️ 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".

Comment thread backend/routers/mcp_sse.py Resolved

@cubic-dev-ai cubic-dev-ai Bot 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.

2 issues found across 2 files

Confidence score: 1/5

  • In backend/routers/mcp_sse.py, the new people mutation tools can execute without enforcing people.write, so any valid MCP key may rename or delete contacts beyond its intended permissions; this is a concrete authorization bypass with direct security and data-integrity impact — enforce scope checks at tool execution (and add a regression test) before merging.
  • In backend/routers/mcp_sse.py (delete_person), deleting the Firestore person document without deleting linked speech-sample files leaves orphaned audio in storage, creating inconsistent privacy/data-retention behavior across delete paths — add storage cleanup for associated files (or a guaranteed async cleanup job) before merging.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread backend/routers/mcp_sse.py Resolved
Comment thread backend/routers/mcp_sse.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the review feedback.

Fixes:

  • rename_person / delete_person now fail closed unless the authenticated MCP key has explicit people.write scope.
  • MCP auth now carries stored key scopes into tool execution instead of relying only on tool metadata.
  • delete_person now calls delete_user_person_speech_samples(uid, person_id) before deleting the Firestore person doc, matching the existing user-facing delete cleanup path.
  • Added regression coverage for write-scope enforcement, speech-sample cleanup, rename/delete validation, and descriptors.

Verification:

cd backend
ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 26 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py database/mcp_api_key.py
git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68c7357949

ℹ️ 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".

Comment thread backend/routers/mcp_sse.py Resolved
Comment thread backend/database/mcp_api_key.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the follow-up Codex review comments.

Fixes:

  • New MCP keys now store explicit scopes and default to the hosted MCP scope set, including people.write, so the advertised write tools are reachable for newly-created keys while execute_tool still enforces the stored scope.
  • Explicit scopes subsets are preserved when provided.
  • MCP scoped auth now uses a Redis-backed {user_id, scopes} cache instead of querying Firestore on every MCP request.
  • Added regression coverage for default people.write, explicit scope subsets, write-scope enforcement, and speech-sample cleanup.

Verification:

cd backend
ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 28 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py routers/mcp.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py
git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cc6dd4703

ℹ️ 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".

Comment thread backend/routers/mcp_sse.py Resolved
Comment thread backend/routers/mcp.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the latest Codex review on scopes.

Fixes:

  • Enforce the advertised securitySchemes scopes for every MCP SSE tool before dispatch, not just people.write tools.
  • Preserve explicit empty scope lists when creating MCP keys (scopes=[] now stays empty instead of defaulting to all scopes).
  • Added regression tests for:
    • a read tool (get_chat_messages) blocked without chat.read
    • explicit empty scope list preservation
    • previous people-write protections remain covered

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 30 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py routers/mcp.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 70c505d72d

ℹ️ 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".

Comment thread backend/routers/mcp_sse.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the latest Codex P2.

Fix:

  • rename_person now returns only minimal person metadata (id, name) instead of clean_person(...), so a people.write-only key cannot receive speech-sample transcripts as part of a write response.
  • The read path remains get_people, which requires people.read through the advertised scope gate.

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 30 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py routers/mcp.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@cubic-dev-ai cubic-dev-ai Bot 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.

4 issues found across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread backend/database/mcp_api_key.py Resolved
Comment thread backend/routers/mcp.py Resolved
Comment thread backend/routers/mcp_sse.py Resolved
Comment thread backend/routers/mcp_sse.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the latest cubic review.

Fixes:

  • Missing stored MCP scopes now fail closed ([]) instead of propagating None into the tool gate.
  • Moved the supported/default MCP scope list into models/mcp_api_key.py and reused it from both REST key creation and SSE metadata/enforcement to avoid drift.
  • Deleted the now-unused people-write scope helper constants.
  • Moved person speech-sample storage cleanup onto storage_executor so the async MCP request path does not block on GCS deletion.

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 30 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py routers/mcp.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@cubic-dev-ai cubic-dev-ai Bot 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.

2 issues found across 6 files (changes from recent commits).

You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread backend/models/mcp_api_key.py Resolved
Comment thread backend/routers/mcp_sse.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38ff0c75af

ℹ️ 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".

Comment thread backend/database/mcp_api_key.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the latest comments.

Fixes:

  • MCP_DEFAULT_API_KEY_SCOPES now copies MCP_SCOPES_SUPPORTED instead of aliasing the same mutable list.
  • Legacy MCP keys that do not have a stored scopes field retain read-only access via MCP_LEGACY_API_KEY_SCOPES; write scopes still require explicit stored scope data.
  • Removed raw UID/person-id logging from async person sample cleanup failures.

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 30 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp_sse.py routers/mcp.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3dfbde65c6

ℹ️ 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".

Comment thread backend/routers/mcp.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the latest Codex P1 about REST MCP scope enforcement.

Fixes:

  • REST /v1/mcp/* data routes now authenticate through MCP API-key auth that carries stored scopes instead of only returning uid.
  • Added route-specific scope dependencies for memories, conversations, action items, goals, chat, people, screen activity, and daily summaries.
  • Write routes (create_memory, edit_memory, delete_memory) require memories.write; read routes require their corresponding read scope.
  • Added regression coverage that verifies restricted keys are rejected, allowed scopes pass, stored scopes are read from the API key, and each REST route is wired to its expected scope dependency.

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 34 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp.py routers/mcp_sse.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 2 files (changes from recent commits).

You’re at about 93% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread backend/routers/mcp.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9a9aaf2cf

ℹ️ 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".

Comment thread backend/routers/mcp.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the latest daily-summaries scope feedback.

Fix:

  • REST /v1/mcp/daily-summaries now requires conversations.read, matching the advertised/enforced SSE MCP tool scope for get_daily_summaries.
  • Updated the REST route dependency regression table so the mismatch stays covered.

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 34 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp.py routers/mcp_sse.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14ffe9f05c

ℹ️ 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".

Comment thread backend/database/mcp_api_key.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the legacy memory-write compatibility feedback.

Fix:

  • Legacy MCP keys that predate stored scopes now retain the access they previously had for memory writes by including memories.write in MCP_LEGACY_API_KEY_SCOPES.
  • The fallback still does not grant the new people.write permission, so the new destructive people cleanup tools continue requiring explicit stored scope data.
  • Added regression coverage for this exact legacy scope shape.

Verification:

ENCRYPTION_SECRET=*** VIRTUAL_ENV= uv run python -m pytest tests/unit/test_mcp_data_endpoints.py -q
# 35 passed, 1 warning

VIRTUAL_ENV= uv run python -m py_compile routers/mcp.py routers/mcp_sse.py database/mcp_api_key.py database/redis_db.py models/mcp_api_key.py

git diff --check

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Review comment resolution summary

All review comments have been verified against current HEAD (989b610). Every real issue is already addressed in the existing commits. 68/68 unit tests pass, py_compile clean, git diff --check clean.

✅ P1 — Tool scope enforcement (cubic-dev-ai, chatgpt-codex-connector)

  • rename_person/delete_person now require people.write via PEOPLE_WRITE_SECURITY on tool definitions + TOOL_REQUIRED_SCOPES runtime check in execute_tool().
  • All SSE tools enforce their advertised scopes — the generic scope gate at the top of execute_tool() checks every tool call against granted_scopes.

✅ P1 — None scopes overgranting (cubic-dev-ai, chatgpt-codex-connector)

  • get_auth_by_api_key() maps scopes: None → MCP_LEGACY_API_KEY_SCOPES (all .read + memories.write), not full MCP_SCOPES_SUPPORTED. Explicit [] is preserved as-is.

✅ P2 — delete_person data retention (chatgpt-codex-connector, cubic-dev-ai)

  • delete_person now calls delete_user_person_speech_samples(uid, person_id) via storage_executor.submit() (fire-and-forget, non-blocking) before deleting the Firestore person doc.

✅ P2 — REST scope enforcement (chatgpt-codex-connector)

  • All REST /v1/mcp/* routes use require_mcp_scope() dependency with get_auth_by_api_key() returning user_id + scopes.

✅ P2 — Daily summaries scope (chatgpt-codex-connector, cubic-dev-ai)

  • Both SSE tool and REST /v1/mcp/daily-summaries now use conversations.read.

✅ P2 — rename_person transcript leak (chatgpt-codex-connector)

  • rename_person returns {"id": person_id, "name": name} — no longer serializes clean_person() with speech_sample_transcripts.

✅ P1/P2 — Legacy key preservation (chatgpt-codex-connector)

  • Keys with no scopes field get MCP_LEGACY_API_KEY_SCOPES (all reads + memories.write), preserving existing MCP client functionality. New keys default to all scopes via MCP_DEFAULT_API_KEY_SCOPES.

✅ P2 — Uncached Firestore auth (chatgpt-codex-connector)

  • get_auth_by_api_key() uses Redis cache (cache_mcp_api_key_auth/get_cached_mcp_api_key_auth) with 1h TTL. Firestore only queried on cache miss.

ℹ️ Not actionable (informational, no code change needed)

  • Scope duplication (cubic-dev-ai, P2): MCP_DEFAULT_API_KEY_SCOPES is imported from models/mcp_api_key.py — no duplication.
  • Unused constants (cubic-dev-ai, P3): PEOPLE_WRITE_SCOPE/PEOPLE_WRITE_TOOLS already removed; scope gate is now generic via TOOL_REQUIRED_SCOPES.
  • Mutable alias (cubic-dev-ai, P2): list(MCP_SCOPES_SUPPORTED) already creates a shallow copy.
  • PII in logs (cubic-dev-ai, P2): UIDs are intentionally visible per AGENTS.md. person_id is an internal Omi ID, not PII.
  • Blocking GCS deletes (cubic-dev-ai, P2): Already offloaded to storage_executor.submit() — fire-and-forget.

Verification

68 passed, 1 warning in 0.25s  (tests/unit/test_mcp_*.py)
py_compile: mcp_sse.py ✅  mcp.py ✅  mcp_api_key.py ✅  mcp_api_key model ✅
git diff --check: clean

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Closing this draft in favor of a narrower follow-up after the canonical memory rollout lands upstream.

Follow-up issue: #8369

Rationale:

  • The core People cleanup need is still valid, but this PR mixed tool additions with broader MCP scope/auth migration and deletion semantics.
  • Fork PR feat(memory): canonical memory domain rollout (store, writes, desktop, backfill) Git-on-my-level/omi#33 introduces the canonical memory/auth context foundation that the follow-up should reuse instead of duplicating.
  • The next implementation should be based on upstream main after that foundation lands, start with safer/non-destructive People cleanup, and carry forward the lessons from this PR's review rounds.

Thanks to the bot reviews here — the feedback surfaced useful requirements around legacy key behavior, REST/SSE scope parity, write-only response leakage, tools/list ergonomics, and durable cleanup semantics.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our roadmap and vision

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community! 💜

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.

1 participant