Skip to content

Convert the project to use Node.js type stripping #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bcomnes
Copy link
Member

@bcomnes bcomnes commented Jun 27, 2025

Kind of a bigish change, but in general should simplify the workflow by removing the dev-time build step. No reason not to start using this flow sooner than later.

Everything runs directly with node on Node 23 or later or node --experimental-strip-types on Node 22. The flag is getting dropped soon as well. All the scripts and shebangs have been updated to include this as well. It's a noop in Node 23 or later.

  • When working in the repo, you just run .ts files.
  • When publishing to npm or GitHub releases, you run the build step, pack the module, ship it somewhere, then run npm run clean which cleans out the declaration files and js files.
  • I also swapped : for - when not using run-s groupings
  • I kept build-dtx separate from the main build. It runs the main build first because I presume that needs built .js assets.
  • I added a test action, and converted one of the debug scripts to a node test runner test that runs in CI. I added a socket API token to the test environment.

Ill add in-line comments as well.

Copy link

socket-security bot commented Jun 27, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​anthropic-ai/​dxt@​0.1.0761009990100
Updated@​types/​node@​22.15.19 ⏵ 22.15.33100 +110080 +196100
Addedc8@​10.1.39910010080100
Addednpm-run-all2@​8.0.4991009994100
Updatedzod@​3.25.3 ⏵ 3.25.67100100100 +2696100
Updated@​modelcontextprotocol/​sdk@​1.11.4 ⏵ 1.13.299 +110010098 +1100

View full report

@bcomnes bcomnes force-pushed the bret/type-stripping branch from 3628f19 to 7cca8ed Compare June 27, 2025 23:27
@socket-security-staging
Copy link

socket-security-staging bot commented Jun 27, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​anthropic-ai/​dxt@​0.1.0761009990100
Updated@​types/​node@​22.15.19 ⏵ 22.15.33100 +110080 +196 +1100
Addedc8@​10.1.39910010080100
Addednpm-run-all2@​8.0.4991009993100
Updatedzod@​3.25.3 ⏵ 3.25.67100100100 +2696100
Updated@​modelcontextprotocol/​sdk@​1.11.4 ⏵ 1.13.299 +110010098100

View full report

@socket-security-staging
Copy link

socket-security-staging bot commented Jun 27, 2025

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert (click for details)
Warn Medium
@anthropic-ai/dxt@0.1.0 is an Unpopular package.

Location: Package overview

From: package-lock.jsonnpm/@anthropic-ai/dxt@0.1.0

ℹ Read more on: This package | This alert | What are unpopular packages?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Unpopular packages may have less maintenance and contain other problems.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@anthropic-ai/dxt@0.1.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@bcomnes bcomnes force-pushed the bret/type-stripping branch from 7cca8ed to 372f99a Compare June 27, 2025 23:28
@@ -23,7 +24,7 @@ The `mock-client` directory contains debug clients for testing the Socket MCP se
Direct stdio communication using JSON-RPC protocol:

```bash
npm run debug:stdio
npm run debug-stdio
Copy link
Member Author

Choose a reason for hiding this comment

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

I switched to - instead of : to disambiguate npm scripts that are run with globs and those just grouped together that don't run together.


# Build the application
RUN npm run build
COPY . .
Copy link
Member Author

Choose a reason for hiding this comment

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

This is so that as the project grows you don't have to constantly update a file list. You are free to change this if you prefer.

CMD [ "node", "--experimental-strip-types", "index.ts" , "--http"]
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't need to build in production either!

@@ -1,22 +1,20 @@
#!/usr/bin/env node
#!/usr/bin/env node --experimental-strip-types
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to add a flag to the shebang.

@bcomnes bcomnes force-pushed the bret/type-stripping branch from 372f99a to 520d137 Compare June 27, 2025 23:32
@@ -1,11 +1,11 @@
#!/usr/bin/env node
import fetch from 'node-fetch';
Copy link
Member Author

Choose a reason for hiding this comment

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

Node has built in fetch now!

@@ -20,9 +20,9 @@ async function parseResponse(response: any) {

// Simple HTTP client for testing MCP server in HTTP mode
async function testHTTPMode() {
const baseUrl = (process.env.MCP_URL || 'http://localhost:3000').replace(/\/$/, ''); // Remove trailing slash
const baseUrl = (process.env['MCP_URL'] || 'http://localhost:3000').replace(/\/$/, ''); // Remove trailing slash
Copy link
Member Author

Choose a reason for hiding this comment

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

Typescript forced this.


async function main() {
const serverPath = join(import.meta.dirname, '..', 'index.ts');
Copy link
Member Author

Choose a reason for hiding this comment

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

Lets use __dirname instead of cwd resolutions.

},
"engines": {
"node": ">=22.0.0",
"npm": ">= 10"
Copy link
Member Author

Choose a reason for hiding this comment

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

Added an engines field.

"debug:http": "node ./build/mock-client/http-client.js",
"server:stdio": "SOCKET_API_KEY=${SOCKET_API_KEY} ./build/index.js",
"server:http": "MCP_HTTP_MODE=true SOCKET_API_KEY=${SOCKET_API_KEY} ./build/index.js"
"prepublishOnly": "npm run build",
Copy link
Member Author

Choose a reason for hiding this comment

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

When you publish, this will auto-build.

"server:stdio": "SOCKET_API_KEY=${SOCKET_API_KEY} ./build/index.js",
"server:http": "MCP_HTTP_MODE=true SOCKET_API_KEY=${SOCKET_API_KEY} ./build/index.js"
"prepublishOnly": "npm run build",
"postpublish": "npm run clean",
Copy link
Member Author

Choose a reason for hiding this comment

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

When the publish is over, it cleans up.

"server:http": "MCP_HTTP_MODE=true SOCKET_API_KEY=${SOCKET_API_KEY} ./build/index.js"
"prepublishOnly": "npm run build",
"postpublish": "npm run clean",
"test": "run-s test:*",
Copy link
Member Author

Choose a reason for hiding this comment

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

Added the test lifecycle, with type checking and the node test runner with coverage.

package.json Outdated
"build": "npm run clean && run-s build:*",
"build:types": "tsc -p tsconfig.declaration.json",
"build:permissions": "chmod +x ./index.js && (chmod +x ./mock-client/*.js 2>/dev/null || true)",
"build-dtx": "run-s build build-dtx:dtx-pack",
Copy link
Member Author

Choose a reason for hiding this comment

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

I kept the build-dtx command out of the main build step, because it seems like something that is done by hand?

@bcomnes bcomnes force-pushed the bret/type-stripping branch from 520d137 to fc81cfb Compare June 27, 2025 23:36
"index.d.ts",
"index.d.ts.map",
"mock-client/**/*.js",
"mock-client/**/*.d.ts*"
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively we could just leave everything in a src folder.

@@ -0,0 +1,171 @@
#!/bin/bash
Copy link
Member Author

Choose a reason for hiding this comment

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

This cleans up declarations and emitted .js files. This keeps your working directory clean of any publish time assets.

@@ -0,0 +1,64 @@
#!/usr/bin/env node
Copy link
Member Author

Choose a reason for hiding this comment

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

I ported the stdout debug script to a test environment.

@@ -0,0 +1,16 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

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

This is used during publishing only.

@bcomnes
Copy link
Member Author

bcomnes commented Jun 27, 2025

Followup: #5

@bcomnes bcomnes requested a review from kapravel June 27, 2025 23:47
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