fix: improve basePath resolution for npx execution support#116
Merged
QuantGeekDev merged 1 commit intoQuantGeekDev:mainfrom Apr 1, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a critical issue where MCP servers fail when executed via npx due to incorrect basePath resolution. The fix implements a multi-stage resolution strategy that first checks for a project's dist directory, then falls back to intelligent module path detection.
- Replaces simple
dirname(process.argv[1])with robust multi-stage basePath resolution - Adds intelligent detection of dist directories to handle both npm and npx execution contexts
- Implements consistent resolution logic matching the existing BaseLoader approach
Contributor
|
hey @QuantGeekDev could you please take a look at this PR? |
Updated MCPServer.resolveBasePath() to use a 3-stage resolution strategy consistent with BaseLoader: check cwd/dist first, walk up from argv[1] to find dist/, then fall back to argv[1] dirname. This fixes QuantGeekDev#101 where npx execution failed because argv[1] pointed to a temp directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7bb68c1 to
6402c82
Compare
Owner
|
@PaulRBerg Thank you for your contribution, it's neat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #101 - MCP servers created with mcp-framework fail when executed via
npxwith the error "Server does not support tools (required for tools/list)".The issue occurs because the current
MCPServer.resolveBasePath()method usesdirname(process.argv[1])which points to different locations when running via:npm run start(works) ✅npx package-name(fails) ❌Solution
Updated
MCPServer.resolveBasePath()to use the same intelligent resolution strategy asBaseLoader:process.cwd() + '/dist'process.argv[1]with intelligentdist/detectionChanges Made
existsSyncimport from 'fs'resolveBasePath()method with multi-stage resolution logicbasePathconfigsTesting
✅ Verified fix works with both execution methods:
npm run start- continues to worknpx package-name- now works correctlyBenefits
basePathworkarounds needednpxdistribution