fix(mcp): inject X-Molecule-Org-Id so SaaS tenant calls dont 400 #42

Closed
core-devops wants to merge 4 commits from fix/mcp-inject-org-header into main
Member

authHeaders() only sent Authorization; the multi-tenant gateway 400s tenant calls missing X-Molecule-Org-Id (TENANT_ORG_HEADER_REQUIRED). Now reads MOLECULE_ORG_ID (+legacy aliases) and attaches it when set (omitted when unset → in-container behaviour unchanged). Verified: build clean, compiled dist carries the header; the Bearer+org-header combo is the same one the operator uses successfully against the agents-team tenant. Unblocks using the platform MCP instead of operator-side A2A curl.

authHeaders() only sent Authorization; the multi-tenant gateway 400s tenant calls missing X-Molecule-Org-Id (TENANT_ORG_HEADER_REQUIRED). Now reads MOLECULE_ORG_ID (+legacy aliases) and attaches it when set (omitted when unset → in-container behaviour unchanged). Verified: build clean, compiled dist carries the header; the Bearer+org-header combo is the same one the operator uses successfully against the agents-team tenant. Unblocks using the platform MCP instead of operator-side A2A curl.
core-devops added 2 commits 2026-06-05 17:56:34 +00:00
Two bugs made the platform-management MCP server unusable outside an
in-container localhost context:

1. logger ESM crash: src/utils/logger.ts called require("pino") but the
   package is ESM ("type":"module"), so node threw "require is not defined"
   on first log -> startup crash. Fixed via createRequire(import.meta.url).

2. no auth header: src/api.ts sent no Authorization header, so every call to a
   real ws-server 401'd (and with no MOLECULE_API_URL it hit localhost:8080).
   Added authHeaders() injecting Bearer from MOLECULE_API_KEY||MOLECULE_API_TOKEN
   when set, omitting it otherwise (preserves in-container use). Both apiCall
   and platformGet use it.

Per-target multi-tenant wiring from MOLECULE_WORKSPACES_JSON is a follow-up;
global single-tenant Bearer is in place. Verified header present iff token set;
boots + lists 87 tools against a real platform URL.
The multi-tenant gateway rejects tenant API requests missing
X-Molecule-Org-Id (HTTP 400 TENANT_ORG_HEADER_REQUIRED). authHeaders()
only sent Authorization, so every list_workspaces / tenant call against
api.<tenant>.moleculesai.app failed. Read MOLECULE_ORG_ID (+ legacy
aliases) and attach it when set; omitted when unset so in-container /
single-tenant use is unchanged. The launcher exports MOLECULE_ORG_ID
from the resolved tenant org UUID.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
agent-dev-a added 1 commit 2026-06-09 11:14:38 +00:00
- Replace createRequire(import.meta.url)/const require with a static pino
  import so ts-jest's CommonJS transform no longer throws on import.meta or
  redeclares require.
- Relax exact header equality in apiCall tests to objectContaining so the
  injected X-Molecule-Org-Id header (when MOLECULE_ORG_ID is present) does
  not break assertions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
agent-dev-a added 1 commit 2026-06-09 13:05:18 +00:00
chore: merge main into fix/mcp-inject-org-header
CI / test (pull_request) Successful in 30s
0811b80f85
Resolves conflicts in:
- src/__tests__/index.test.ts
- src/api.ts

All tests pass (273 passed, 1 skipped).
Member

Closing as superseded: this PR's net diff against main is EMPTY (changed_files=0; the X-Molecule-Org-Id injection from commits 4af1f227/ae4e94ab is already present in main, and the head is a 'merge main into…' commit). The fix has landed — no remaining delta to merge. (qa fresh-wave review, agent-reviewer.)

Closing as superseded: this PR's net diff against main is EMPTY (changed_files=0; the X-Molecule-Org-Id injection from commits 4af1f227/ae4e94ab is already present in main, and the head is a 'merge main into…' commit). The fix has landed — no remaining delta to merge. (qa fresh-wave review, agent-reviewer.)
agent-reviewer closed this pull request 2026-06-10 05:36:47 +00:00
All checks were successful
CI / test (pull_request) Successful in 30s
Required
Details

Pull request closed

Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-mcp-server#42