---
id: 11224
title: Migrate memory-core services to flatter SDK structure (M6 MC)
state: CLOSED
labels:
  - enhancement
  - ai
  - architecture
assignees:
  - neo-gemini-pro
createdAt: '2026-05-11T16:56:58Z'
updatedAt: '2026-05-12T02:08:02Z'
githubUrl: 'https://github.com/neomjs/neo/issues/11224'
author: neo-gemini-pro
commentsCount: 0
parentIssue: 10982
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-05-12T02:00:23Z'
---
# Migrate memory-core services to flatter SDK structure (M6 MC)

# Migrate memory-core services to flatter SDK structure (M6 MC)

## Context
Second Tier-1 sub-ticket of M6 epic #10982. Memory Core server: 417 LOC `Server.mjs`, ~14 services + `lifecycle/` subdirectories. This is the **largest substantive M6 lift**. It follows the pattern established in the M6 KB sub-ticket (#10983).

## The Problem
Memory Core services live under `ai/mcp/server/memory-core/services/` and are imported into `ai/services.mjs` via that path. Per M6 design (`v13-path.md` §4 + D4), services flatten into the SDK structure; `Server.mjs` shrinks from 417 LOC → <50 LOC thin endpoint wrapper consuming services via the SDK. 

## The Architectural Reality
MC service inventory (approximate):
```
ai/mcp/server/memory-core/services/
├── EdgeGraphService.mjs
├── GraphService.mjs
├── MemoryService.mjs
├── PermissionService.mjs
├── SessionService.mjs
├── SummarizationService.mjs
├── TaskService.mjs
├── ... (and lifecycle subdirs)
```
Current `ai/services.mjs` imports use `Memory_*` namespace prefixes. Preserving these post-migration is non-negotiable for SDK consumer compatibility.
`Server.mjs` (417 LOC) currently handles tool registration and service singleton wiring. Migration removes service singleton wiring (shifts to SDK) and leaves only tool registration + BaseServer extension boilerplate.

## The Fix
**Proposed SDK layout:**
```
ai/services/memory-core/
├── EdgeGraphService.mjs
├── GraphService.mjs
├── MemoryService.mjs
├── ... (other services + lifecycle subdirs)
```

Sequence:
1. **Move:** `git mv ai/mcp/server/memory-core/services/* ai/services/memory-core/`
2. **Update SDK imports:** Edit `ai/services.mjs` to point at new locations; preserve `Memory_*` prefixes verbatim.
3. **Update Server.mjs:** Edit `ai/mcp/server/memory-core/Server.mjs` to import services via `ai/services.mjs` rather than directly; remove local-services-singleton wiring.
4. **Shrink target:** `Server.mjs` <50 LOC. (Note: given the number of tools, it might be slightly larger, but the goal is to remove all service instantiations).
5. **Verify Factory pattern intact:** unit + integration suite passes; `RequestContextService.run` wraps dispatch unchanged.
6. **Capture LOC delta** in PR body per M6 epic AC7.

## Acceptance Criteria
- [ ] **AC1:** All MC services + lifecycle subdirectories relocated from `ai/mcp/server/memory-core/services/` to `ai/services/memory-core/`
- [ ] **AC2:** `ai/services.mjs` imports updated; `Memory_*` namespace prefixes preserved verbatim (no consumer-facing API change)
- [ ] **AC3:** `ai/mcp/server/memory-core/Server.mjs` shrunk to <50 LOC (or as close to tool-registration-only as possible)
- [ ] **AC4:** Cross-family review approval per swarm PR review routing (one peer review minimum)
- [ ] **AC5:** Unit row + integration row green on PR
- [ ] **AC6:** LOC delta captured in PR body (target: >30% LOC moved from MCP server tree → SDK tree per M6 epic AC7)

## Out of Scope
- Service-internal refactors (separate tickets if needed)
- Adding new MC tools or service surfaces
- BaseServer-extension regressions (out of scope; M2 substrate is stable)
- Other server migrations (separate sub-tickets per M6 epic)

## Avoided Traps / Gold Standards Rejected
- **Rejected: rename `Memory_*` namespace prefixes during migration.** Cascading breaking change for SDK consumers.
- **Rejected: flatten ALL way to `ai/services/*.mjs` (no per-domain subdir).** Risks namespace collisions across servers. Per-domain subdir resolves this without re-renaming.
- **Rejected: Bundle with other servers.** The MC migration is the largest lift and must be isolated per `feedback_substrate_scope_restraint`.

## Related
- **Parent:** #10982 (M6 epic — SDK migration per-server)
- **Strategic anchor:** `learn/agentos/v13-path.md` §4 M6 + D4
- **Pattern PR:** #10983 (M6 KB migration)
- **Sibling sub-tickets (forthcoming):** GH-WF, NL SDK migrations

Origin Session ID: 57502eb2-7f7b-4b9b-a849-49f016b08c95
Retrieval Hint: `query_raw_memories(query="MC memory-core SDK migration M6 v13 flatter service structure")`

## Timeline

- 2026-05-11T16:57:00Z @neo-gemini-pro added the `enhancement` label
- 2026-05-11T16:57:01Z @neo-gemini-pro added the `ai` label
- 2026-05-11T16:57:01Z @neo-gemini-pro added the `architecture` label
- 2026-05-11T16:57:01Z @neo-gemini-pro added the `release:v13` label
- 2026-05-11T16:57:09Z @neo-gemini-pro added parent issue #10982
- 2026-05-11T16:57:10Z @neo-gemini-pro assigned to @neo-gemini-pro
- 2026-05-11T17:35:54Z @neo-gemini-pro cross-referenced by PR #11225
- 2026-05-11T18:09:06Z @neo-gemini-pro referenced in commit `9d79e28` - "test(memory-core): make MailboxService.transitionTask validation regex resilient to Zod (#11224)"
- 2026-05-11T18:32:47Z @neo-gemini-pro referenced in commit `d73db38` - "test(memory-core): isolate MailboxService unit tests and restore McpIntegrationService JSDoc (#11224)"
- 2026-05-11T19:34:37Z @neo-gpt cross-referenced by PR #11227
- 2026-05-11T19:54:16Z @neo-gemini-pro cross-referenced by PR #11228
- 2026-05-11T21:42:52Z @neo-gemini-pro referenced in commit `0a394a7` - "test(grid): fix Pooling.spec.mjs scroll parameter for Fixed-DOM-Order validation (#11224)"
- 2026-05-12T02:00:24Z @tobiu referenced in commit `2aa16b2` - "feat(mc): enforce Zod-validated SDK perimeter (#11224) (#11228)

* feat(mc): enforce Zod-validated SDK perimeter (#11224)

* test(grid): fix Pooling.spec.mjs scroll parameter for Fixed-DOM-Order validation (#11224)

* fix(mcp): refactor ai/services.mjs to use Proxy wrappers for makeSafe (#11228)

- Prevents direct mutation of service instance prototypes which broke Neo.get and Neo.idMap bindings
- Fixes test/playwright/unit/ai/mcp/Authorization.spec.mjs configuration variables

* revert(test): drop unrelated grid Pooling test changes (#11228)

* revert(test): drop unrelated mcp Authorization test changes (#11228)

---------

Co-authored-by: neo-gemini-pro <neo-gemini-pro@users.noreply.github.com>"
- 2026-05-12T02:00:24Z @tobiu closed this issue
- 2026-05-12T02:08:02Z @neo-gemini-pro removed the `release:v13` label

