feat: Implement machine ID override for session continuity and add tests for create() function#234
Conversation
…sts for create() function
📝 WalkthroughWalkthroughAdds a flat-config Direct MCP server factory with instance caching and optional machineId override, a new server-side Changes
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>
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>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.
Performance Test ResultsStatus: ✅ All tests passed Summary
Total: 100 tests across 21 projects 📊 View full report in workflow run Generated at: 2026-02-05T02:51:11.306Z |
Summary by CodeRabbit
New Features
Tests