Skip to content

Add Frontend Event Listeners for MCP Real-Time UI Updates - #328

Merged
malibio merged 2 commits into
mainfrom
feature/issue-326-mcp-realtime-ui-updates
Oct 22, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-326-mcp-realtime-ui-updates

Conversation

@malibio

@malibio malibio commented Oct 21, 2025

Copy link
Copy Markdown
Collaborator

Closes #326

malibio and others added 2 commits October 22, 2025 01:38
## 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
malibio merged commit b250d9b into main Oct 22, 2025
@malibio
malibio deleted the feature/issue-326-mcp-realtime-ui-updates branch October 22, 2025 00:03
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]>
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.

Add Frontend Event Listeners for MCP Real-Time UI Updates

1 participant