Repository navigation
Add Frontend Event Listeners for MCP Real-Time UI Updates - #328
Merged
Merged
Conversation
## Changes
### Phase 1: Update Rust Event Payloads
- Modified `NodeCreatedEvent` to include full `Node` data instead of just ID and type
- Updated `emit_event_for_method()` to deserialize full Node from MCP results
- `create_node` and `create_nodes_from_markdown` now emit complete Node objects
- `update_node` uses hybrid approach (emits node_id, frontend fetches)
- `delete_node` remains unchanged (only needs node_id)
### Phase 2: Add Frontend Event Listeners
- Added MCP event listeners in `app-shell.svelte`
- Listen to `node-created`, `node-updated`, and `node-deleted` events
- Integrated with `SharedNodeStore` for reactive UI updates
- Used `UpdateSource` type `'mcp-server'` for proper source tracking
- Added proper cleanup for all event listeners on unmount
### Phase 3: Integration with SharedNodeStore
- Verified `SharedNodeStore.getInstance()` method exists
- Used `setNode()` for create/update events
- Used `deleteNode()` for delete events
- Followed hybrid approach for updates (frontend fetches full node via `get_node`)
## Technical Details
**Rust Changes:**
- Event payloads now include full Node data for instant UI updates
- No extra database fetch needed for create operations
- Proper error handling with warning logs for deserialization failures
**Frontend Changes:**
- Event listeners only initialized in Tauri environment
- Async handling for node updates with proper error logging
- Source tracking via `{ type: 'mcp-server' }` for conflict resolution
- All listeners properly cleaned up on component unmount
## Testing
- Rust compilation verified with `cargo check`
- All quality checks passed (`bun run quality:fix`)
- Ready for end-to-end testing with Claude Code
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Implemented all code review recommendations including nitpicks: ## Changes ### 1. Remove Unnecessary Clone (Rust) - Removed redundant `node.clone()` in mcp_integration.rs line 108 - `NodeCreatedEvent` takes ownership, so clone was unnecessary - Updated error logging to use `event.node.id` instead of moved `node.id` ### 2. Extract MCP Event Listener Setup (Frontend) - Created `setupMCPListeners()` function in app-shell.svelte - Improves readability by separating MCP listener setup from main onMount - Enhances testability - listener setup can now be tested independently - Returns cleanup function for proper resource management - Reduces complexity in onMount (now ~100 lines instead of 160+) ### 3. Add Event Type Constants - Created new `src/lib/constants/mcp-events.ts` module - Defines `MCP_EVENTS` constant with all event type strings - Prevents typos in event names (type-safe string literals) - Centralizes event types for easier refactoring - Added comprehensive JSDoc documentation - Updated app-shell.svelte to use constants instead of hardcoded strings - Created barrel export in `src/lib/constants/index.ts` ## Benefits **Code Quality:** - Better separation of concerns - Improved maintainability - Enhanced type safety - Easier to add new MCP event types **Performance:** - No performance impact (constants are compile-time) - Removed unnecessary clone operation in Rust **Testability:** - MCP listener setup can be tested in isolation - Constants ensure consistent event naming across tests ## Files Modified - `packages/desktop-app/src-tauri/src/mcp_integration.rs` - Remove clone - `packages/desktop-app/src/lib/components/layout/app-shell.svelte` - Extract function, use constants - `packages/desktop-app/src/lib/constants/mcp-events.ts` - New constants file - `packages/desktop-app/src/lib/constants/index.ts` - New barrel export 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 4, 2026
* feat: Add frontend event listeners for MCP real-time UI updates (#326) ## Changes ### Phase 1: Update Rust Event Payloads - Modified `NodeCreatedEvent` to include full `Node` data instead of just ID and type - Updated `emit_event_for_method()` to deserialize full Node from MCP results - `create_node` and `create_nodes_from_markdown` now emit complete Node objects - `update_node` uses hybrid approach (emits node_id, frontend fetches) - `delete_node` remains unchanged (only needs node_id) ### Phase 2: Add Frontend Event Listeners - Added MCP event listeners in `app-shell.svelte` - Listen to `node-created`, `node-updated`, and `node-deleted` events - Integrated with `SharedNodeStore` for reactive UI updates - Used `UpdateSource` type `'mcp-server'` for proper source tracking - Added proper cleanup for all event listeners on unmount ### Phase 3: Integration with SharedNodeStore - Verified `SharedNodeStore.getInstance()` method exists - Used `setNode()` for create/update events - Used `deleteNode()` for delete events - Followed hybrid approach for updates (frontend fetches full node via `get_node`) ## Technical Details **Rust Changes:** - Event payloads now include full Node data for instant UI updates - No extra database fetch needed for create operations - Proper error handling with warning logs for deserialization failures **Frontend Changes:** - Event listeners only initialized in Tauri environment - Async handling for node updates with proper error logging - Source tracking via `{ type: 'mcp-server' }` for conflict resolution - All listeners properly cleaned up on component unmount ## Testing - Rust compilation verified with `cargo check` - All quality checks passed (`bun run quality:fix`) - Ready for end-to-end testing with Claude Code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Apply code review improvements for MCP event handling Implemented all code review recommendations including nitpicks: ## Changes ### 1. Remove Unnecessary Clone (Rust) - Removed redundant `node.clone()` in mcp_integration.rs line 108 - `NodeCreatedEvent` takes ownership, so clone was unnecessary - Updated error logging to use `event.node.id` instead of moved `node.id` ### 2. Extract MCP Event Listener Setup (Frontend) - Created `setupMCPListeners()` function in app-shell.svelte - Improves readability by separating MCP listener setup from main onMount - Enhances testability - listener setup can now be tested independently - Returns cleanup function for proper resource management - Reduces complexity in onMount (now ~100 lines instead of 160+) ### 3. Add Event Type Constants - Created new `src/lib/constants/mcp-events.ts` module - Defines `MCP_EVENTS` constant with all event type strings - Prevents typos in event names (type-safe string literals) - Centralizes event types for easier refactoring - Added comprehensive JSDoc documentation - Updated app-shell.svelte to use constants instead of hardcoded strings - Created barrel export in `src/lib/constants/index.ts` ## Benefits **Code Quality:** - Better separation of concerns - Improved maintainability - Enhanced type safety - Easier to add new MCP event types **Performance:** - No performance impact (constants are compile-time) - Removed unnecessary clone operation in Rust **Testability:** - MCP listener setup can be tested in isolation - Constants ensure consistent event naming across tests ## Files Modified - `packages/desktop-app/src-tauri/src/mcp_integration.rs` - Remove clone - `packages/desktop-app/src/lib/components/layout/app-shell.svelte` - Extract function, use constants - `packages/desktop-app/src/lib/constants/mcp-events.ts` - New constants file - `packages/desktop-app/src/lib/constants/index.ts` - New barrel export 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 5, 2026
* feat: Add frontend event listeners for MCP real-time UI updates (#326) ## Changes ### Phase 1: Update Rust Event Payloads - Modified `NodeCreatedEvent` to include full `Node` data instead of just ID and type - Updated `emit_event_for_method()` to deserialize full Node from MCP results - `create_node` and `create_nodes_from_markdown` now emit complete Node objects - `update_node` uses hybrid approach (emits node_id, frontend fetches) - `delete_node` remains unchanged (only needs node_id) ### Phase 2: Add Frontend Event Listeners - Added MCP event listeners in `app-shell.svelte` - Listen to `node-created`, `node-updated`, and `node-deleted` events - Integrated with `SharedNodeStore` for reactive UI updates - Used `UpdateSource` type `'mcp-server'` for proper source tracking - Added proper cleanup for all event listeners on unmount ### Phase 3: Integration with SharedNodeStore - Verified `SharedNodeStore.getInstance()` method exists - Used `setNode()` for create/update events - Used `deleteNode()` for delete events - Followed hybrid approach for updates (frontend fetches full node via `get_node`) ## Technical Details **Rust Changes:** - Event payloads now include full Node data for instant UI updates - No extra database fetch needed for create operations - Proper error handling with warning logs for deserialization failures **Frontend Changes:** - Event listeners only initialized in Tauri environment - Async handling for node updates with proper error logging - Source tracking via `{ type: 'mcp-server' }` for conflict resolution - All listeners properly cleaned up on component unmount ## Testing - Rust compilation verified with `cargo check` - All quality checks passed (`bun run quality:fix`) - Ready for end-to-end testing with Claude Code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Apply code review improvements for MCP event handling Implemented all code review recommendations including nitpicks: ## Changes ### 1. Remove Unnecessary Clone (Rust) - Removed redundant `node.clone()` in mcp_integration.rs line 108 - `NodeCreatedEvent` takes ownership, so clone was unnecessary - Updated error logging to use `event.node.id` instead of moved `node.id` ### 2. Extract MCP Event Listener Setup (Frontend) - Created `setupMCPListeners()` function in app-shell.svelte - Improves readability by separating MCP listener setup from main onMount - Enhances testability - listener setup can now be tested independently - Returns cleanup function for proper resource management - Reduces complexity in onMount (now ~100 lines instead of 160+) ### 3. Add Event Type Constants - Created new `src/lib/constants/mcp-events.ts` module - Defines `MCP_EVENTS` constant with all event type strings - Prevents typos in event names (type-safe string literals) - Centralizes event types for easier refactoring - Added comprehensive JSDoc documentation - Updated app-shell.svelte to use constants instead of hardcoded strings - Created barrel export in `src/lib/constants/index.ts` ## Benefits **Code Quality:** - Better separation of concerns - Improved maintainability - Enhanced type safety - Easier to add new MCP event types **Performance:** - No performance impact (constants are compile-time) - Removed unnecessary clone operation in Rust **Testability:** - MCP listener setup can be tested in isolation - Constants ensure consistent event naming across tests ## Files Modified - `packages/desktop-app/src-tauri/src/mcp_integration.rs` - Remove clone - `packages/desktop-app/src/lib/components/layout/app-shell.svelte` - Extract function, use constants - `packages/desktop-app/src/lib/constants/mcp-events.ts` - New constants file - `packages/desktop-app/src/lib/constants/index.ts` - New barrel export 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 26, 2026
* feat: Add frontend event listeners for MCP real-time UI updates (#326) ## Changes ### Phase 1: Update Rust Event Payloads - Modified `NodeCreatedEvent` to include full `Node` data instead of just ID and type - Updated `emit_event_for_method()` to deserialize full Node from MCP results - `create_node` and `create_nodes_from_markdown` now emit complete Node objects - `update_node` uses hybrid approach (emits node_id, frontend fetches) - `delete_node` remains unchanged (only needs node_id) ### Phase 2: Add Frontend Event Listeners - Added MCP event listeners in `app-shell.svelte` - Listen to `node-created`, `node-updated`, and `node-deleted` events - Integrated with `SharedNodeStore` for reactive UI updates - Used `UpdateSource` type `'mcp-server'` for proper source tracking - Added proper cleanup for all event listeners on unmount ### Phase 3: Integration with SharedNodeStore - Verified `SharedNodeStore.getInstance()` method exists - Used `setNode()` for create/update events - Used `deleteNode()` for delete events - Followed hybrid approach for updates (frontend fetches full node via `get_node`) ## Technical Details **Rust Changes:** - Event payloads now include full Node data for instant UI updates - No extra database fetch needed for create operations - Proper error handling with warning logs for deserialization failures **Frontend Changes:** - Event listeners only initialized in Tauri environment - Async handling for node updates with proper error logging - Source tracking via `{ type: 'mcp-server' }` for conflict resolution - All listeners properly cleaned up on component unmount ## Testing - Rust compilation verified with `cargo check` - All quality checks passed (`bun run quality:fix`) - Ready for end-to-end testing with Claude Code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Apply code review improvements for MCP event handling Implemented all code review recommendations including nitpicks: ## Changes ### 1. Remove Unnecessary Clone (Rust) - Removed redundant `node.clone()` in mcp_integration.rs line 108 - `NodeCreatedEvent` takes ownership, so clone was unnecessary - Updated error logging to use `event.node.id` instead of moved `node.id` ### 2. Extract MCP Event Listener Setup (Frontend) - Created `setupMCPListeners()` function in app-shell.svelte - Improves readability by separating MCP listener setup from main onMount - Enhances testability - listener setup can now be tested independently - Returns cleanup function for proper resource management - Reduces complexity in onMount (now ~100 lines instead of 160+) ### 3. Add Event Type Constants - Created new `src/lib/constants/mcp-events.ts` module - Defines `MCP_EVENTS` constant with all event type strings - Prevents typos in event names (type-safe string literals) - Centralizes event types for easier refactoring - Added comprehensive JSDoc documentation - Updated app-shell.svelte to use constants instead of hardcoded strings - Created barrel export in `src/lib/constants/index.ts` ## Benefits **Code Quality:** - Better separation of concerns - Improved maintainability - Enhanced type safety - Easier to add new MCP event types **Performance:** - No performance impact (constants are compile-time) - Removed unnecessary clone operation in Rust **Testability:** - MCP listener setup can be tested in isolation - Constants ensure consistent event naming across tests ## Files Modified - `packages/desktop-app/src-tauri/src/mcp_integration.rs` - Remove clone - `packages/desktop-app/src/lib/components/layout/app-shell.svelte` - Extract function, use constants - `packages/desktop-app/src/lib/constants/mcp-events.ts` - New constants file - `packages/desktop-app/src/lib/constants/index.ts` - New barrel export 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #326