LearnNewsExamplesServices
Frontmatter
id9563
titleModularize MCP Server Architecture and Extract Shared Services
stateClosed
labels
enhancementairefactoringarchitecture
assigneestobiu
createdAtMar 26, 2026, 4:04 PM
updatedAtMar 26, 2026, 4:11 PM
githubUrlhttps://github.com/neomjs/neo/issues/9563
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMar 26, 2026, 4:11 PM

Modularize MCP Server Architecture and Extract Shared Services

Closed v12.1.0 enhancementairefactoringarchitecture
tobiu
tobiu commented on Mar 26, 2026, 4:04 PM

Goal

Refactor the MCP server root files (Server.mjs) to reduce bloat by extracting optional and complex logic into dedicated services.

Context

With the recent addition of OIDC/OAuth 2.1 discovery, token verification, and CORS support, the Server.mjs files for Knowledge Base and Memory Core have become less readable. Since this logic is identical across servers, it should be extracted into shared services.

Proposed Changes

  1. Extract Auth Logic: Create ai/mcp/server/shared/services/AuthService.mjs to handle OIDC discovery, token verification, and Protected Resource Metadata.
  2. Extract SSE Logic: Create ai/mcp/server/shared/services/TransportService.mjs to manage Express apps, CORS, SSE transport handshakes, and session management.
  3. Modular Server: Update Server.mjs to use dynamic imports for these services, keeping the root file lean and ensuring dependencies are only loaded when needed.
  4. Consolidate Common Logic: Ensure that future MCP servers can leverage these same services for rapid and consistent deployment.

This refactoring will improve maintainability and simplify the implementation of future features like the Neural Link authorization.

tobiu added the enhancement label on Mar 26, 2026, 4:04 PM
tobiu added the ai label on Mar 26, 2026, 4:04 PM
tobiu added the refactoring label on Mar 26, 2026, 4:04 PM
tobiu added the architecture label on Mar 26, 2026, 4:04 PM
tobiu referenced in commit 8b4254a - "Modularize MCP server architecture and extract shared services (#9563)" on Mar 26, 2026, 4:11 PM
tobiu assigned to @tobiu on Mar 26, 2026, 4:11 PM
tobiu closed this issue on Mar 26, 2026, 4:11 PM
tobiu
tobiu Mar 26, 2026, 4:11 PM

Refactored Server.mjs by extracting OIDC/OAuth and SSE transport logic into shared AuthService and TransportService. Improved maintainability and reduced root file bloat. Verified with functional tests.

tobiu referenced in commit cd957a3 - "Apply Anchor & Echo strategy to MCP services and tests (#9563)" on Mar 26, 2026, 4:15 PM