Skip to content

Commit 97e86d1

Browse files
DinanathDashRawJat
andauthored
Improve module path resolution and macOS compatibility (#172)
This pull request introduces several improvements and fixes across the MCP server and supporting scripts. The most notable changes include a more robust check for script invocation, improved compatibility for temporary file creation on macOS, and metadata updates. **Server invocation and compatibility improvements:** * Improved the script invocation check in `server.mjs` to use `realpathSync` and `fileURLToPath`, making it more robust and reliable across symlinked environments. (`mcp-server/server.mjs`, `[mcp-server/server.mjsL1596-R1599](diffhunk://#diff-fa2b329c088195110d7f59f714c29a003b1cd1804716bb67acdacb4888ec3ef1L1596-R1599)`) * Updated import statements in `server.mjs` to remove unused imports and add `realpathSync`, simplifying the code and reducing dependencies. (`mcp-server/server.mjs`, `[mcp-server/server.mjsR4-R8](diffhunk://#diff-fa2b329c088195110d7f59f714c29a003b1cd1804716bb67acdacb4888ec3ef1R4-R8)`) **Script enhancements for macOS:** * Modified `verify-hitl-staging.sh` to use a macOS-safe method for creating temporary files with `mktemp`, improving compatibility and reliability on macOS systems. (`scripts/verify-hitl-staging.sh`, `[scripts/verify-hitl-staging.shL16-R16](diffhunk://#diff-9154b6d85679f4d5188e393c955ec759bd0d2d67a0b9844fe5d9723bac72c5e8L16-R16)`) * Cleaned up comments and removed redundant lines in `verify-hitl-staging.sh` for clarity and maintainability. (`scripts/verify-hitl-staging.sh`, `[[1]](diffhunk://#diff-9154b6d85679f4d5188e393c955ec759bd0d2d67a0b9844fe5d9723bac72c5e8L2-R2)`, `[[2]](diffhunk://#diff-9154b6d85679f4d5188e393c955ec759bd0d2d67a0b9844fe5d9723bac72c5e8L26)`) **Metadata updates:** * Added the `mcpName` field to `package.json` to specify the MCP server's identity, aiding in package management and identification. (`mcp-server/package.json`, `[mcp-server/package.jsonR4](diffhunk://#diff-f3494fd36ee5f868a34336de16a47abd48792d43efeb619ed167c8067ec1630fR4)`) --- Co-authored-by: Rajat Patra <113469515+RawJat@users.noreply.github.com>
2 parents bf0ef59 + e4beb56 commit 97e86d1

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

mcp-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@dinanathdash/envault-mcp-server",
33
"version": "1.10.0",
4+
"mcpName": "io.github.DinanathDash/envault",
45
"type": "module",
56
"description": "MCP server for Envault CLI operations",
67
"license": "SEE LICENSE IN LICENSE",

mcp-server/server.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env node
22

33
import fs from "node:fs/promises";
4+
import { realpathSync } from "node:fs";
45
import path from "node:path";
56
import { execFile } from "node:child_process";
67
import { promisify } from "node:util";
7-
import { fileURLToPath, pathToFileURL } from "node:url";
8+
import { fileURLToPath } from "node:url";
89
import crypto from "node:crypto";
910
import os from "node:os";
1011

@@ -1593,7 +1594,9 @@ async function main() {
15931594
const invokedAsScript = (() => {
15941595
try {
15951596
if (!process.argv[1]) return false;
1596-
return import.meta.url === pathToFileURL(process.argv[1]).href;
1597+
const currentModulePath = realpathSync(fileURLToPath(import.meta.url));
1598+
const argvModulePath = realpathSync(path.resolve(process.argv[1]));
1599+
return currentModulePath === argvModulePath;
15971600
} catch {
15981601
return false;
15991602
}

scripts/verify-hitl-staging.sh

100644100755
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
2-
3-
# verify-hitl-staging.sh
4-
# Creates a mock payload and sends it to the HITL pipeline to verify proper interception.
2+
# verify-hitl-staging.sh (macOS Optimized)
53

64
if [ -z "$ENVAULT_TOKEN" ] || [ -z "$ENVAULT_BASE_URL" ]; then
75
echo "Error: ENVAULT_TOKEN and ENVAULT_BASE_URL must be set."
@@ -13,8 +11,9 @@ PAYLOAD='{"project_id":"mock-project","environment":"staging","secrets":{"MOCK_S
1311

1412
echo "Testing HITL Mutation Endpoint: $ENDPOINT"
1513

16-
# Execute curl request, capturing HTTP status code and response body separately
17-
RESPONSE_FILE=$(mktemp)
14+
# macOS-safe temporary file creation
15+
RESPONSE_FILE=$(mktemp /tmp/envault_hitl.XXXXXX)
16+
1817
STATUS_CODE=$(curl -L -s -w "%{http_code}" -o "$RESPONSE_FILE" -X POST "$ENDPOINT" \
1918
-H "Authorization: Bearer $ENVAULT_TOKEN" \
2019
-H "Content-Type: application/json" \
@@ -23,7 +22,6 @@ STATUS_CODE=$(curl -L -s -w "%{http_code}" -o "$RESPONSE_FILE" -X POST "$ENDPOIN
2322
BODY=$(cat "$RESPONSE_FILE")
2423
rm -f "$RESPONSE_FILE"
2524

26-
# Evaluate the HTTP status code
2725
if [ "$STATUS_CODE" -eq 202 ]; then
2826
echo -e "\033[0;32mHITL Gate Active: Mutation safely queued for approval.\033[0m"
2927
exit 0
@@ -34,4 +32,4 @@ else
3432
echo -e "\033[0;31mError: Received HTTP $STATUS_CODE\033[0m"
3533
echo "Response Body: $BODY"
3634
exit 1
37-
fi
35+
fi

0 commit comments

Comments
 (0)