Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ on:

jobs:
test:
name: Run Unit Tests
name: Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20.x, 22.x, 24.x]

steps:
- name: Checkout code
Expand All @@ -18,14 +22,16 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24.x
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: mcp-server/package-lock.json

- name: Install dependencies
working-directory: ./mcp-server
run: npm ci

- name: Run tests
# Includes package-environments.integration.test.ts (workspace ESM/CJS),
# package-published-esm.integration.test.ts (npm pack + import "@currents/mcp").
- name: Build and run tests
working-directory: ./mcp-server
run: npm run test:run
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
# syntax=docker/dockerfile:1

# Build stage
FROM node:lts-alpine AS build
FROM node:20-alpine AS build
WORKDIR /app

# Install dependencies
COPY mcp-server/package.json mcp-server/package-lock.json ./
RUN npm ci --production=false

# Copy source code
COPY mcp-server/tsconfig.json ./tsconfig.json
COPY mcp-server/tsconfig.json mcp-server/tsconfig.cjs.json ./
COPY mcp-server/scripts ./scripts
COPY mcp-server/src ./src

# Build the project
RUN npm run build

# Runtime stage
FROM node:lts-alpine AS runtime
FROM node:20-alpine AS runtime
WORKDIR /app

# Copy build artifacts and dependencies
Expand Down
43 changes: 34 additions & 9 deletions mcp-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions mcp-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@
"bin": "./build/index.js",
"version": "2.2.16",
"description": "Currents MCP server",
"main": "index.js",
"main": "./build/cjs/api.js",
"module": "./build/api.js",
"types": "./build/api.d.ts",
"exports": {
".": {
"types": "./build/api.d.ts",
"import": "./build/api.js",
"require": "./build/cjs/api.js"
}
},
"scripts": {
"build": "tsc && chmod 755 build/index.js",
"build": "tsc && tsc -p tsconfig.cjs.json && node ./scripts/write-cjs-package-json.mjs && chmod 755 build/index.js",
"publish:mcp": "npm run publish:npm",
"publish:npm": "npm run rm && npm run build && ./publish.cjs",
"start": "node build/index.js",
"rm": "rimraf dist",
"test": "vitest",
"test:ui": "vitest --ui",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage",
"test:run": "npm run build && vitest run",
"test:coverage": "npm run build && vitest run --coverage",
"release": "release-it",
"release:dry": "release-it --dry-run"
},
Expand All @@ -36,14 +45,18 @@
"url": "https://github.com/currents-dev/currents-mcp.git"
},
"license": "Apache-2.0",
"engines": {
"node": ">=20"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.25.2",
"@modelcontextprotocol/sdk": "^1.28.0",
"commander": "^12.1.0",
"pino": "^9.9.5",
"pino-pretty": "^13.1.1",
"zod": "^4.3.5"
},
"devDependencies": {
"@types/node": "^20.19.0",
"@release-it/conventional-changelog": "^10.0.0",
"release-it": "^19.0.3",
"rimraf": "^6.0.1",
Expand Down
8 changes: 8 additions & 0 deletions mcp-server/scripts/write-cjs-package-json.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const cjsDir = join(root, "build", "cjs");
mkdirSync(cjsDir, { recursive: true });
writeFileSync(join(cjsDir, "package.json"), `${JSON.stringify({ type: "commonjs" })}\n`);
1 change: 1 addition & 0 deletions mcp-server/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { startMcpServer } from "./server.js";
98 changes: 98 additions & 0 deletions mcp-server/src/cli-bin.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Packaged **CLI** integration tests: the `bin` field and `npx` behavior for a
* tarball shaped like a publish (not the programmatic `exports` entry; see
* `package-published-esm.integration.test.ts` for `import "@currents/mcp"`).
*

* 1. Prerequisite: `build/index.js` exists (`npm run test:run` runs `build`
* first). If missing, the suite is skipped so `vitest` without a prior
* build does not fail noisily.
* 2. `packTarball`: `npm pack` from the package root → one `.tgz` under a
* temp dir. Contents follow `package.json` `files` and npm’s pack rules
* (same artifact shape as registry install, minus release-only publish.cjs
* mutations).
*/
import { execFileSync, spawnSync } from "node:child_process";
import { existsSync, mkdtempSync, readdirSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";

const root = fileURLToPath(new URL("..", import.meta.url));
const buildIndex = path.join(root, "build", "index.js");

function packTarball(packDest: string): string {
// Respect `files` and standard pack rules; do not mutate package.json (unlike release `publish.cjs`).
execFileSync("npm", ["pack", "--pack-destination", packDest], {
cwd: root,
stdio: ["ignore", "pipe", "pipe"],
});
const tgz = readdirSync(packDest).filter((f) => f.endsWith(".tgz"));
if (tgz.length !== 1) {
throw new Error(`expected one .tgz in ${packDest}, got: ${tgz.join(", ")}`);
}
return path.join(packDest, tgz[0]);
}

describe.skipIf(!existsSync(buildIndex))(
"packaged CLI (npx / bin)",
{ timeout: 60_000 },
() => {
/**
* `npx -y --package <abs-path-to.tgz> mcp`: npm treats the tarball as the
* package to install transiently; `mcp` is the bin name from that package’s
* `package.json` `bin` map (not the scoped package name). The child should
* start the MCP server and log the “live” line (stdio MCP servers run until
* stdin closes; we cap wall time with `spawnSync` timeout). Accept either
* that log line or process timeout as success so slow CI still passes.
* */
it("starts via npx --package tarball mcp", () => {
const packDir = mkdtempSync(path.join(tmpdir(), "mcp-pack-"));
const tarball = packTarball(packDir);
const r = spawnSync("npx", ["-y", "--package", tarball, "mcp"], {
cwd: packDir,
timeout: 45_000,
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
env: {
...process.env,
// Required for server startup; value is unused in this smoke test.
CURRENTS_API_KEY: "vitest-cli-pack-smoke",
},
});
const combined = `${r.stdout ?? ""}${r.stderr ?? ""}`;
const timedOut =
r.error != null && "code" in r.error && r.error.code === "ETIMEDOUT";
expect(combined.includes("Currents MCP Server is live") || timedOut).toBe(
true
);
});

/*
* Second `it` — consumer project + `node_modules/.bin`:
* - `npm init -y` and `npm install <tgz>` in a fresh temp project. npm links
* `node_modules/.bin/mcp` (or `mcp.cmd` on Windows) to the packed CLI.
* - Assert the shim exists. This catches broken `bin`, wrong `files` (missing
* `build/index.js`), or install layout issues without spawning the server.
* */
it("exposes mcp bin after npm install from tarball", () => {
const packDir = mkdtempSync(path.join(tmpdir(), "mcp-pack-"));
const installDir = mkdtempSync(path.join(tmpdir(), "mcp-install-"));
const tarball = packTarball(packDir);
execFileSync("npm", ["init", "-y"], {
cwd: installDir,
stdio: "ignore",
});
execFileSync("npm", ["install", tarball], {
cwd: installDir,
stdio: "ignore",
});
const binDir = path.join(installDir, "node_modules", ".bin");
const hasMcp =
existsSync(path.join(binDir, "mcp")) ||
existsSync(path.join(binDir, "mcp.cmd"));
expect(hasMcp).toBe(true);
});
}
);
Loading
Loading