Skip to content

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

Open
itosa-kazu wants to merge 1 commit into
currents-dev:mainfrom
itosa-kazu:codex/fix-currents-mcp-types
Open

fix(mcp-server): point types metadata to emitted declarations#146
itosa-kazu wants to merge 1 commit 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

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

    • Updated TypeScript type declarations configuration for improved ESM module support, switching to new type declaration file mappings.
  • Tests

    • Enhanced integration test suite with improved npm command execution handling and added validation that type declaration files are properly bundled and correctly resolved when installed.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@itosa-kazu, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 31 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: 7c8fbb8d-48af-49ac-9df9-27df96bb6300

📥 Commits

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

📒 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 updates the MCP server package to publish ESM-compatible type declarations via a new .d.mts mapping in package.json, refactors both integration test files to centralize npm command execution through locally-resolved CLI paths, and adds validation to confirm the type declarations are correctly included in the published tarball.

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 for ESM-compatible type resolution.
npm CLI resolution helpers in integration tests
mcp-server/src/cli-bin.integration.test.ts, mcp-server/src/package-published-esm.integration.test.ts
Both test files introduce execNpm and spawnNpx helpers that resolve npm/npx entry points from process.env.npm_execpath when available, with fallback to plain command invocation, and update packTarball to use this centralized wrapper.
CLI integration test updates
mcp-server/src/cli-bin.integration.test.ts
CLI smoke tests and consumer project setup are switched from direct spawnSync and execFileSync to use the new spawnNpx and execNpm helpers.
Published package type validation test
mcp-server/src/package-published-esm.integration.test.ts
Consumer setup is updated to use execNpm, and a new test is added that installs the packed tarball and validates that both pkg.types and pkg.exports["."].types reference existing declaration files in the installed package.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • currents-dev/currents-mcp#136: Both PRs modify the package's published TypeScript declaration mappings under exports["."].types/types (related PR updates output targets while this PR further changes the file extension from .d.ts to .d.mts).
  • currents-dev/currents-mcp#135: Both PRs update the packTarball helper in package-published-esm.integration.test.ts (this PR wraps it with execNpm, related PR adds npm pack --ignore-scripts).
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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' accurately summarizes the main change: updating the package's types metadata to reference the emitted .d.mts declaration file instead of the previous .d.ts file.
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

@itosa-kazu itosa-kazu force-pushed the codex/fix-currents-mcp-types branch from 204015f to 6d6df1b Compare June 9, 2026 23:18
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.

1 participant