How We Achieved Sub-Millisecond Multi-Agent Sync: The Spector MCP Protocol in Action

Spector MCP Sync

When building complex applications using AI agents, you quickly hit a coordination bottleneck. If you run multiple agents concurrently—say, a researcher, a writer, and a quality reviewer—how do they share state?

Passing the entire chat history back and forth bloats your prompt tokens and drives up API costs. Syncing state via traditional databases adds database round-trips and introduces latency.

To solve this, we integrated Spector with the Model Context Protocol (MCP). MCP provides a standard open-source protocol for models to access tools and resources. By turning Spector into an MCP memory server, we enabled sub-millisecond memory read/writes and seamless state sharing across completely independent agents.


1. The MCP Shared State Architecture

In our architecture, the Spector MCP server acts as a centralized "blackboard" for all running agents. Instead of serializing and deserializing context locally, agents read and write from Spector's low-level off-heap memory through standard JSON-RPC over stdin/stdout or SSE (Server-Sent Events).

sequenceDiagram participant A as Agent 1 (Researcher) participant S as Spector MCP Server participant B as Agent 2 (Writer) A->>S: Write Episode (JSON-RPC) Note over S: Low-level SMKM Write
(Sub-millisecond) S-->>A: Ack B->>S: Recall Memory (synaptic_filter="research") S-->>B: Recalled Episodic Context

Because Spector stores these memories off-heap using Project Panama's memory segments, we avoid standard Java Garbage Collection (GC) pauses entirely. Read and write operations execute in micro-seconds, ensuring the synchronization step never blocks agent pipelines.


2. Setting Up the Spector MCP Server

Integrating Spector into your agent environment is simple. First, define the server configuration in your local MCP settings file (e.g., mcp-config.json for cursor/Claude Desktop or your custom runner):

{
  "mcpServers": {
    "spector-memory": {
      "command": "java",
      "args": [
        "-jar",
        "/path/to/spector-mcp-server.jar",
        "--port", "8080",
        "--db-path", "/var/lib/spector/memory"
      ]
    }
  }
}

Once running, the Spector MCP server exposes two core tools:

  1. memory_remember: Saves episodic or semantic memories with associated metadata tags, valence, and importance weights.
  2. memory_recall: Queries memories using a combination of semantic vector search, spreading activation, and tag filters.

3. Real-world Code Example: Node.js MCP Integration

Here is a simple snippet showing how to use the @modelcontextprotocol/sdk to write a memory episode from an active agent:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const transport = new StdioClientTransport({
  command: "java",
  args: ["-jar", "spector-mcp-server.jar"]
});

const client = new Client({
  name: "agent-coordinator",
  version: "1.0.0"
});

await client.connect(transport);

// Store a shared state memory
await client.callTool({
  name: "memory_remember",
  arguments: {
    text: "User requested Q3 database migration script to use PostgreSQL instead of MySQL.",
    tier: "EPISODIC",
    source: "USER_STATED",
    tags: "database,migration,postgres",
    interest: 0.9,
    urgency: 0.8
  }
});
console.log("Memory successfully synchronized!");

By leveraging this decoupled memory server, you ensure that every agent has a consistent, low-latency source of truth without bloating prompt templates.