octocode-mcp 2.3.12 → 2.3.13

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/build/index.js +75 -92
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -144,29 +144,6 @@ function escapeShellArg(arg, shellType, isGitHubQuery // Flag to indicate if thi
144
144
  const isWindows = platform() === 'win32';
145
145
  shellType = isWindows ? 'cmd' : 'unix';
146
146
  }
147
- // Special handling for GitHub search queries to preserve AND logic
148
- if (isGitHubQuery) {
149
- // If the argument already contains quotes, preserve them for exact phrases
150
- if (arg.includes('"')) {
151
- // For Unix-like shells, wrap the entire argument in single quotes
152
- if (shellType === 'unix') {
153
- return `'${arg.replace(/'/g, "'\"'\"'")}'`;
154
- }
155
- // For Windows CMD
156
- if (shellType === 'cmd') {
157
- return `"${arg.replace(/"/g, '""')}"`;
158
- }
159
- // For PowerShell
160
- return `'${arg.replace(/'/g, "''")}'`;
161
- }
162
- // For space-separated terms (AND search), minimize escaping
163
- if (arg.includes(' ') && shellType === 'unix') {
164
- // Only escape if contains dangerous shell characters
165
- if (!/[;&|<>$`\\]/.test(arg)) {
166
- return `"${arg}"`;
167
- }
168
- }
169
- }
170
147
  switch (shellType) {
171
148
  case 'powershell':
172
149
  return escapePowerShellArg(arg);
@@ -174,7 +151,7 @@ function escapeShellArg(arg, shellType, isGitHubQuery // Flag to indicate if thi
174
151
  return escapeWindowsCmdArg(arg);
175
152
  case 'unix':
176
153
  default:
177
- return escapeUnixShellArg(arg, isGitHubQuery);
154
+ return escapeUnixShellArg(arg);
178
155
  }
179
156
  }
180
157
  /**
@@ -205,30 +182,10 @@ function escapeWindowsCmdArg(arg) {
205
182
  * Preserves AND search logic by not over-escaping space-separated terms
206
183
  */
207
184
  function escapeUnixShellArg(arg, isGitHubQuery) {
208
- // For GitHub search queries, we need to preserve AND logic and quoted phrases
209
- if (isGitHubQuery) {
210
- // If the query contains quotes, we need to preserve them for GitHub CLI
211
- // but escape the entire argument for the shell
212
- if (arg.includes('"')) {
213
- // Use single quotes to wrap the entire query while preserving internal quotes
214
- // This allows GitHub CLI to see: "quoted phrase" other terms
215
- return `'${arg.replace(/'/g, "'\"'\"'")}'`;
216
- }
217
- // For space-separated terms (AND search), only escape if absolutely necessary
218
- // GitHub CLI expects space-separated terms for AND logic
219
- if (arg.includes(' ') && !/[;&|<>$`\\]/.test(arg)) {
220
- // Only wrap in quotes if it contains shell metacharacters beyond spaces
221
- return `"${arg}"`;
222
- }
223
- // For single terms or terms with special chars, escape normally
224
- if (/[;&|<>$`\\]/.test(arg)) {
225
- return `'${arg.replace(/'/g, "'\"'\"'")}'`;
226
- }
227
- // Simple terms don't need escaping
228
- return arg;
229
- }
230
185
  // Standard Unix shell escaping for other arguments
231
- if (/[^a-zA-Z0-9\-_./=@:]/.test(arg)) {
186
+ // Only escape if contains dangerous shell metacharacters
187
+ // Allow common safe characters: alphanumeric, dash, underscore, dot, slash, equals, at, colon, comma
188
+ if (/[;&|<>$`\\*?()[\]{}^~]/.test(arg)) {
232
189
  return `'${arg.replace(/'/g, "'\"'\"'")}'`;
233
190
  }
234
191
  return arg;
@@ -245,7 +202,28 @@ async function executeNpmCommand(command, args = [], options = {}) {
245
202
  // Get shell configuration
246
203
  const shellConfig = getShellConfig(options.windowsShell);
247
204
  // Build command with validated prefix and properly escaped arguments
248
- const escapedArgs = args.map(arg => escapeShellArg(arg, shellConfig.type));
205
+ // NPM commands need minimal escaping - most arguments are package names or CLI flags
206
+ const escapedArgs = args.map(arg => {
207
+ const isCliFlag = arg.startsWith('--');
208
+ // CLI flags like --searchlimit=20, --json need minimal escaping
209
+ if (isCliFlag) {
210
+ // Only escape CLI flags if they contain dangerous shell characters
211
+ if (/[;&|<>$`\\]/.test(arg)) {
212
+ return escapeShellArg(arg, shellConfig.type);
213
+ }
214
+ return arg;
215
+ }
216
+ // Package names and search terms need minimal escaping
217
+ // Only escape if contains shell metacharacters that could be dangerous
218
+ if (/[;&|<>$`\\*?[\]{}]/.test(arg)) {
219
+ return escapeShellArg(arg, shellConfig.type);
220
+ }
221
+ // For arguments with spaces, use minimal quoting
222
+ if (/\s/.test(arg)) {
223
+ return `"${arg}"`;
224
+ }
225
+ return arg;
226
+ });
249
227
  const fullCommand = `npm ${command} ${escapedArgs.join(' ')}`;
250
228
  const executeNpmCommand = () => executeCommand(fullCommand, 'npm', options, shellConfig);
251
229
  if (options.cache) {
@@ -269,33 +247,40 @@ async function executeGitHubCommand(command, args = [], options = {}) {
269
247
  // Get shell configuration
270
248
  const shellConfig = getShellConfig(options.windowsShell);
271
249
  // Build command with validated prefix and properly escaped arguments
272
- // For GitHub search commands, we need to distinguish between:
273
- // 1. Main query (index 1) - needs special escaping for AND logic
274
- // 2. CLI flags (--flag=value) - standard escaping
275
- // 3. Search qualifiers (key:value) - minimal escaping
250
+ // For GitHub search commands, we need minimal escaping to avoid interfering with GitHub CLI
276
251
  const escapedArgs = args.map((arg, index) => {
277
252
  const isMainQueryArgument = command === 'search' && index === 1;
278
253
  const isCliFlag = arg.startsWith('--');
279
- const isGitHubQualifier = command === 'search' &&
280
- index > 1 &&
281
- !isCliFlag &&
282
- (arg.includes(':') || arg.startsWith('('));
283
- // CLI flags like --language=javascript, --repo=owner/repo need standard escaping
254
+ // CLI flags like --language=javascript, --repo=owner/repo need minimal escaping
284
255
  if (isCliFlag) {
285
- return escapeShellArg(arg, shellConfig.type, false);
256
+ // Only escape CLI flags if they contain dangerous shell characters
257
+ if (/[;&|<>$`\\*?[\]{}]/.test(arg)) {
258
+ return escapeShellArg(arg, shellConfig.type);
259
+ }
260
+ return arg;
286
261
  }
287
- // GitHub search qualifiers need special handling
288
- // Most qualifiers can be passed as-is, but those with shell metacharacters need escaping
289
- if (isGitHubQualifier) {
290
- // Check if the qualifier contains shell metacharacters that need escaping
291
- if (/[<>&|;`$\\]/.test(arg)) {
292
- // Escape qualifiers that contain shell metacharacters like size:<1000, size:>500
293
- return escapeShellArg(arg, shellConfig.type, false);
262
+ // For search queries, only escape if absolutely necessary for shell safety
263
+ if (isMainQueryArgument) {
264
+ // Only escape if the argument contains shell metacharacters that could be dangerous
265
+ if (/[;&|<>$`\\*?[\]{}]/.test(arg)) {
266
+ return escapeShellArg(arg, shellConfig.type);
267
+ }
268
+ // For simple queries with spaces or special chars, use minimal quoting
269
+ if (/\s/.test(arg)) {
270
+ return `"${arg}"`;
294
271
  }
295
- // Safe qualifiers like "language:typescript", "user:microsoft" can be passed as-is
296
272
  return arg;
297
273
  }
298
- return escapeShellArg(arg, shellConfig.type, isMainQueryArgument);
274
+ // For other arguments, use minimal escaping
275
+ // Only escape if contains shell metacharacters that could be dangerous
276
+ if (/[;&|<>$`\\*?[\]{}]/.test(arg)) {
277
+ return escapeShellArg(arg, shellConfig.type);
278
+ }
279
+ // For arguments with spaces, use minimal quoting
280
+ if (/\s/.test(arg)) {
281
+ return `"${arg}"`;
282
+ }
283
+ return arg;
299
284
  });
300
285
  const fullCommand = `gh ${command} ${escapedArgs.join(' ')}`;
301
286
  const executeGhCommand = () => executeCommand(fullCommand, 'github', options, shellConfig);
@@ -1355,8 +1340,8 @@ function buildGitHubCliArgs(params) {
1355
1340
  const args = ['code'];
1356
1341
  // Build search query (either exactQuery OR queryTerms, never both)
1357
1342
  if (params.exactQuery) {
1358
- // Add exact query with quotes for literal matching
1359
- args.push(`"${params.exactQuery}"`);
1343
+ // Add exact query - let GitHub CLI handle the quoting
1344
+ args.push(params.exactQuery);
1360
1345
  }
1361
1346
  else if (params.queryTerms && params.queryTerms.length > 0) {
1362
1347
  // Add query terms as separate arguments (for AND logic)
@@ -113434,23 +113419,19 @@ function buildGitHubPullRequestsListCommand(params) {
113434
113419
  const NPM_PACKAGE_SEARCH_TOOL_NAME = 'npmPackageSearch';
113435
113420
  const DESCRIPTION$3 = `Search NPM packages using 'npm search' command. Discover packages by functionality keywords and explore alternatives.
113436
113421
 
113437
- CAPABILITIES:
113438
- - Package discovery: npm search <term> --json --searchlimit=<n>
113439
- - Multiple search terms: searches each term separately and combines results
113440
- - Functional keyword search: "testing", "validation", "http client"
113441
- - Repository URL extraction for GitHub integration
113442
- - Deduplication and result optimization
113422
+ **WHEN TO USE**: Use when users ask questions about npm packages or need to discover packages - provides package discovery and ecosystem insights.
113423
+
113424
+ **KEY INSIGHTS**:
113425
+ - Another code search mechanism for npm packages (along github repository search)
113426
+ - Repo discovery by npm packages search
113427
+ - Package descriptions, keywords, and version information
113428
+ - Can be used undesrsant npm depndencies better
113443
113429
 
113444
- SEARCH STRATEGY:
113430
+ **SEARCH STRATEGY**:
113445
113431
  - Use broad functional terms for best discovery
113446
113432
  - Single keywords work better than complex phrases
113447
113433
  - Multiple searches reveal ecosystem alternatives
113448
- - Results include package names, versions, descriptions, and repository links
113449
-
113450
- USAGE EXAMPLES:
113451
- - Single search: queries="testing"
113452
- - Multiple searches: queries=["react", "hooks", "typescript"]
113453
- - Limit results: searchLimit=10`;
113434
+ - Combine with npm_view_package for detailed analysis of discovered packages`;
113454
113435
  const MAX_DESCRIPTION_LENGTH = 100;
113455
113436
  const MAX_KEYWORDS = 10;
113456
113437
  function registerNpmSearchTool(server) {
@@ -114317,18 +114298,20 @@ function buildGitHubIssuesAPICommand(params) {
114317
114298
  const NPM_VIEW_PACKAGE_TOOL_NAME = 'npmViewPackage';
114318
114299
  const DESCRIPTION = `View NPM package information using 'npm view' command. Supports field-specific queries and GitHub repository discovery.
114319
114300
 
114320
- CAPABILITIES:
114301
+ **WHEN TO USE**: Use when users ask questions about npm packages - provides comprehensive package data and insights.
114302
+
114303
+ **KEY INSIGHTS**:
114304
+ - Git repository URL for source code exploration
114305
+ - Package exports structure (understand API surface and dependencies)
114306
+ - Dependencies/devDependencies for ecosystem analysis
114307
+ - Version history, size, performance metrics
114308
+ - License and author information
114309
+
114310
+ **CAPABILITIES**:
114321
114311
  - Full package info: npm view <package> --json (optimized format)
114322
- - Single field: npm view <package> <field> (e.g., version, description, license)
114312
+ - Single field: npm view <package> <field> (version, description, license)
114323
114313
  - Multiple fields: filtered JSON response for specific fields
114324
- - Repository URLs for GitHub integration and source code analysis
114325
- - Version history, dependencies, and package metadata
114326
-
114327
- USAGE EXAMPLES:
114328
- - Get version: field="version"
114329
- - Get repository: field="repository" or match="repository"
114330
- - Get multiple: match=["version", "description", "license"]
114331
- - Get all info: no parameters (returns optimized package data)`;
114314
+ - Repository URLs for GitHub integration and source code analysis`;
114332
114315
  function registerNpmViewPackageTool(server) {
114333
114316
  server.registerTool(NPM_VIEW_PACKAGE_TOOL_NAME, {
114334
114317
  description: DESCRIPTION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "octocode-mcp",
3
- "version": "2.3.12",
3
+ "version": "2.3.13",
4
4
  "description": "Model Context Protocol (MCP) server for advanced GitHub repository analysis, code discovery, and npm package exploration. Provides AI assistants with powerful tools to search, analyze, and understand codebases across GitHub and npm ecosystems.",
5
5
  "author": "Guy Bary <guybary@gmail.com>",
6
6
  "homepage": "https://octocode.ai",