File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 24.18.0
Original file line number Diff line number Diff line change 3434 ],
3535 "author" : " abdush" ,
3636 "license" : " MIT" ,
37+ "engines" : {
38+ "node" : " 24.x"
39+ },
3740 "type" : " module" ,
3841 "bin" : {
3942 "context7-mcp" : " dist/index.js"
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { randomUUID } from "node:crypto";
2121import { createSessionStore } from "./lib/sessionStore.js" ;
2222import { SERVER_VERSION } from "./lib/constants.js" ;
2323import { localContext7Service } from "./local/service.js" ;
24+ import { assertSupportedNodeRuntime } from "./runtime.js" ;
2425
2526/** Default HTTP server port */
2627const DEFAULT_PORT = 3000 ;
@@ -538,6 +539,7 @@ function installTransportArgAliasing(transport: Transport): void {
538539}
539540
540541async function main ( ) {
542+ assertSupportedNodeRuntime ( ) ;
541543 const transportType = TRANSPORT_TYPE ;
542544
543545 if ( transportType === "http" ) {
Original file line number Diff line number Diff line change 1- import { initDatabase } from "@neuledge/context" ;
21import { readFile , stat } from "node:fs/promises" ;
32import { join } from "node:path" ;
43import type {
@@ -31,6 +30,11 @@ import type {
3130
3231const MAX_INDEX_CANDIDATES = 5 ;
3332
33+ async function initializeNativeDatabase ( ) : Promise < void > {
34+ const { initDatabase } = await import ( "@neuledge/context" ) ;
35+ await initDatabase ( ) ;
36+ }
37+
3438function resultFromManifest ( manifest : LibraryManifest ) : SearchResult {
3539 const safe = ( value : string , limit : number ) =>
3640 value
@@ -82,7 +86,9 @@ export class LocalContext7Service {
8286 this . store = new LocalLibraryStore ( config ) ;
8387 this . discovery = new LibraryDiscovery ( config ) ;
8488 this . builder = new LocalLibraryBuilder ( config , this . store ) ;
85- this . ready = Promise . all ( [ this . store . initialize ( ) , initDatabase ( ) ] ) . then ( ( ) => undefined ) ;
89+ this . ready = Promise . all ( [ this . store . initialize ( ) , initializeNativeDatabase ( ) ] ) . then (
90+ ( ) => undefined
91+ ) ;
8692 }
8793
8894 private async buildOnce (
Original file line number Diff line number Diff line change 1+ export const SUPPORTED_NODE_MAJOR = 24 ;
2+
3+ export function assertSupportedNodeRuntime ( nodeVersion : string = process . versions . node ) : void {
4+ const major = Number . parseInt ( nodeVersion . split ( "." , 1 ) [ 0 ] ?? "" , 10 ) ;
5+ if ( major === SUPPORTED_NODE_MAJOR ) return ;
6+
7+ throw new Error (
8+ `Context7 Local requires Node.js ${ SUPPORTED_NODE_MAJOR } .x because its local SQLite index uses native modules. ` +
9+ `Detected Node.js ${ nodeVersion } . Run the MCP server with Node.js ${ SUPPORTED_NODE_MAJOR } .x or reinstall dependencies with the selected Node.js runtime.`
10+ ) ;
11+ }
Original file line number Diff line number Diff line change 1+ import { describe , expect , test } from "vitest" ;
2+ import { SUPPORTED_NODE_MAJOR , assertSupportedNodeRuntime } from "../src/runtime.js" ;
3+
4+ describe ( "MCP native runtime compatibility" , ( ) => {
5+ test ( "accepts the Node.js runtime used to install native SQLite dependencies" , ( ) => {
6+ expect ( ( ) => assertSupportedNodeRuntime ( "24.18.0" ) ) . not . toThrow ( ) ;
7+ } ) ;
8+
9+ test ( "rejects an incompatible runtime before native modules are loaded" , ( ) => {
10+ expect ( ( ) => assertSupportedNodeRuntime ( "26.5.0" ) ) . toThrow (
11+ `Context7 Local requires Node.js ${ SUPPORTED_NODE_MAJOR } .x`
12+ ) ;
13+ } ) ;
14+ } ) ;
You can’t perform that action at this time.
0 commit comments