Skip to content

feat(mcp): user_view MCP App — interactive user profile (KLA-403)#20

Merged
jrennichjc merged 5 commits into
mainfrom
juergen/mcp-app-user-view
Apr 28, 2026
Merged

feat(mcp): user_view MCP App — interactive user profile (KLA-403)#20
jrennichjc merged 5 commits into
mainfrom
juergen/mcp-app-user-view

Conversation

@jklaassenjc
Copy link
Copy Markdown
Collaborator

@jklaassenjc jklaassenjc commented Apr 28, 2026

Summary

What's in the box

Server (`apps_user.go`)

  • `userViewArgs { User string }` — resolves via UserConfig (username, email, or hex ID)
  • Parallel fan-out: GET /systemusers/{id}, V2 /users/{id}/memberof, V1 /systemusers/{id}/sshkeys, Insights events filtered by `initiated_by.username` (last 30d, limit 50)
  • Best-effort sub-fetches: groups or SSH keys failing → `warnings[]` entry, doesn't block the view
  • `last_login` derived from the most recent event (no extra call)
  • `previewSSHKey` trims public keys to algo-prefix + 12 chars so the UI stays scannable

Client (`apps_html/user.html`)

  • Header card with avatar (initials), name + email, joined/last-seen, status badges
  • Three cards: groups (pills), SSH keys (table), recent events (table)
  • Refresh re-runs user_view with the username captured from the initial payload

Tests (`apps_user_test.go`, 5 tests)

  • `previewSSHKey` shape (algo-prefixed, short, unstructured)
  • `fetchUserViewData` aggregation across all four sub-fetches
  • Required-input validation
  • `_meta.ui.resourceUri` advertised
  • `ui://` resource has common.js injected, marker stripped

Test plan

  • `go test ./...` — clean, 5 new tests
  • `go vet ./...` — clean
  • Live validation in basic-host on `v1.16.0`

Closes KLA-403.

🤖 Generated with Claude Code


Note

Medium Risk
Medium risk because it introduces new multi-endpoint aggregation logic (V1/V2/Insights) and a sizeable embedded HTML UI; failures or schema mismatches could surface as incorrect or partial profile data.

Overview
Adds a new MCP App, user_view, which takes a user identifier (username/email/ID) and returns a structured profile payload that MCP App-capable hosts render via a new ui://jc/user HTML resource.

Server-side, the new handler resolves the user then fans out in parallel to fetch group memberships, SSH keys (with key previews), and last-30d Insights events (bounded), returning best-effort results with warnings when sub-fetches fail.

Also tightens the DOM helper used by the existing dashboard and insights apps to be text/Node-only (dropping unknown attributes) to reduce XSS surface, and updates tool registration/tests to include the new tool and expected tool count.

Reviewed by Cursor Bugbot for commit cacdeed. Bugbot is set up for automated code reviews on this repo. Configure here.

Adds the user-detail MCP App: pass username/email/ID, get back a structured
profile with header, MFA enrollment, group memberships, SSH keys, and
recent insights events. Mirrors the dashboard's "fan out parallel API
calls + aggregate" pattern, leans on the typed-tool helper from PR #19,
and uses the shared jcApp scaffolding from PR #18.

Server side (apps_user.go):
- userViewArgs: single User field (resolves via the existing UserConfig
  resolver, so username/email/24-char ID all work)
- userViewData: header + mfa + groups[] + ssh_keys[] + recent_events[]
  + warnings[]
- fetchUserViewData fans out four goroutines:
  * GET /systemusers/{id} for the header & MFA flags
  * V2 /users/{id}/memberof for group memberships (sorted by name)
  * V1 /systemusers/{id}/sshkeys for SSH keys
  * Insights /events filtered by initiated_by.username, last 30d, limit 50
- Best-effort sub-fetches: a transient failure on groups or SSH keys
  becomes a Warnings entry, doesn't block the rest of the view
- last_login is derived from the most recent event (cheap, no extra call)
- previewSSHKey trims public keys to "<algo> <12-char-prefix>…" so the UI
  panel stays scannable

Client side (apps_html/user.html):
- Header card: avatar (initials), name + email + "joined / last seen",
  status badges (Active/Suspended/Locked + MFA on/off)
- Groups: pill list
- SSH keys: name + algo-prefixed preview + create date table
- Recent events: timestamp + service + event_type + result + client IP
- Refresh re-runs user_view with the username captured from the initial
  payload (survives the iframe reload without needing args replayed)

Tests (apps_user_test.go):
- previewSSHKey covers algo-prefixed, short, and unstructured inputs
- fetchUserViewData_Aggregates: full fixture (user + 2 groups + 1 ssh
  key + 2 events) verifies header, MFA enrollment, group sort, ssh
  preview shape, event count, last_login derivation
- fetchUserViewData_RequiresUser: empty input rejected
- user_view exposes _meta.ui.resourceUri
- ui:// resource has common.js injected and the marker stripped
- Tool count 196 → 197, expected list adds user_view

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread internal/mcp/apps_user.go
Comment thread internal/mcp/apps_html/user.html
- apps_user.go: fetch user detail synchronously before fanning out so
  the Insights events filter can use the canonical username (not the
  caller's raw input, which may be an email or hex ID).
- user.html: read mfa.status === "ENROLLED" alongside totp_enabled so
  non-TOTP MFA enrollments still show the badge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 64f5432. Configure here.

Comment thread internal/mcp/apps_user.go Outdated
juergen-kc and others added 2 commits April 27, 2026 20:27
Drop the hand-rolled joinWarnings helper in favour of strings.Join,
addressing Cursor Bugbot's low-severity nit on PR #20.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CodeQL flagged the el(...) helper's `appendChild(c)` branch as a
client-side XSS sink because the analyzer can't prove `c` is a Node.
Tighten the helper across the three apps to only accept strings (which
go through createTextNode) or instances of Node — same runtime
behaviour, but gives CodeQL the type proof it needs to mark the path
sanitized.

Closes the open dashboard.html alert
(repos/TheJumpCloud/jc-cli/code-scanning/alerts/1) and pre-empts the
same alert showing up on insights.html and user.html.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
children.forEach(function(c) {
if (typeof c === 'string') node.appendChild(document.createTextNode(c));
else if (c) node.appendChild(c);
else if (c instanceof Node) node.appendChild(c);
if (c == null) return;
if (typeof c === "string") n.appendChild(document.createTextNode(c));
else n.appendChild(c);
else if (c instanceof Node) n.appendChild(c);
Remove the catch-all setAttribute / style-passthrough fallback in the
el() DOM builder across the three MCP Apps. No callers exercised that
branch (every attr is className or textContent, plus dashboard's fixed
inline style palette), and keeping it open meant a future caller
passing {href: untrusted} or {onclick: ...} would silently introduce
an XSS sink.

Helpers are now strictly text-content + className only; anything else
is dropped. Coerce values to String() defensively. Doesn't close the
js/xss CodeQL alerts (analyzer can't prove inter-procedural Node
provenance — to be dismissed as false positive), but eliminates the
real future-misuse footgun.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jrennichjc jrennichjc merged commit 788678a into main Apr 28, 2026
5 of 7 checks passed
@jrennichjc jrennichjc deleted the juergen/mcp-app-user-view branch April 28, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants