Skip to content

fix(mcp-server): point types metadata to emitted declarations#146

Merged
miguelangaranocurrents merged 2 commits into
currents-dev:mainfrom
itosa-kazu:codex/fix-currents-mcp-types
Jun 10, 2026
Merged

fix(mcp-server): point types metadata to emitted declarations#146
miguelangaranocurrents merged 2 commits into
currents-dev:mainfrom
itosa-kazu:codex/fix-currents-mcp-types

Conversation

@itosa-kazu

@itosa-kazu itosa-kazu commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • point package types and exported types to the emitted dist/api.d.mts
  • add pack/install integration coverage that checks metadata declaration paths exist
  • invoke npm/npx through the current Node runtime in integration tests when available, which keeps the tests working on Windows

Validation

  • npm ci --ignore-scripts
  • npx tsdown
  • npx vitest run src/package-published-esm.integration.test.ts
  • npx tsdown; npx vitest run (12 files / 385 tests)
  • npm pack --ignore-scripts plus clean temp install metadata smoke

Note: npm run build runs tsdown successfully here, then fails on Windows at the existing POSIX chmod 755 dist/index.mjs step.

Summary by CodeRabbit

  • Chores

    • Switched package type declaration mappings to ESM-compatible declaration files for proper ESM typing resolution.
  • Tests

    • Centralized npm/npx invocation in test helpers for more reliable command execution.
    • Improved integration tests and added a new test that verifies bundled type declaration paths are present and correctly referenced after packaging/install.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cursor[bot], we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 10 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f1ea2f3-cb46-41e7-8353-de575f2f7cab

📥 Commits

Reviewing files that changed from the base of the PR and between 39773a3 and 26e0294.

📒 Files selected for processing (4)
  • mcp-server/package.json
  • mcp-server/src/cli-bin.integration.test.ts
  • mcp-server/src/package-published-esm.integration.test.ts
  • mcp-server/test/npm-exec.ts
📝 Walkthrough

Walkthrough

The PR switches published typings to ./dist/api.d.mts, adds shared execNpm/spawnNpx test helpers that prefer locally-resolved npm/npx, updates integration tests to use those helpers for packing/installing, and adds a test that validates the installed package's types and exports["."].types point to existing files.

Changes

ESM type declarations and npm CLI integration

Layer / File(s) Summary
ESM type declaration mapping in package.json
mcp-server/package.json
types field and exports["."].types are updated to point to ./dist/api.d.mts instead of ./dist/api.d.ts.
Introduce npm/npx test helpers
mcp-server/test/npm-exec.ts
Adds execNpm and spawnNpx helpers that prefer process.env.npm_execpath-derived entrypoints and fall back to npm/npx, executing via execFileSync/spawnSync with typed options.
CLI integration test updates
mcp-server/src/cli-bin.integration.test.ts
Replaces direct spawnSync/execFileSync npm/npx calls with spawnNpx/execNpm, and changes packTarball to run npm pack via execNpm.
Published package tests: pack, install, validate types
mcp-server/src/package-published-esm.integration.test.ts
Rewrites packTarball to use execNpm, switches consumer setup to execNpm(["init","-y"]), and adds a test that installs the tarball and asserts pkg.types and pkg.exports["."].types reference existing files in the installed package.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(mcp-server): point types metadata to emitted declarations' clearly and concisely describes the main change: updating package.json to reference the correct ESM-compatible type declarations file (api.d.mts instead of api.d.ts).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
mcp-server/src/cli-bin.integration.test.ts (2)

24-25: ⚡ Quick win

Npx CLI path derivation assumes a specific npm structure.

The regex replacement /npm-cli\.js$/ assumes that process.env.npm_execpath always ends with npm-cli.js. If npm's internal structure changes or the path format differs across platforms or npm versions, this derivation will fail silently, falling back to the system npx command without indication.

🛡️ More robust derivation
-const npmCli = process.env.npm_execpath;
-const npxCli = npmCli?.replace(/npm-cli\.js$/, "npx-cli.js");
+const npmCli = process.env.npm_execpath;
+const npxCli = npmCli
+  ? path.join(path.dirname(npmCli), "npx-cli.js")
+  : undefined;

This approach derives the npx path by replacing the filename within the same directory, which is more resilient to path variations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mcp-server/src/cli-bin.integration.test.ts` around lines 24 - 25, The current
npx path derivation assumes npm_execpath ends with "npm-cli.js" by using a fixed
regex; update the logic to safely compute npxCli from npmCli by taking the
directory portion of process.env.npm_execpath (reference: npmCli and
process.env.npm_execpath) and joining it with "npx-cli.js" so filename
replacement is not dependent on exact string endings and works across platforms
(handle null/undefined npmCli and Windows path separators), and ensure a clear
fallback/log message if the computed npxCli does not exist.

24-39: ⚡ Quick win

Extract shared npm execution helpers to eliminate duplication.

The npmCli, npxCli, execNpm, and spawnNpx definitions (lines 24–39) are duplicated verbatim in package-published-esm.integration.test.ts (lines 46–53 for the npm subset). Extract these helpers into a shared test utility module to maintain a single source of truth and simplify future updates.

♻️ Suggested structure

Create mcp-server/test/helpers/npm-exec.ts:

import { execFileSync, spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
import path from "node:path";

const npmCli = process.env.npm_execpath;
const npxCli = npmCli?.replace(/npm-cli\.js$/, "npx-cli.js");

export function execNpm(args: string[], options: Parameters<typeof execFileSync>[2]) {
  if (npmCli) {
    return execFileSync(process.execPath, [npmCli, ...args], options);
  }
  return execFileSync("npm", args, options);
}

export function spawnNpx(args: string[], options: Parameters<typeof spawnSync>[2]) {
  if (npxCli && existsSync(npxCli)) {
    return spawnSync(process.execPath, [npxCli, ...args], options);
  }
  return spawnSync("npx", args, options);
}

Then import in both test files:

-const npmCli = process.env.npm_execpath;
-const npxCli = npmCli?.replace(/npm-cli\.js$/, "npx-cli.js");
-
-function execNpm(args: string[], options: Parameters<typeof execFileSync>[2]) {
-  if (npmCli) {
-    return execFileSync(process.execPath, [npmCli, ...args], options);
-  }
-  return execFileSync("npm", args, options);
-}
-
-function spawnNpx(args: string[], options: Parameters<typeof spawnSync>[2]) {
-  if (npxCli && existsSync(npxCli)) {
-    return spawnSync(process.execPath, [npxCli, ...args], options);
-  }
-  return spawnSync("npx", args, options);
-}
+import { execNpm, spawnNpx } from "../test/helpers/npm-exec.js";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mcp-server/src/cli-bin.integration.test.ts` around lines 24 - 39, Extract the
duplicated helpers npmCli, npxCli, execNpm, and spawnNpx into a single shared
test helper module (e.g., npm-exec.ts) and export execNpm and spawnNpx; then
remove the duplicate declarations from
mcp-server/src/cli-bin.integration.test.ts and
package-published-esm.integration.test.ts and import the exported execNpm and
spawnNpx from the new helper instead, preserving the exact behavior and
signatures (Parameters<typeof execFileSync>[2] and Parameters<typeof
spawnSync>[2]).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@mcp-server/src/cli-bin.integration.test.ts`:
- Around line 24-25: The current npx path derivation assumes npm_execpath ends
with "npm-cli.js" by using a fixed regex; update the logic to safely compute
npxCli from npmCli by taking the directory portion of process.env.npm_execpath
(reference: npmCli and process.env.npm_execpath) and joining it with
"npx-cli.js" so filename replacement is not dependent on exact string endings
and works across platforms (handle null/undefined npmCli and Windows path
separators), and ensure a clear fallback/log message if the computed npxCli does
not exist.
- Around line 24-39: Extract the duplicated helpers npmCli, npxCli, execNpm, and
spawnNpx into a single shared test helper module (e.g., npm-exec.ts) and export
execNpm and spawnNpx; then remove the duplicate declarations from
mcp-server/src/cli-bin.integration.test.ts and
package-published-esm.integration.test.ts and import the exported execNpm and
spawnNpx from the new helper instead, preserving the exact behavior and
signatures (Parameters<typeof execFileSync>[2] and Parameters<typeof
spawnSync>[2]).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65007382-f2db-4bee-ac8b-cd4fc14de924

📥 Commits

Reviewing files that changed from the base of the PR and between f620c80 and 204015f.

📒 Files selected for processing (3)
  • mcp-server/package.json
  • mcp-server/src/cli-bin.integration.test.ts
  • mcp-server/src/package-published-esm.integration.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mcp-server/test/npm-exec.ts`:
- Around line 12-15: The current branch uses npmCli when truthy without
verifying the path actually exists, so a non-existent npm_execpath will throw
before falling back to "npm"; modify the logic around the npmCli usage in
mcp-server/test/npm-exec.ts (the block that calls execFileSync(process.execPath,
[npmCli, ...args], options)) to first verify the file exists (e.g.,
fs.existsSync or fs.access) similar to spawnNpx’s check, and only call
execFileSync with process.execPath + npmCli if the file check passes; otherwise
fall back to execFileSync("npm", args, options).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a90f8ac6-6dd0-4984-a188-ac23700d6107

📥 Commits

Reviewing files that changed from the base of the PR and between 204015f and 39773a3.

⛔ Files ignored due to path filters (1)
  • mcp-server/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • mcp-server/package.json
  • mcp-server/src/cli-bin.integration.test.ts
  • mcp-server/src/package-published-esm.integration.test.ts
  • mcp-server/test/npm-exec.ts
✅ Files skipped from review due to trivial changes (1)
  • mcp-server/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • mcp-server/src/cli-bin.integration.test.ts
  • mcp-server/src/package-published-esm.integration.test.ts

Comment thread mcp-server/test/npm-exec.ts Outdated
itosa-kazu and others added 2 commits June 10, 2026 20:56
Fall back to plain npm when npm_execpath is set but the file is missing,
matching spawnNpx behavior.
@cursor cursor Bot force-pushed the codex/fix-currents-mcp-types branch from e57a432 to 26e0294 Compare June 10, 2026 20:57
@miguelangaranocurrents miguelangaranocurrents merged commit 7aa2521 into currents-dev:main Jun 10, 2026
5 checks passed
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.

3 participants