Skip to content

Add admin user creation MCP capability - #626

Merged
kentcdodds merged 2 commits into
mainfrom
cursor/admin-capability-role-gating-289c
Jul 5, 2026
Merged

kentcdodds merged 2 commits into
mainfrom
cursor/admin-capability-role-gating-289c

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jul 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds admin_user_create to the admin MCP capability domain.
  • Reuses adminCreateUserWithPasswordSetup so MCP creation matches the admin UI flow: create account, assign default user role, verify email, and return a reset-password setup link.
  • Audits successful invocations with target user id and redacted target email.
  • Updates admin capability docs and unit coverage.

Testing

  • npm run validate ✅
    • typecheck exited 0
    • format/lint exited 0
    • unit tests: 171 files / 516 tests passed
    • Playwright E2E: 6 passed
    • MCP E2E: 3 passed
System recap — extends existing primitives (medium risk)

Mode: recap · Base: main @ 36cfdbb · Head: 417cfab

Classification: extends — this PR adds one mutating admin capability to the existing admin MCP domain and reuses the existing admin user creation service.

Primitives touched

Primitive Group Impact
capability-registry assistant extends — registers admin_user_create in the admin domain
rbac auth composes — uses the existing requiredRole: 'admin' capability gate
mcp-server surfaces composes — exposes the capability through existing search/execute surfaces
d1-app-db storage composes — calls existing service-layer writes for users, roles, and setup tokens

System map

flowchart LR
	rbac["rbac"]:::touched --> capabilityRegistry["capability-registry"]:::extended
	capabilityRegistry --> mcpServer["mcp-server"]:::touched
	mcpServer --> d1AppDb["d1-app-db"]:::touched
	classDef touched fill:#1a7f37,color:#fff
	classDef extended fill:#9a6700,color:#fff
	classDef added fill:#cf222e,color:#fff
	classDef untouched fill:#57606a,color:#fff
Loading

Change flow

sequenceDiagram
	participant Host as MCP host
	participant Cap as admin_user_create
	participant Service as adminCreateUserWithPasswordSetup
	participant DB as APP_DB
	Host->>Cap: execute codemode.admin_user_create({ email })
	Cap->>Service: call existing admin UI service
	Service->>DB: create user, assign user role, create setup token
	Cap->>DB: write sanitized audit event
	Cap-->>Host: created user metadata + setup link
Loading

Invariants

  • Preserves per-user-isolation: the capability creates account metadata and setup-token state only through the existing admin service; it does not read or expose user content.
  • Admin access remains role-gated at the generic capability layer (requiredRole: 'admin') and enforced again at execute time.
Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features
    • Added an admin-only “create account” action in the admin tools.
    • Created users now receive a password setup link with expiry, default role assignment, and audit-log metadata.
  • Documentation
    • Updated admin domain guidance to list current admin capabilities and to standardize how new admin actions are added.
  • Tests
    • Expanded coverage for the account creation flow, including database mocking and audit/reason verification.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e4d461e1-dd71-4a95-a5ab-68d76c3bfff6

📥 Commits

Reviewing files that changed from the base of the PR and between 417cfab and 7905aeb.

📒 Files selected for processing (1)
  • packages/worker/src/mcp/capabilities/admin/admin-user-create.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/worker/src/mcp/capabilities/admin/admin-user-create.ts

📝 Walkthrough

Walkthrough

Adds a new admin_user_create MCP capability for admin-only user creation with password setup links, extends shared admin audit helpers with configurable success reasons and redacted-email reason building, wires the capability into the admin domain, and updates tests and documentation.

Changes

Admin User Creation Capability

Layer / File(s) Summary
Shared admin capability helpers
packages/worker/src/mcp/capabilities/admin/admin-shared.ts
Adds adminMutationCapabilityAccess, extends auditAdminCapabilityInvocation with an optional successReason callback, and adds buildCreatedUserAuditReason using redactEmailRecipient.
admin_user_create capability definition
packages/worker/src/mcp/capabilities/admin/admin-user-create.ts
Defines Zod input/output schemas and registers adminUserCreateCapability, whose handler creates a user with a password setup link inside an audited invocation.
Domain wiring
packages/worker/src/mcp/capabilities/admin/domain.ts
Imports and adds adminUserCreateCapability to adminDomain's capabilities array.
Mock DB test coverage and documentation
packages/worker/src/mcp/capabilities/admin/admin-capabilities.node.test.ts, docs/contributing/adding-capabilities.md
Extends the mock D1 test database with user creation, role assignment, and password reset mutation handling; adds a test verifying the new capability; updates admin capabilities documentation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Admin
  participant adminUserCreateCapability
  participant auditAdminCapabilityInvocation
  participant AppDB

  Admin->>adminUserCreateCapability: handler(email, username)
  adminUserCreateCapability->>auditAdminCapabilityInvocation: wrap(createUser call)
  auditAdminCapabilityInvocation->>AppDB: adminCreateUserWithPasswordSetup(email, username, baseUrl)
  AppDB-->>auditAdminCapabilityInvocation: createdUser
  auditAdminCapabilityInvocation->>auditAdminCapabilityInvocation: log audit (buildCreatedUserAuditReason)
  auditAdminCapabilityInvocation-->>adminUserCreateCapability: createdUser
  adminUserCreateCapability-->>Admin: { createdUser }
Loading

Related issues: None found.

Related PRs: None found.

Suggested labels: enhancement, admin, mcp

Suggested reviewers: kentcdodds

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the admin user creation MCP capability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/admin-capability-role-gating-289c

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-626.kentcdodds.workers.dev

Worker: kody-pr-626
D1: kody-pr-626-db
KV: kody-pr-626-oauth-kv

Mocks:

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
packages/worker/src/mcp/capabilities/admin/admin-user-create.ts (1)

11-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use top-level z.email() instead of deprecated .email() chain.

Zod v4 promotes string-format validators to top-level functions; z.string().email() still works but is deprecated and will be removed in a future major version.

♻️ Proposed fix
 const inputSchema = z.object({
-	email: z
-		.string()
-		.email()
-		.describe('Email address for the account to create.'),
+	email: z
+		.email()
+		.describe('Email address for the account to create.'),
🤖 Prompt for 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.

In `@packages/worker/src/mcp/capabilities/admin/admin-user-create.ts` around lines
11 - 23, The input schema in admin-user-create should use the top-level email
validator instead of the deprecated string method. Update the email field in
inputSchema to use z.email() directly, keeping the existing describe text and
preserving the username field behavior. Locate this in admin-user-create.ts
where inputSchema is defined.
🤖 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.

Nitpick comments:
In `@packages/worker/src/mcp/capabilities/admin/admin-user-create.ts`:
- Around line 11-23: The input schema in admin-user-create should use the
top-level email validator instead of the deprecated string method. Update the
email field in inputSchema to use z.email() directly, keeping the existing
describe text and preserving the username field behavior. Locate this in
admin-user-create.ts where inputSchema is defined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6071f56e-2609-4241-9306-13f890b2eee6

📥 Commits

Reviewing files that changed from the base of the PR and between 36cfdbb and 417cfab.

📒 Files selected for processing (5)
  • docs/contributing/adding-capabilities.md
  • packages/worker/src/mcp/capabilities/admin/admin-capabilities.node.test.ts
  • packages/worker/src/mcp/capabilities/admin/admin-shared.ts
  • packages/worker/src/mcp/capabilities/admin/admin-user-create.ts
  • packages/worker/src/mcp/capabilities/admin/domain.ts

@kentcdodds
kentcdodds merged commit f47f785 into main Jul 5, 2026
5 checks passed
@kentcdodds
kentcdodds deleted the cursor/admin-capability-role-gating-289c branch July 5, 2026 20:03
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