npm-run-mcp-server 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +30 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -87,18 +87,27 @@ async function main() {
87
87
  const args = parseCliArgs(process.argv);
88
88
  const startCwd = args.cwd ? resolve(String(args.cwd)) : process.cwd();
89
89
  const pkgJsonPath = await findNearestPackageJson(startCwd);
90
+ let projectDir = null;
91
+ let projectPkg = null;
90
92
  if (!pkgJsonPath) {
91
93
  console.error(`npm-run-mcp-server: No package.json found starting from ${startCwd}`);
92
- process.exit(1);
94
+ // Don't exit - start server with no tools instead
95
+ }
96
+ else {
97
+ projectDir = dirname(pkgJsonPath);
98
+ projectPkg = await readPackageJson(pkgJsonPath);
93
99
  }
94
- const projectDir = dirname(pkgJsonPath);
95
- const projectPkg = await readPackageJson(pkgJsonPath);
96
100
  const verbose = Boolean(args.verbose ||
97
101
  process.env.MCP_VERBOSE ||
98
102
  (process.env.DEBUG && process.env.DEBUG.toLowerCase().includes('mcp')));
99
103
  if (verbose) {
100
104
  console.error(`[mcp] server starting: cwd=${startCwd}`);
101
- console.error(`[mcp] using package.json: ${pkgJsonPath}`);
105
+ if (pkgJsonPath) {
106
+ console.error(`[mcp] using package.json: ${pkgJsonPath}`);
107
+ }
108
+ else {
109
+ console.error(`[mcp] no package.json found - starting with no tools`);
110
+ }
102
111
  }
103
112
  const __filename = fileURLToPath(import.meta.url);
104
113
  const __dirname = dirname(__filename);
@@ -115,11 +124,27 @@ async function main() {
115
124
  }
116
125
  }
117
126
  catch { }
127
+ const server = new McpServer({ name: serverName, version: serverVersion });
128
+ // Handle case where no package.json was found
129
+ if (!projectDir || !projectPkg) {
130
+ if (args['list-scripts']) {
131
+ console.error('No package.json found - no scripts available');
132
+ process.exit(0);
133
+ }
134
+ const transport = new StdioServerTransport();
135
+ if (verbose) {
136
+ console.error(`[mcp] no tools registered; awaiting stdio client...`);
137
+ }
138
+ await server.connect(transport);
139
+ if (verbose) {
140
+ console.error(`[mcp] stdio transport connected (waiting for initialize)`);
141
+ }
142
+ return;
143
+ }
118
144
  const pm = detectPackageManager(projectDir, projectPkg, args.pm);
119
145
  if (verbose) {
120
146
  console.error(`[mcp] detected package manager: ${pm}`);
121
147
  }
122
- const server = new McpServer({ name: serverName, version: serverVersion });
123
148
  const scripts = projectPkg.scripts ?? {};
124
149
  const scriptNames = Object.keys(scripts);
125
150
  if (scriptNames.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-run-mcp-server",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "An MCP server that exposes package.json scripts as tools for agents.",
5
5
  "bin": {
6
6
  "npm-run-mcp-server": "dist/index.js"