Skip to content

Make MCP server graph state mutable (TVar) #5

@jeremiepas

Description

@jeremiepas

Problem

The MCP server loads the graph once at startup. Conversations added via add_conversation are saved to disk but NOT reflected in the in-memory Graph. New memories are invisible within the same session.

Solution

Replace the immutable Graph value with a MemoryAgentState containing TVar fields:

data MemoryAgentState = MemoryAgentState
  { masGraph      :: TVar Graph
  , masIndex      :: TVar GraphIndex
  , masCommMap    :: TVar CommunityMap
  , masAnalysis   :: TVar Analysis
  , masConvs      :: TVar [ConversationNode]
  , masDirty      :: TVar Bool
  , masMutationCount :: TVar Int
  }

All MCP handlers read from TVars. add_conversation updates TVars atomically via STM.

Acceptance Criteria

  • add_conversation creates a node visible in select_context immediately
  • conversation_history returns conversations added in current session
  • select_context with include_history=true includes new conversations
  • Thread-safe: concurrent MCP requests don't corrupt state

Files to Modify

  • src/Graphos/Infrastructure/Server/MCP.hs
  • src/Graphos/Domain/Context.hs (no changes needed, types already complete)

Effort: 2-3 days

Priority: Critical (blocks all other memory agent work)

See: docs/proposals/memory-agent/03-architecture.md (Spec 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmemory-agentMemory agent capabilitiesphase-1Phase 1: Mutable Graph + Persistence

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions