Skip to content

bug: workflow-tools.js importLocalModule() references src/ paths instead of dist/ #3954

@iMokys

Description

@iMokys

Description

packages/mcp-server/dist/workflow-tools.js contains 9 importLocalModule() calls that use relative paths pointing to ../../../src/resources/extensions/gsd/.... Since this file runs from its compiled location in dist/, these paths resolve to the src/ directory where only .ts source files exist — not the .js files the dynamic import() expects.

Result: Every MCP tool that calls importLocalModule() fails with:

Cannot find module '.../src/resources/extensions/gsd/db-writer.js'

Affected modules (all 9)

../../../src/resources/extensions/gsd/bootstrap/write-gate.js
../../../src/resources/extensions/gsd/db-writer.js
../../../src/resources/extensions/gsd/doctor.js
../../../src/resources/extensions/gsd/gsd-db.js
../../../src/resources/extensions/gsd/journal.js
../../../src/resources/extensions/gsd/milestone-ids.js
../../../src/resources/extensions/gsd/state.js
../../../src/resources/extensions/gsd/tools/plan-task.js
../../../src/resources/extensions/gsd/tools/workflow-tool-executors.js

Affected tools

gsd_decision_save, gsd_milestone operations, state writes, journal writes, doctor (via MCP), plan-task — any tool that routes through importLocalModule() in workflow-tools.js.

Root cause

packages/mcp-server/src/workflow-tools.ts hardcodes relative paths with src/ prefixes:

const { saveDecisionToDb } = await importLocalModule(
  "../../../src/resources/extensions/gsd/db-writer.js"
);

TypeScript compiles this to dist/workflow-tools.js but string literals pass through unchanged. The importLocalModule() function resolves relative to import.meta.url (the file's own location), so:

  • Expected resolution: packages/mcp-server/dist/ + ../../../dist/resources/extensions/gsd/db-writer.js
  • Actual resolution: packages/mcp-server/dist/ + ../../../src/resources/extensions/gsd/db-writer.js

Reproduction

  1. Install gsd-pi globally: npm i -g gsd-pi
  2. Run any project with MCP workflow server configured
  3. Call gsd_decision_save (or any tool using importLocalModule)
  4. Observe: Cannot find module '.../src/resources/extensions/gsd/db-writer.js'

Workaround

Create symlinks from dist/*.js to the src/ paths:

BASE="$(npm root -g)/gsd-pi"
for f in \
  resources/extensions/gsd/bootstrap/write-gate.js \
  resources/extensions/gsd/db-writer.js \
  resources/extensions/gsd/doctor.js \
  resources/extensions/gsd/gsd-db.js \
  resources/extensions/gsd/journal.js \
  resources/extensions/gsd/milestone-ids.js \
  resources/extensions/gsd/state.js \
  resources/extensions/gsd/tools/plan-task.js \
  resources/extensions/gsd/tools/workflow-tool-executors.js; do
  ln -sf "$BASE/dist/$f" "$BASE/src/$f"
done

Suggested fix

Change all importLocalModule() paths in packages/mcp-server/src/workflow-tools.ts from ../../../src/... to ../../../dist/..., or introduce a build-time path substitution that rewrites src/ to dist/ during compilation.

Environment

  • gsd-pi: global install via npm
  • Node: v22.22.0
  • OS: Linux (WSL2)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions