feat(chat): add embedded assistant and MCP workflows#5109
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a lecturer MCP service and deployment, Manage assistant runtime + widget with proposal confirmation, chat/manage context types/hooks/store integrated into chat routes and UI, PWA course chat drawer and GraphQL chatbot API, Helm/CI packaging, and tests/docs. ChangesComplete PR checkpoint
Estimated code review effort Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
cb96071 to
a35778a
Compare
Confidence Score: 5/5Safe to merge after addressing the open items from previous review threads and validating cookie sharing between the manage and chat subdomains in staging. The core auth flows (session verification, MCP JWT minting, proposal token sign-and-verify, APQ-only mutation forwarding) are implemented defensively and tested. The postMessage bridges are correctly origin-validated on both ends. The one new finding — the 'open in new tab' link using the embed URL — is a minor UX edge case that does not affect the main assistant functionality. apps/frontend-manage/src/components/assistant/ManageAssistantWidget.tsx — the new-tab href should use a non-embedded URL to preserve the full login-recovery UI.
|
| Filename | Overview |
|---|---|
| apps/chat/src/app/api/manage/chat/route.ts | New POST route for the Manage assistant: validates auth, sanitizes context, loads MCP tools, streams AI responses. MCP tool loading failure is handled gracefully with a silent fallback. |
| apps/chat/src/app/api/manage/proposals/confirm/route.ts | Proposal confirmation route: verifies user identity, JWT proposal token, and forwards APQ mutation to GraphQL with proper CSRF headers. getGraphqlEndpoint() has a silent localhost fallback when APP_ORIGIN_API is missing (flagged in a previous review thread). |
| apps/chat/src/services/manageProposals.ts | Builds APQ-only GraphQL requests (no inline query body), verifies signed proposal tokens, and executes confirmation mutations. All errors are normalized to a generic token error to prevent leaking verification details. |
| apps/chat/src/lib/server/manageAuth.ts | Reads the next-auth session cookie and verifies it with APP_SECRET to authenticate manage lecturers in the chat app. |
| apps/mcp-lecturer/src/server.ts | FastMCP server with bearer-token auth, read/draft tool separation, and signed proposal generation. Error normalization prevents leaking authorization details to the model. |
| apps/mcp-lecturer/src/service.ts | Read service backed by Prisma with userId-scoped DerivedPermission filters on every query; double-checked with requireDerivedPermission after data retrieval. Content fields are capped to prevent token blowout. |
| apps/frontend-manage/src/components/assistant/ManageAssistantWidget.tsx | Iframe-based Manage assistant widget with postMessage context bridge, ack retry, and keyboard/focus management. The 'open in new tab' link reuses the embed URL; a non-embedded URL should be derived separately (see comment). |
| apps/frontend-pwa/src/components/chatbot/CourseChatDrawer.tsx | Course chatbot drawer with origin-validated postMessage context bridge; correctly separates embedded iframe URL from non-embedded new-tab href. |
Sequence Diagram
sequenceDiagram
participant Manage as Manage App
participant ChatApp as Chat App
participant MCP as mcp-lecturer
participant GQL as GraphQL API
Note over Manage,ChatApp: Embedded assistant (iframe)
Manage->>ChatApp: "iframe src=/manage?embed=true"
Manage->>ChatApp: postMessage klicker:manage-context
ChatApp-->>Manage: postMessage klicker:manage-context-ack
Note over ChatApp,MCP: Chat request
Manage->>ChatApp: POST /api/manage/chat (session cookie)
ChatApp->>ChatApp: getAuthenticatedManageUserId()
ChatApp->>ChatApp: mintLecturerMcpJwt(userId)
ChatApp->>MCP: Bearer JWT
MCP->>MCP: verifyLecturerSession()
MCP-->>ChatApp: MCP tool list
ChatApp-->>Manage: SSE stream
Note over ChatApp,GQL: Proposal confirmation
Manage->>ChatApp: POST /api/manage/proposals/confirm
ChatApp->>ChatApp: verifyManageProposalToken()
ChatApp->>GQL: POST /api/graphql (APQ)
GQL-->>ChatApp: manipulateChoicesQuestion
ChatApp-->>Manage: element created
Reviews (7): Last reviewed commit: "fix(security): avoid test url hotspots" | Re-trigger Greptile
# Conflicts: # AGENTS.md # apps/chat/src/components/thread.tsx # apps/olat-api/test/docker/Dockerfile.test # cypress/cypress/e2e/O-live-quiz-workflow.cy.ts # cypress/cypress/support/commands.ts # packages/grading/package.json # packages/hatchet/package.json # packages/markdown/package.json # packages/prisma/package.json # packages/util/package.json # pnpm-lock.yaml
|
Too many files changed for review. ( Bypass the limit by tagging |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 14050276 | Triggered | Generic Password | db1c87b | .github/workflows/playwright-testing.yml | View secret |
| 1509424 | Triggered | Generic Password | db1c87b | .github/workflows/playwright-testing.yml | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
|
Production readiness review pushed to the branch: TL;DR: solid merge candidate for |
|
Junior runtime feedback verified and incorporated into the review file (commit 109dbf7, findings F5–F9):
Checklist steps 1, 5, 7 updated accordingly. |




What This Adds
apps/mcp-lecturerwith auth, authorization, tool policy/error/capability patterns, smoke scripts, tests, and Helm/K8s deployment wiring.grading,hatchet,markdown,prisma, andutil; GraphQL keeps Rollup with a NodeNext-compatible emit override.v3intov3-ai, then latestv3-aiinto this branch; kept@assistant-ui/react-ai-sdkat1.3.7to match the existing@assistant-ui/react@0.12.10runtime.How It Works
apps/mcp-lecturerandapps/mcp-studentcommunicating over streamable HTTP.APP_SECRET.Branch Coverage
v3(viav3-ai)8e0c851b9aapps/mcp-lecturer,apps/mcp-student,apps/chatintegration, and build setup refactoring.Verification
Current head (
8e0c851b9a):pnpm --filter @klicker-uzh/mcp-lecturer test-> 33/33 tests passedpnpm --filter @klicker-uzh/mcp-student test-> 23/23 tests passedpnpm --filter @klicker-uzh/mcp-lecturer smoke:local --dry-run-> successfully runs and prints configpnpm --filter @klicker-uzh/mcp-student smoke:local --dry-run-> successfully runs and prints configEarlier branch verification:
pnpm run build-> all 32 workspace packages built successfullycheck:all-> formatted and lint-checkedSecurity / Privacy
Manual Verification Before Merge
./_run_app_dependencies.sh localpnpm --filter @klicker-uzh/mcp-lecturer devpnpm --filter @klicker-uzh/mcp-student devpnpm --filter @klicker-uzh/mcp-lecturer dev -- pnpm run smoke:localpnpm --filter @klicker-uzh/mcp-student dev -- pnpm run smoke:localClickUp Links