Skip to content

Commit 2e4aa5e

Browse files
committed
getting the package version from package.json directly
1 parent 4e887a3 commit 2e4aa5e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

build/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { z } from "zod";
55
import fetch from 'node-fetch';
66
import winston from 'winston';
77
import readline from 'readline';
8-
const VERSION = "0.0.1"; // Version of the MCP server
8+
import { fileURLToPath } from 'url';
9+
import { dirname, join } from 'path';
10+
import { readFileSync } from 'fs';
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = dirname(__filename);
13+
// Extract version from package.json
14+
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
15+
const VERSION = packageJson.version || "0.0.1";
916
// Configure winston logger
1017
const logger = winston.createLogger({
1118
level: 'info',
@@ -15,6 +22,7 @@ const logger = winston.createLogger({
1522
new winston.transports.File({ filename: 'socket-mcp.log' })
1623
]
1724
});
25+
logger.info(`Starting Socket MCP server version ${VERSION}`);
1826
const SOCKET_API_URL = "https://api.socket.dev/v0/purl?alerts=false&compact=false&fixable=false&licenseattrib=false&licensedetails=false";
1927
let SOCKET_API_KEY = process.env.SOCKET_API_KEY || "";
2028
if (!SOCKET_API_KEY) {

src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ import { z } from "zod";
55
import fetch from 'node-fetch';
66
import winston from 'winston';
77
import readline from 'readline';
8-
import readline from 'readline';
8+
import { fileURLToPath } from 'url';
9+
import { dirname, join } from 'path';
10+
import { readFileSync } from 'fs';
11+
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename);
914

10-
const VERSION = "0.0.1"; // Version of the MCP server
15+
// Extract version from package.json
16+
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
17+
const VERSION = packageJson.version || "0.0.1";
1118

1219
// Configure winston logger
1320
const logger = winston.createLogger({
@@ -23,6 +30,8 @@ const logger = winston.createLogger({
2330
]
2431
});
2532

33+
logger.info(`Starting Socket MCP server version ${VERSION}`);
34+
2635
const SOCKET_API_URL = "https://api.socket.dev/v0/purl?alerts=false&compact=false&fixable=false&licenseattrib=false&licensedetails=false";
2736

2837
let SOCKET_API_KEY = process.env.SOCKET_API_KEY || "";

0 commit comments

Comments
 (0)