Skip to content
Open
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
18 changes: 16 additions & 2 deletions src/core/MCPServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { ToolProtocol } from '../tools/BaseTool.js';
import { PromptProtocol } from '../prompts/BasePrompt.js';
import { ResourceProtocol } from '../resources/BaseResource.js';
import { readFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';
import { join, resolve, dirname } from 'path';
import { logger } from './Logger.js';
import { ToolLoader } from '../loaders/toolLoader.js';
Expand Down Expand Up @@ -101,9 +101,23 @@ export class MCPServer {
if (configPath) {
return configPath;
}

// Try current working directory first (consistent with BaseLoader logic)
const projectRoot = process.cwd();
const distPath = join(projectRoot, 'dist');
if (existsSync(distPath)) {
logger.debug(`Using project's dist directory: ${distPath}`);
return distPath;
}

// Fallback to process.argv[1] logic with intelligent dist detection
if (process.argv[1]) {
return dirname(process.argv[1]);
const moduleDir = dirname(process.argv[1]);
const basePath = moduleDir.endsWith('dist') ? moduleDir : join(moduleDir, 'dist');
logger.debug(`Using module path-based resolution: ${basePath}`);
return basePath;
}

return process.cwd();
}

Expand Down