4.6 KiB
4.6 KiB
Implementation Plan
Here is a plan to transform your Node.js CLI package into a Deno CLI project, focusing on reusing the existing TypeScript code in the src/
directory:
-
Analyze Dependencies:
- Identify Node.js built-in modules used (e.g.,
events
,process
). - Identify external npm packages (e.g.,
@modelcontextprotocol/sdk
).
- Identify Node.js built-in modules used (e.g.,
-
Configure
deno.json
:- Update the
imports
section to map npm packages usingnpm:
specifiers (e.g.,"@modelcontextprotocol/sdk/": "npm:@modelcontextprotocol/sdk/"
). - Ensure necessary Deno standard library modules are imported if needed (e.g.,
std/node
for Node compatibility APIs if direct replacement isn't feasible). - Update the
tasks
section to usedeno run
with appropriate permissions (--allow-net
,--allow-read
,--allow-env
, etc.) targetingsrc/proxy.ts
. Remove--watch
from the main start task unless desired. - Review
compilerOptions
. Deno uses these, but ensure they align with Deno's defaults or project needs. Remove"types": ["node"]
as Deno handles Node types vianode:
specifiers. - Remove
"unstable": ["sloppy-imports"]
and plan to add explicit file extensions to imports.
- Update the
-
Adapt Code in
src/
:- Imports:
- Prefix all Node.js built-in module imports with
node:
(e.g.,import { EventEmitter } from 'node:events';
). - Update imports for external npm packages to match the
npm:
specifiers defined indeno.json
or directly usenpm:
specifiers in the import statement. - Append the
.ts
(or.js
if applicable) extension to all relative file imports within thesrc/
directory (e.g.,import { ... } from './lib/utils.ts';
).
- Prefix all Node.js built-in module imports with
- Node Globals/APIs:
- Replace
process.argv
withDeno.args
. Note thatDeno.args
does not include the script name, so adjustments to slicing (like.slice(2)
) might be needed or removed. - Replace
process.exit()
withDeno.exit()
. - Replace or refactor any other Node-specific APIs that don't have direct Deno equivalents or aren't polyfilled via the
node:
specifier (e.g., check compatibility ofStdioServerTransport
if it relies heavily on Node streams internally, although thenpm:
specifier should handle much of this).
- Replace
- Imports:
-
Cleanup Project Root:
- Delete
pnpm-lock.yaml
andnode_modules
(if present). - Decide whether to keep
package.json
. It's not used by Deno for dependencies but can be useful for metadata (name, version, description). If kept, ensure it doesn't cause confusion. - Remove
tsconfig.json
if all necessary compiler options are migrated todeno.json
. Linters/editors might still pick it up, so consider keeping it for tooling compatibility if needed, butdeno.json
takes precedence for Deno itself.
- Delete
-
Testing:
- Added client.ts as an additional CLI entrypoint
- Added client task to deno.json
- Run the main task using
deno task proxy:start <args...>
. - Thoroughly test the CLI's functionality to ensure it behaves identically to the original Node.js version. Pay close attention to areas involving file system access, network requests, environment variables, and process management.
-
Refine Type Safety & Linting:
- Address remaining
any
types and other linter warnings identified bydeno lint
. - Improve type definitions, especially for external library interactions (e.g., express request/response types if kept).
- Run
deno fmt
to ensure consistent code formatting.
- Address remaining
-
Improve Dependency Management:
- Evaluate replacing
npm:express
with a native Deno HTTP server solution (e.g.,Deno.serve
or fromstd/http
). - Evaluate replacing
npm:open
with a Deno equivalent or platform-specific commands.
- Evaluate replacing
-
Implement Testing:
- Add unit tests for key utility functions (e.g., in
utils.ts
,mcp-auth-config.ts
). - Add integration tests for the core proxy (
proxy.ts
) and client (client.ts
) functionality.
- Add unit tests for key utility functions (e.g., in
-
Enhance Documentation:
- Update
README.md
with Deno-specific installation, usage, and contribution guidelines. - Add comprehensive TSDoc comments to all exported functions, classes, and interfaces.
- Update
-
Build & Distribution:
- Configure
deno publish
settings if intending to publish to deno.land/x. - Explore using
deno compile
to create standalone executables for different platforms.
- Configure
This plan prioritizes modifying the existing TypeScript code minimally while adapting the project structure and configuration for Deno. We will start by modifying deno.json
and src/proxy.ts
.