Skip to content

feat: Implement machine ID override for session continuity and add tests for create() function#234

Merged
frontegg-david merged 2 commits intomainfrom
support-one-command-run
Feb 5, 2026
Merged

feat: Implement machine ID override for session continuity and add tests for create() function#234
frontegg-david merged 2 commits intomainfrom
support-one-command-run

Conversation

@frontegg-david
Copy link
Contributor

@frontegg-david frontegg-david commented Feb 5, 2026

Summary by CodeRabbit

  • New Features

    • Direct server factory with flat configuration, lifecycle-aware caching, and cache clearing.
    • Process-wide machine ID override to support stable session continuity.
    • DirectMcpServer.connect() to establish client sessions with optional session IDs.
  • Tests

    • End-to-end tests for server creation, multi-client connectivity, session isolation, and lifecycle.
    • Unit tests for factory behavior, caching semantics, machine-id handling, and connect() behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Adds a flat-config Direct MCP server factory with instance caching and optional machineId override, a new server-side connect() method to instantiate Direct clients, and comprehensive unit and E2E tests covering config building, caching, lifecycle, and multi-client workflows.

Changes

Cohort / File(s) Summary
Machine ID
libs/sdk/src/auth/machine-id.ts
Added setMachineIdOverride(id?: string) and made getMachineId() return the override when set; added docs.
Direct create factory & types
libs/sdk/src/direct/create.ts, libs/sdk/src/direct/create.types.ts
New create(config) factory with global cache keyed by cacheKey, buildConfig() helper, dynamic machineId injection, and clearCreateCache(); added CreateConfig type for flat inputs.
Direct server client API
libs/sdk/src/direct/direct-server.ts, libs/sdk/src/direct/direct.types.ts
Added `connect(sessionIdOrOptions?: string
Tests
libs/sdk/src/direct/__tests__/create.spec.ts, libs/sdk/src/direct/__tests__/create-e2e.spec.ts, libs/sdk/src/direct/__tests__/direct-server.spec.ts
New unit and E2E tests for create factory (config, caching, lifecycle), machineId override behavior, server connect() semantics, multi-client sessions, and server lifecycle/restart scenarios.
Exports / surface
libs/sdk/src/direct/index.ts, libs/sdk/src/index.ts
Exported create, clearCreateCache, and CreateConfig from direct module and root SDK index to expose new factory and types.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Code
    participant Factory as create()
    participant Builder as buildConfig()
    participant FrontMCP as FrontMcpInstance
    participant Server as DirectMcpServer

    Client->>Factory: create(config)
    Factory->>Factory: Check instanceCache
    Factory->>Builder: buildConfig(config)
    Builder->>Builder: Create synthetic app and attach metadata
    Builder-->>Factory: FrontMcpConfigInput
    Factory->>Factory: Optional setMachineIdOverride()
    Factory->>FrontMCP: createDirect(fullConfig)
    FrontMCP->>Server: Instantiate & initialize
    FrontMCP-->>Factory: Promise<DirectMcpServer>
    Factory->>Factory: Cache with cacheKey
    Factory-->>Client: Promise<DirectMcpServer>
Loading
sequenceDiagram
    participant AppCode as App Code
    participant Server as DirectMcpServer
    participant ClientImpl as DirectClientImpl
    participant Client as DirectClient

    AppCode->>Server: connect(sessionId)
    Server->>Server: Validate not disposed
    Server->>Server: Normalize to ConnectOptions
    Server->>ClientImpl: Dynamic import
    Server->>ClientImpl: create(scope, options)
    ClientImpl->>Client: Instantiate with scope & options
    ClientImpl-->>Server: DirectClient
    Server-->>AppCode: Promise<DirectClient>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I stitched a flat config seam,

servers wake and share a dream;
clients hop in, sessions glide,
machine IDs hold through the tide.
Caches hum and tests applaud—hip-hop!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: introducing machine ID override mechanism for session continuity and adding comprehensive test suites for the create() factory function.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 65.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch support-one-command-run

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@libs/sdk/src/direct/__tests__/create.spec.ts`:
- Around line 15-25: The mockServer object is missing the required connect()
method from the DirectMcpServer interface; add a connect:
jest.fn().mockResolvedValue(<DirectClient>) (or an async function returning a
DirectClient stub) to the mockServer definition so it satisfies the
DirectMcpServer type, ensuring the method signature returns
Promise<DirectClient> and referencing the existing mockServer, DirectMcpServer
and DirectClient symbols when implementing the stub.

In `@libs/sdk/src/direct/create.ts`:
- Around line 139-143: The config.machineId override is being applied in
create() via setMachineIdOverride but never restored, making the override
process-global; update create() to scope the override by importing the
machine-id utilities, capture the current value with getMachineId() (or
equivalent), call setMachineIdOverride(config.machineId) before server
construction, then restore the original value with
setMachineIdOverride(previousValue) (or undefined) immediately after the server
is created so subsequent getMachineId() calls are unaffected.
🧹 Nitpick comments (1)
libs/sdk/src/direct/__tests__/create-e2e.spec.ts (1)

92-96: Use MCP error class instead of generic Error in the test guard.
Keep error handling consistent with SDK conventions even in tests.

♻️ Suggested change
 import { z } from 'zod';
+import { InternalMcpError } from '../../errors';
@@
-    if (!echoTool) throw new Error('echoTool not found');
+    if (!echoTool) throw new InternalMcpError('echoTool not found');

As per coding guidelines: Use specific error classes with MCP error codes instead of generic errors.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Performance Test Results

Status: ✅ All tests passed

Summary

Project Tests Passed Warnings Failed Leaks
✅ demo-e2e-agents 4 4 0 0 0
✅ demo-e2e-cache 11 11 0 0 0
✅ demo-e2e-codecall 4 4 0 0 0
✅ demo-e2e-config 4 4 0 0 0
✅ demo-e2e-direct 3 3 0 0 0
✅ demo-e2e-elicitation 1 1 0 0 0
✅ demo-e2e-errors 4 4 0 0 0
✅ demo-e2e-hooks 3 3 0 0 0
✅ demo-e2e-multiapp 4 4 0 0 0
✅ demo-e2e-notifications 3 3 0 0 0
✅ demo-e2e-openapi 2 2 0 0 0
✅ demo-e2e-providers 4 4 0 0 0
✅ demo-e2e-public 4 4 0 0 0
✅ demo-e2e-redis 14 14 0 0 0
✅ demo-e2e-remember 4 4 0 0 0
✅ demo-e2e-remote 5 5 0 0 0
✅ demo-e2e-serverless 2 2 0 0 0
✅ demo-e2e-skills 15 15 0 0 0
✅ demo-e2e-standalone 2 2 0 0 0
✅ demo-e2e-transport-recreation 3 3 0 0 0
✅ demo-e2e-ui 4 4 0 0 0

Total: 100 tests across 21 projects

📊 View full report in workflow run


Generated at: 2026-02-05T02:51:11.306Z
Commit: c48eeff4

@frontegg-david frontegg-david merged commit d6e9cf8 into main Feb 5, 2026
58 checks passed
@frontegg-david frontegg-david deleted the support-one-command-run branch February 5, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant