Repository navigation
Closed
Labels
bugSomething isn't workingmulti-agentMulti-agent backend support and agent-agnostic architectureplannedImplementation plan approved
Description
Context
#372 (MCP server) added @modelcontextprotocol/sdk as a dependency and serve.ts imports it eagerly at the top of bin/cli.ts (line 53). This means every npx sequant command (run, doctor, init, etc.) loads the MCP SDK — even when the user has no intention of using MCP.
When the SDK isn't installed (or fails to resolve), this produces:
- 14 TypeScript build errors on main
- 5 test failures on main
- Every feature branch that rebases/merges from main inherits the breakage
- QA constantly has to distinguish "pre-existing on main" vs "introduced by this PR"
This caused friction during #369 (Aider) QA and merge.
Problem Files
| File | Import Type | Impact |
|---|---|---|
bin/cli.ts:53 |
import { serveCommand } from "../src/commands/serve.js" |
Eager — breaks all CLI commands |
src/commands/serve.ts:10-11 |
import { StdioServerTransport, SSEServerTransport } |
Static — fails at import time |
src/mcp/server.ts:9 |
import { McpServer } |
Static — fails at import time |
src/mcp/tools/*.ts |
import type { McpServer } |
Type-only — OK at runtime, fails tsc |
src/commands/doctor.ts:497 |
await import("../mcp/server.js") |
Dynamic — already handles failure correctly |
Goal
Make the MCP SDK a truly optional dependency. npx sequant run and all non-MCP commands should work without the SDK installed.
Acceptance Criteria
-
bin/cli.tslazy-loadsserve.tsvia dynamicimport()inside the.action()handler -
npx sequant run,npx sequant doctor,npx sequant initwork without@modelcontextprotocol/sdkinstalled -
npx sequant servegives a clear error if SDK is not installed (not a cryptic import failure) -
npm run buildpasses without the SDK installed (type-only imports need conditional handling) - Tests pass without the SDK installed (MCP tests can be skipped with a guard)
-
doctorMCP health check continues to work (already uses dynamic import — verify)
Design
CLI entry point (bin/cli.ts)
// Before (eager):
import { serveCommand } from "../src/commands/serve.js";
program.command("serve").action(serveCommand);
// After (lazy):
program.command("serve").action(async (...args) => {
try {
const { serveCommand } = await import("../src/commands/serve.js");
return serveCommand(...args);
} catch (err) {
console.error("MCP server requires @modelcontextprotocol/sdk. Install: npm install @modelcontextprotocol/sdk");
process.exit(1);
}
});Type-only imports
import type is erased at runtime but fails tsc. Options:
- Move MCP types to a local
.d.tsfile that mirrors the SDK types - Use
// @ts-ignorewith a comment (not ideal) - Make SDK a
peerDependencywith"optional": true
Option 3 is cleanest.
Testing
- Remove
@modelcontextprotocol/sdkfromnode_modules, verify all non-MCP commands work - Verify
npx sequant servegives a clear error - Verify
npm run buildpasses
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingmulti-agentMulti-agent backend support and agent-agnostic architectureplannedImplementation plan approved
Activity
admarble commentedon Mar 23, 2026
Spec Plan — #396: Lazy-load MCP SDK
AC Checklist
bin/cli.tslazy-loadsserve.tsvia dynamicimport()sequant run/doctor/initwork without SDK installedsequant servegives clear error without SDKnpm run buildpasses without SDK installeddoctorMCP health check continues to workimport typestatements resolve via ambient declarationsImplementation Plan
Phase 1 — Lazy-load serve command (AC-1, AC-2, AC-3)
import { serveCommand }frombin/cli.ts.action(serveCommand)with async wrapper usingawait import()Phase 2 — Ambient type declarations (AC-4, AC-7)
4. Create
src/mcp/sdk-types.d.tswith ambient module declarations for SDK types5. Move
@modelcontextprotocol/sdkfromdependenciestopeerDependencies(optional)Phase 3 — Test guards (AC-5)
6. Add
describe.skipIf()guard toserver.test.tsandserver-extended.test.tsPhase 4 — Verify (AC-6)
7. Confirm
doctor.tsdynamic import still works (no changes needed)Non-Goals
Scope
✅ SCOPE_OK — Single focused fix, 3 directories, 6 AC items
Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
fix(#396): lazy-load MCP SDK to prevent build failures when not insta…
admarble commentedon Mar 23, 2026
/fullsolve Complete
Issue: #396
Status: READY_FOR_MERGE
AC Coverage
bin/cli.tslazy-loadsserve.tsvia dynamicimport()sequant run/doctor/initwork without SDK installedsequant servegives clear error if SDK missingnpm run buildpasses without SDK installeddoctorMCP health check continues to workKey Changes
bin/cli.ts: Removed static import, added lazy-load in.action()handlersrc/mcp/sdk-types.d.ts: New ambient type declarations as tsc fallbackpackage.json: Moved SDK fromdependenciesto optionalpeerDependenciesdescribe.skipIf(!mcpSdkAvailable)guardseslint.config.js: Added*.d.tsto ignoresIterations
Quality Metrics
PR: #398
Ready for human review and merge.
fix(#396): lazy-load MCP SDK to prevent build failures when not insta…
docs(#396): update MCP server docs for optional SDK dependency
admarble commentedon Mar 23, 2026
Documentation Updated
File:
docs/features/mcp-server.md(updated existing doc)Changes:
@modelcontextprotocol/sdkto prerequisites with note that it's optionalNo new doc file needed — the existing MCP server documentation was updated to reflect the SDK being an optional peer dependency.