Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@modelcontextprotocol/sdk": "^1.9.0",
"axios": "",
"cors": "",
"dotenv": "",
"dotenv": "^17.2.0",
"express": "",
"zod": ""
},
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { resources, addResource as addResourceCore, Resource } from './resources

// Load environment variables with enhanced setup
setupEnvironment();
// Also load with standard dotenv for compatibility
dotenv.config();
// Also load with standard dotenv for compatibility.
// quiet: true suppresses dotenv v17+'s startup banner, which is written to
// stdout and would corrupt the stdio JSON-RPC stream (breaks the MCP client).
dotenv.config({ quiet: true });

// Keep a reference to the server for notifications
let serverInstance: Server | null = null;
Expand Down
13 changes: 8 additions & 5 deletions src/utils/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import dotenv from 'dotenv';
import path from 'path';
import { transformParamsToHyphenated } from './param-transformer';

// Try to load environment variables from .env file with absolute path
dotenv.config();
// Try to load environment variables from .env file with absolute path.
// quiet: true suppresses dotenv v17+'s "injecting env" banner, which is
// written to stdout and would corrupt the stdio JSON-RPC stream (this module
// is imported by index.ts, so these calls run during server startup).
dotenv.config({ quiet: true });
// Also try with explicit path as fallback
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
dotenv.config({ path: path.resolve(process.cwd(), '.env'), quiet: true });

// NASA API Base URLs
export const NASA_API_BASE_URL = 'https://api.nasa.gov';
Expand All @@ -28,7 +31,7 @@ export async function nasaApiRequest(
if (!apiKey) {
try {
const envPath = path.resolve(process.cwd(), '.env');
dotenv.config({ path: envPath });
dotenv.config({ path: envPath, quiet: true });
apiKey = process.env.NASA_API_KEY;
} catch (error) {
console.error('Error loading .env file:', error);
Expand Down Expand Up @@ -124,7 +127,7 @@ export async function jplApiRequest(
// If other JPL endpoints require a key but it's missing, try loading .env
try {
const envPath = path.resolve(process.cwd(), '.env');
dotenv.config({ path: envPath });
dotenv.config({ path: envPath, quiet: true });
apiKey = process.env.NASA_API_KEY;
if (apiKey) {
paramsToSend.api_key = apiKey;
Expand Down
18 changes: 10 additions & 8 deletions src/utils/env-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,26 @@ export function setupEnvironment() {
const rootEnvPath = path.join(currentDir, '.env');
const distEnvPath = path.join(currentDir, 'dist', '.env');

// First try standard .env loading
dotenv.config();

// First try standard .env loading.
// quiet: true suppresses dotenv v17+'s startup banner ("injecting env…"),
// which is printed to stdout and would corrupt the stdio JSON-RPC stream.
dotenv.config({ quiet: true });

// If running from dist, also try parent directory
if (currentDir.includes('dist')) {
const parentEnvPath = path.join(currentDir, '..', '.env');
if (fs.existsSync(parentEnvPath)) {
dotenv.config({ path: parentEnvPath });
dotenv.config({ path: parentEnvPath, quiet: true });
}
}

// Also try explicit paths
if (fs.existsSync(rootEnvPath)) {
dotenv.config({ path: rootEnvPath });
dotenv.config({ path: rootEnvPath, quiet: true });
}

if (fs.existsSync(distEnvPath)) {
dotenv.config({ path: distEnvPath });
dotenv.config({ path: distEnvPath, quiet: true });
}

// Ensure dist directory has a copy of .env
Expand Down
Loading