Skip to content

Refactor MCP server as managed service and enable browser mode support #715

Closed

Description

@malibio

Refactor MCP server as managed service and enable browser mode support

Summary

Refactor MCP server to be a managed Tauri service (like NodeService, EmbeddingService) and create a standalone dev-mcp binary for browser mode development, enabling AI agent integration across both development modes.

Current State

Tauri Mode:

  • MCP server spawned as background task via initialize_mcp_server() after database init
  • Works correctly but not structured as a managed service
  • Inconsistent with other services (NodeService, Embedding Service, etc.)

Browser Mode:

  • NO MCP server available
  • AI agents cannot connect during browser development
  • Limits ability to test MCP integration

Proposed Changes

Phase 1: Refactor MCP to Managed Service (Tauri Mode)

  1. Create McpServerService (src-tauri/src/services/mcp_server_service.rs):

    pub struct McpServerService {
        node_service: Arc<NodeService>,
        embedding_service: Arc<NodeEmbeddingService>,
        port: u16,
        // Potential future: health status, metrics, connection count
    }
    
    impl McpServerService {
        pub fn new(...) -> Self { ... }
        pub fn start(&self) -> anyhow::Result<()> { ... }
        pub fn port(&self) -> u16 { ... }
    }
  2. Register as managed service in commands/db.rs::init_services():

    let mcp_service = McpServerService::new(...);
    mcp_service.start()?;
    app.manage(mcp_service);
  3. Remove lib.rs::initialize_mcp_server() (functionality moved to service)

  4. Move core logic from mcp_integration.rs to new service module

Phase 2: Enable Browser Mode MCP

  1. Create dev-mcp binary (src-tauri/src/bin/dev-mcp.rs):

    • Similar structure to dev-proxy.rs
    • Connects to SurrealDB HTTP server (port 8000)
    • Initializes NodeService and EmbeddingService
    • Starts MCP server on port 3100
  2. Add npm script in packages/desktop-app/package.json:

    "dev:browser:mcp": "cd src-tauri && cargo run --bin dev-mcp"
  3. Update dev:browser concurrently command:

    "dev:browser": "concurrently 'bun run dev:browser:db' 'sleep 2 && bun run dev:browser:proxy' 'sleep 2 && bun run dev:browser:mcp' 'sleep 4 && bun run dev:browser:frontend'"

Benefits

✅ Unified architecture across browser and Tauri modes
✅ Consistent service pattern (all services managed the same way)
✅ Better testability (MCP can be tested independently)
✅ Lifecycle control (potential for start/stop/restart methods)
✅ Browser mode MCP (AI agents can connect during development)
✅ Future-ready (easier to add health checks, metrics, etc.)

Technical Details

Port Configuration:

  • Uses MCP_PORT environment variable (defaults to 3100)
  • No conflicts with dev-proxy (3001) or SurrealDB (8000)

State Sharing:

  • Both dev-proxy and dev-mcp share NodeService (different Arc instances, same DB)
  • MCP is stateless (no SSE subscription needed - queries fresh from NodeService)
  • dev-proxy handles SSE for browser real-time sync

Event Propagation:

  • NodeService emits domain events
  • dev-proxy's SSE handler forwards to browser
  • MCP queries return fresh data (stateless request/response)

Acceptance Criteria

  • McpServerService created in src-tauri/src/services/ module
  • MCP registered as managed service in init_services()
  • initialize_mcp_server() function removed from lib.rs
  • dev-mcp binary created in src-tauri/src/bin/
  • Browser mode launches MCP server automatically
  • MCP server accessible on port 3100 in both modes
  • AI agents can connect in browser mode
  • Existing Tauri mode MCP functionality unchanged
  • Tests pass (existing MCP integration tests still work)
  • Documentation updated (architecture docs, development guide)

Labels

refactoring, mcp, architecture, developer-experience

Activity

  1. self-assigned this
    on Dec 2, 2025
  2. added 8 commits that reference this issue on Dec 2, 2025
    e0df44b
    a6a6a8f
    89698af
    27b7c63
    5400398
    38fa725
    715ab3e
    81f4ae8
  3. malibio commented on Dec 2, 2025

    @malibio
    CollaboratorAuthor

    Session Update - WIP Commit 81f4ae8

    Fixed Svelte reactive loops and began SSE filtering fixes.

    Completed:

    • ✅ Fixed effect_update_depth_exceeded error in TaskSchemaForm
    • ✅ Fixed excessive re-renders in SchemaPropertyForm ( pattern issue)
    • ✅ Partial SSE filtering in domain event bridge (NodeCreated, NodeUpdated, NodeDeleted)

    Remaining:

    • Complete SSE filtering for EdgeCreated/EdgeDeleted events
    • Remove duplicate SSE broadcasts from HTTP handlers (they bypass the filter)
    • Consider proper fix: NodeService-level subscriber filtering (this is 3rd occurrence of this bug)

    Current Issue:
    Task status toggle shows update briefly then reverts - browser receiving own changes via SSE despite filtering attempt.

  4. added a commit that references this issue on Dec 3, 2025
    032fec7
  5. added 2 commits that reference this issue on Feb 4, 2026
    85e7368
    0008864
  6. added a commit that references this issue on Feb 26, 2026
    3d6af32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions