@nekzus/mcp-server 1.19.0-alpha.2 → 1.19.0-alpha.21
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.
- package/README.md +194 -278
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +32 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +384 -546
- package/dist/index.js.map +1 -1
- package/dist/src/cache.d.ts +22 -0
- package/dist/src/cache.d.ts.map +1 -0
- package/dist/src/cache.js +68 -0
- package/dist/src/cache.js.map +1 -0
- package/dist/src/config.d.ts +11 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +45 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/handlers/index.d.ts +2 -0
- package/dist/src/handlers/index.d.ts.map +1 -0
- package/dist/src/handlers/index.js +2 -0
- package/dist/src/handlers/index.js.map +1 -0
- package/dist/src/http.d.ts +16 -0
- package/dist/src/http.d.ts.map +1 -0
- package/dist/src/http.js +109 -0
- package/dist/src/http.js.map +1 -0
- package/dist/src/icons.d.ts +21 -0
- package/dist/src/icons.d.ts.map +1 -0
- package/dist/src/icons.js +29 -0
- package/dist/src/icons.js.map +1 -0
- package/dist/src/prompts/index.d.ts +3 -0
- package/dist/src/prompts/index.d.ts.map +1 -0
- package/dist/src/prompts/index.js +22 -0
- package/dist/src/prompts/index.js.map +1 -0
- package/dist/src/resources/index.d.ts +3 -0
- package/dist/src/resources/index.d.ts.map +1 -0
- package/dist/src/resources/index.js +62 -0
- package/dist/src/resources/index.js.map +1 -0
- package/dist/src/schemas.d.ts +143 -0
- package/dist/src/schemas.d.ts.map +1 -0
- package/dist/src/schemas.js +189 -0
- package/dist/src/schemas.js.map +1 -0
- package/dist/src/server.d.ts +7 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +23 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/tools/index.d.ts +4 -0
- package/dist/src/tools/index.d.ts.map +1 -0
- package/dist/src/tools/index.js +411 -0
- package/dist/src/tools/index.js.map +1 -0
- package/dist/src/utils/fetch-retry.d.ts +5 -0
- package/dist/src/utils/fetch-retry.d.ts.map +1 -0
- package/dist/src/utils/fetch-retry.js +69 -0
- package/dist/src/utils/fetch-retry.js.map +1 -0
- package/dist/src/utils/version-resolver.d.ts +14 -0
- package/dist/src/utils/version-resolver.d.ts.map +1 -0
- package/dist/src/utils/version-resolver.js +76 -0
- package/dist/src/utils/version-resolver.js.map +1 -0
- package/llms-full.txt +346 -414
- package/package.json +15 -16
- package/smithery.yaml +10 -2
package/dist/index.js
CHANGED
|
@@ -2,18 +2,49 @@
|
|
|
2
2
|
import * as crypto from 'node:crypto';
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
8
6
|
import fetch from 'node-fetch';
|
|
9
7
|
import { z } from 'zod';
|
|
8
|
+
import createServer from './src/server.js';
|
|
9
|
+
import { needsVersionResolution, resolvePackageVersion } from './src/utils/version-resolver.js';
|
|
10
10
|
// Cache configuration
|
|
11
|
-
let NPM_REGISTRY_URL = (process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org').replace(/\/$/, '');
|
|
11
|
+
export let NPM_REGISTRY_URL = (process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org').replace(/\/$/, '');
|
|
12
|
+
export function setNpmRegistryUrl(url) {
|
|
13
|
+
NPM_REGISTRY_URL = url.replace(/\/$/, '');
|
|
14
|
+
}
|
|
12
15
|
// Cache configuration
|
|
16
|
+
const CACHE_TTL_SHORT = 5 * 60 * 1000; // 5 minutes
|
|
13
17
|
const CACHE_TTL_MEDIUM = 60 * 60 * 1000; // 1 hour
|
|
14
18
|
const CACHE_TTL_LONG = 6 * 60 * 60 * 1000; // 6 hours
|
|
15
19
|
const CACHE_TTL_VERY_LONG = 24 * 60 * 60 * 1000; // 24 hours
|
|
16
20
|
const MAX_CACHE_SIZE = 500; // Max number of items in cache
|
|
21
|
+
async function resolveVersionIfShorthand(name, version) {
|
|
22
|
+
if (!needsVersionResolution(version)) {
|
|
23
|
+
return version;
|
|
24
|
+
}
|
|
25
|
+
const cacheKey = generateCacheKey('abbreviatedPackument', name);
|
|
26
|
+
let packument = cacheGet(cacheKey);
|
|
27
|
+
if (!packument) {
|
|
28
|
+
try {
|
|
29
|
+
const res = await fetchWithRetry(`${NPM_REGISTRY_URL}/${encodeURIComponent(name)}`, {
|
|
30
|
+
headers: { Accept: 'application/vnd.npm.install-v1+json' },
|
|
31
|
+
});
|
|
32
|
+
if (res.ok) {
|
|
33
|
+
packument = await res.json();
|
|
34
|
+
cacheSet(cacheKey, packument, CACHE_TTL_SHORT);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Ignore error and fall back to original version
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (packument) {
|
|
42
|
+
const resolved = resolvePackageVersion(packument, version);
|
|
43
|
+
if (resolved)
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
46
|
+
return version;
|
|
47
|
+
}
|
|
17
48
|
const apiCache = new Map();
|
|
18
49
|
let currentLockfileHash = null;
|
|
19
50
|
function getLockfileHash() {
|
|
@@ -117,7 +148,7 @@ export async function fetchWithRetry(url, options = {}, config = {}) {
|
|
|
117
148
|
const retryAfter = response.headers.get('retry-after');
|
|
118
149
|
const waitMs = retryAfter
|
|
119
150
|
? parseInt(retryAfter, 10) * 1000
|
|
120
|
-
: HTTP_INITIAL_BACKOFF_MS *
|
|
151
|
+
: HTTP_INITIAL_BACKOFF_MS * 2 ** attempt;
|
|
121
152
|
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
122
153
|
continue;
|
|
123
154
|
}
|
|
@@ -126,7 +157,7 @@ export async function fetchWithRetry(url, options = {}, config = {}) {
|
|
|
126
157
|
}
|
|
127
158
|
catch (err) {
|
|
128
159
|
if (attempt < maxRetries) {
|
|
129
|
-
const waitMs = HTTP_INITIAL_BACKOFF_MS *
|
|
160
|
+
const waitMs = HTTP_INITIAL_BACKOFF_MS * 2 ** attempt;
|
|
130
161
|
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
131
162
|
continue;
|
|
132
163
|
}
|
|
@@ -334,11 +365,24 @@ function isValidNpmPackageName(name) {
|
|
|
334
365
|
!name.startsWith('_') &&
|
|
335
366
|
!name.startsWith('.'));
|
|
336
367
|
}
|
|
368
|
+
export function createEmptyArrayErrorResponse(toolName) {
|
|
369
|
+
const errorResponse = JSON.stringify({
|
|
370
|
+
queryPackages: [],
|
|
371
|
+
results: [],
|
|
372
|
+
status: 'error',
|
|
373
|
+
error: 'No package names provided in request',
|
|
374
|
+
message: `The packages parameter for ${toolName} must contain at least one package name.`,
|
|
375
|
+
}, null, 2);
|
|
376
|
+
return {
|
|
377
|
+
content: [{ type: 'text', text: errorResponse }],
|
|
378
|
+
isError: true,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
337
381
|
export async function handleNpmVersions(args) {
|
|
338
382
|
try {
|
|
339
383
|
const packagesToProcess = args.packages || [];
|
|
340
384
|
if (packagesToProcess.length === 0) {
|
|
341
|
-
|
|
385
|
+
return createEmptyArrayErrorResponse('npmVersions');
|
|
342
386
|
}
|
|
343
387
|
const processedResults = await Promise.all(packagesToProcess.map(async (pkgInput) => {
|
|
344
388
|
let name = '';
|
|
@@ -463,7 +507,7 @@ export async function handleNpmLatest(args) {
|
|
|
463
507
|
try {
|
|
464
508
|
const packagesToProcess = args.packages || [];
|
|
465
509
|
if (packagesToProcess.length === 0) {
|
|
466
|
-
|
|
510
|
+
return createEmptyArrayErrorResponse('npmLatest');
|
|
467
511
|
}
|
|
468
512
|
const processedResults = await Promise.all(packagesToProcess.map(async (pkgInput) => {
|
|
469
513
|
let name = '';
|
|
@@ -525,7 +569,8 @@ export async function handleNpmLatest(args) {
|
|
|
525
569
|
};
|
|
526
570
|
}
|
|
527
571
|
try {
|
|
528
|
-
const
|
|
572
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, versionTag);
|
|
573
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
529
574
|
if (!response.ok) {
|
|
530
575
|
let errorMsg = `Failed to fetch package version: ${response.status} ${response.statusText}`;
|
|
531
576
|
if (response.status === 404) {
|
|
@@ -659,7 +704,8 @@ export async function handleNpmDeps(args) {
|
|
|
659
704
|
};
|
|
660
705
|
}
|
|
661
706
|
try {
|
|
662
|
-
const
|
|
707
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, version);
|
|
708
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
663
709
|
if (!response.ok) {
|
|
664
710
|
return {
|
|
665
711
|
package: packageNameForOutput,
|
|
@@ -785,7 +831,8 @@ export async function handleNpmTypes(args) {
|
|
|
785
831
|
};
|
|
786
832
|
}
|
|
787
833
|
try {
|
|
788
|
-
const
|
|
834
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, version);
|
|
835
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
789
836
|
if (!response.ok) {
|
|
790
837
|
return {
|
|
791
838
|
package: packageNameForOutput,
|
|
@@ -1014,6 +1061,47 @@ async function fetchTransitiveDependenciesFromDepsDev(pkgName, version) {
|
|
|
1014
1061
|
return [];
|
|
1015
1062
|
}
|
|
1016
1063
|
}
|
|
1064
|
+
export async function fetchRepoStatsFromDepsDev(owner, repo, ignoreCache = false) {
|
|
1065
|
+
const projectKey = encodeURIComponent(`github.com/${owner}/${repo}`);
|
|
1066
|
+
const cacheKey = generateCacheKey('depsDevProject', owner, repo);
|
|
1067
|
+
const cached = ignoreCache ? undefined : cacheGet(cacheKey);
|
|
1068
|
+
if (cached)
|
|
1069
|
+
return cached;
|
|
1070
|
+
try {
|
|
1071
|
+
const response = await fetchWithRetry(`https://api.deps.dev/v3alpha/projects/${projectKey}`, {}, { maxRetries: 1 });
|
|
1072
|
+
if (!response.ok)
|
|
1073
|
+
return null;
|
|
1074
|
+
const data = (await response.json());
|
|
1075
|
+
const result = {
|
|
1076
|
+
starsCount: data.starsCount ?? 0,
|
|
1077
|
+
forksCount: data.forksCount ?? 0,
|
|
1078
|
+
openIssuesCount: data.openIssuesCount ?? 0,
|
|
1079
|
+
license: data.license ?? 'unknown',
|
|
1080
|
+
description: data.description ?? '',
|
|
1081
|
+
homepage: data.homepage ?? '',
|
|
1082
|
+
scorecard: data.scorecard
|
|
1083
|
+
? {
|
|
1084
|
+
overallScore: data.scorecard.overallScore,
|
|
1085
|
+
checks: (data.scorecard.checks || []).map((c) => ({
|
|
1086
|
+
name: c.name,
|
|
1087
|
+
score: c.score,
|
|
1088
|
+
reason: c.reason &&
|
|
1089
|
+
(c.score === -1 || c.reason.toLowerCase().includes('internal error')) &&
|
|
1090
|
+
(c.reason.toLowerCase().includes('internal error') ||
|
|
1091
|
+
c.reason.toLowerCase().includes('classic branch protection rules'))
|
|
1092
|
+
? 'Check not evaluated due to upstream OpenSSF Scorecard API permission limits'
|
|
1093
|
+
: c.reason || 'No details provided',
|
|
1094
|
+
})),
|
|
1095
|
+
}
|
|
1096
|
+
: undefined,
|
|
1097
|
+
};
|
|
1098
|
+
cacheSet(cacheKey, result, CACHE_TTL_VERY_LONG);
|
|
1099
|
+
return result;
|
|
1100
|
+
}
|
|
1101
|
+
catch {
|
|
1102
|
+
return null;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1017
1105
|
// Helper to resolve 'latest' tag to actual version number
|
|
1018
1106
|
async function resolveLatestVersion(packageName) {
|
|
1019
1107
|
try {
|
|
@@ -1176,7 +1264,7 @@ export async function handleNpmVulnerabilities(args) {
|
|
|
1176
1264
|
// Start fetching dependencies with deps.dev
|
|
1177
1265
|
await processPackage(name, version);
|
|
1178
1266
|
// Ecosystem Check: Scan associated packages that share the same version
|
|
1179
|
-
if (ECOSYSTEM_MAP[name]) {
|
|
1267
|
+
if (Object.hasOwn(ECOSYSTEM_MAP, name) && Array.isArray(ECOSYSTEM_MAP[name])) {
|
|
1180
1268
|
for (const associatedPkg of ECOSYSTEM_MAP[name]) {
|
|
1181
1269
|
await processPackage(associatedPkg, version);
|
|
1182
1270
|
}
|
|
@@ -1221,9 +1309,25 @@ export async function handleNpmVulnerabilities(args) {
|
|
|
1221
1309
|
// Fetch full details
|
|
1222
1310
|
const richData = await enrichVulnerabilityData(vuln.id, args.ignoreCache);
|
|
1223
1311
|
const finalVuln = richData || vuln; // Fallback to basic if fetch fails
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1312
|
+
let sev = 'Unknown';
|
|
1313
|
+
if (typeof finalVuln.database_specific?.severity === 'string') {
|
|
1314
|
+
sev = finalVuln.database_specific.severity;
|
|
1315
|
+
}
|
|
1316
|
+
else if (Array.isArray(finalVuln.severity) && finalVuln.severity.length > 0) {
|
|
1317
|
+
const first = finalVuln.severity[0];
|
|
1318
|
+
if (typeof first === 'string') {
|
|
1319
|
+
sev = first;
|
|
1320
|
+
}
|
|
1321
|
+
else if (first && typeof first === 'object') {
|
|
1322
|
+
sev = first.score || first.type || 'Unknown';
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
else if (typeof finalVuln.severity === 'string') {
|
|
1326
|
+
sev = finalVuln.severity;
|
|
1327
|
+
}
|
|
1328
|
+
else if (typeof finalVuln.ecosystem_specific?.severity === 'string') {
|
|
1329
|
+
sev = finalVuln.ecosystem_specific.severity;
|
|
1330
|
+
}
|
|
1227
1331
|
const refs = finalVuln.references ? finalVuln.references.map((r) => r.url) : [];
|
|
1228
1332
|
const vulnerabilityDetails = {
|
|
1229
1333
|
id: finalVuln.id,
|
|
@@ -1493,8 +1597,9 @@ export async function handleNpmCompare(args) {
|
|
|
1493
1597
|
};
|
|
1494
1598
|
}
|
|
1495
1599
|
try {
|
|
1600
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, versionTag);
|
|
1496
1601
|
// Fetch package version details from registry
|
|
1497
|
-
const pkgResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${
|
|
1602
|
+
const pkgResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
1498
1603
|
if (!pkgResponse.ok) {
|
|
1499
1604
|
throw new Error(`Failed to fetch package info for ${name}@${versionTag}: ${pkgResponse.status} ${pkgResponse.statusText}`);
|
|
1500
1605
|
}
|
|
@@ -1619,7 +1724,7 @@ export async function getLocalPackageMetrics(name, ignoreCache = false) {
|
|
|
1619
1724
|
catch (dlError) {
|
|
1620
1725
|
console.debug(`Could not fetch downloads for ${name}: ${dlError}`);
|
|
1621
1726
|
}
|
|
1622
|
-
// 3. Fetch GitHub stats (optional, graceful degradation)
|
|
1727
|
+
// 3. Fetch GitHub stats via deps.dev (optional, graceful degradation)
|
|
1623
1728
|
let github = {
|
|
1624
1729
|
starsCount: 0,
|
|
1625
1730
|
forksCount: 0,
|
|
@@ -1627,6 +1732,7 @@ export async function getLocalPackageMetrics(name, ignoreCache = false) {
|
|
|
1627
1732
|
openIssuesCount: 0,
|
|
1628
1733
|
hasGitHubData: false,
|
|
1629
1734
|
};
|
|
1735
|
+
let scorecard;
|
|
1630
1736
|
const repoUrl = versionData.repository?.url || packageInfo.repository?.url;
|
|
1631
1737
|
if (repoUrl?.includes('github.com')) {
|
|
1632
1738
|
const githubMatch = repoUrl.match(/github\.com[:/]([^/]+)\/([^/.]+)/);
|
|
@@ -1634,20 +1740,20 @@ export async function getLocalPackageMetrics(name, ignoreCache = false) {
|
|
|
1634
1740
|
const [, owner, repo] = githubMatch;
|
|
1635
1741
|
const cleanRepo = repo.replace(/\.git$/, '');
|
|
1636
1742
|
try {
|
|
1637
|
-
const
|
|
1638
|
-
if (
|
|
1639
|
-
const ghData = await ghResponse.json();
|
|
1743
|
+
const depsDevData = await fetchRepoStatsFromDepsDev(owner, cleanRepo, ignoreCache);
|
|
1744
|
+
if (depsDevData) {
|
|
1640
1745
|
github = {
|
|
1641
|
-
starsCount:
|
|
1642
|
-
forksCount:
|
|
1643
|
-
subscribersCount:
|
|
1644
|
-
openIssuesCount:
|
|
1746
|
+
starsCount: depsDevData.starsCount,
|
|
1747
|
+
forksCount: depsDevData.forksCount,
|
|
1748
|
+
subscribersCount: 0,
|
|
1749
|
+
openIssuesCount: depsDevData.openIssuesCount,
|
|
1645
1750
|
hasGitHubData: true,
|
|
1646
1751
|
};
|
|
1752
|
+
scorecard = depsDevData.scorecard;
|
|
1647
1753
|
}
|
|
1648
1754
|
}
|
|
1649
1755
|
catch (ghError) {
|
|
1650
|
-
console.debug(`Could not fetch
|
|
1756
|
+
console.debug(`Could not fetch deps.dev project data for ${owner}/${cleanRepo}: ${ghError}`);
|
|
1651
1757
|
}
|
|
1652
1758
|
}
|
|
1653
1759
|
}
|
|
@@ -1664,19 +1770,20 @@ export async function getLocalPackageMetrics(name, ignoreCache = false) {
|
|
|
1664
1770
|
let popularity = popularityNPM;
|
|
1665
1771
|
if (github.hasGitHubData) {
|
|
1666
1772
|
const popularityGH = Math.min(1, github.starsCount / 50000);
|
|
1667
|
-
popularity =
|
|
1668
|
-
}
|
|
1669
|
-
const quality = (
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
: lastPublishDaysAgo < 365
|
|
1773
|
+
popularity = popularityNPM * 0.7 + popularityGH * 0.3;
|
|
1774
|
+
}
|
|
1775
|
+
const quality = (hasTypes ? 0.3 : 0) + (hasReadme ? 0.2 : 0) + Math.max(0, 0.5 - dependencyCount * 0.005);
|
|
1776
|
+
const maintenancePublish = lastPublishDaysAgo < 30
|
|
1777
|
+
? 1.0
|
|
1778
|
+
: lastPublishDaysAgo < 90
|
|
1779
|
+
? 0.8
|
|
1780
|
+
: lastPublishDaysAgo < 365
|
|
1781
|
+
? 0.5
|
|
1675
1782
|
: 0.2;
|
|
1676
1783
|
let maintenance = maintenancePublish;
|
|
1677
1784
|
if (github.hasGitHubData) {
|
|
1678
1785
|
const issuesScore = github.openIssuesCount < 50 ? 0.3 : github.openIssuesCount < 200 ? 0.2 : 0.1;
|
|
1679
|
-
maintenance =
|
|
1786
|
+
maintenance = maintenancePublish * 0.7 + issuesScore;
|
|
1680
1787
|
}
|
|
1681
1788
|
const finalScore = popularity * 0.4 + quality * 0.3 + maintenance * 0.3;
|
|
1682
1789
|
const result = {
|
|
@@ -1694,6 +1801,7 @@ export async function getLocalPackageMetrics(name, ignoreCache = false) {
|
|
|
1694
1801
|
maintenance,
|
|
1695
1802
|
},
|
|
1696
1803
|
},
|
|
1804
|
+
scorecard,
|
|
1697
1805
|
};
|
|
1698
1806
|
cacheSet(cacheKey, result, CACHE_TTL_LONG);
|
|
1699
1807
|
return result;
|
|
@@ -2108,6 +2216,7 @@ export async function handleNpmScore(args) {
|
|
|
2108
2216
|
},
|
|
2109
2217
|
}
|
|
2110
2218
|
: null,
|
|
2219
|
+
scorecard: metrics.scorecard,
|
|
2111
2220
|
};
|
|
2112
2221
|
cacheSet(cacheKey, scoreData, CACHE_TTL_LONG);
|
|
2113
2222
|
return {
|
|
@@ -2267,8 +2376,8 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2267
2376
|
data: null,
|
|
2268
2377
|
};
|
|
2269
2378
|
}
|
|
2270
|
-
const versionToUse = versionTag
|
|
2271
|
-
if (!versionToUse || !packageInfo.versions
|
|
2379
|
+
const versionToUse = resolvePackageVersion(packageInfo, versionTag) || versionTag;
|
|
2380
|
+
if (!versionToUse || !packageInfo.versions?.[versionToUse]) {
|
|
2272
2381
|
return {
|
|
2273
2382
|
packageInput: pkgInput,
|
|
2274
2383
|
packageName: name,
|
|
@@ -2290,8 +2399,11 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2290
2399
|
}
|
|
2291
2400
|
}
|
|
2292
2401
|
const hasReadme = !!readmeContent;
|
|
2402
|
+
const demarcatedReadme = readmeContent
|
|
2403
|
+
? `<untrusted_external_content source="${readmeSource || 'registry'}" package="${name}" type="readme">\n${readmeContent}\n</untrusted_external_content>`
|
|
2404
|
+
: null;
|
|
2293
2405
|
const readmeResultData = {
|
|
2294
|
-
readme:
|
|
2406
|
+
readme: demarcatedReadme,
|
|
2295
2407
|
hasReadme: hasReadme,
|
|
2296
2408
|
readmeSource: readmeSource,
|
|
2297
2409
|
versionFetched: versionToUse, // Store the actually fetched version
|
|
@@ -2304,7 +2416,7 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2304
2416
|
versionFetched: versionToUse,
|
|
2305
2417
|
status: 'success',
|
|
2306
2418
|
error: null,
|
|
2307
|
-
data: { readme:
|
|
2419
|
+
data: { readme: demarcatedReadme, hasReadme: hasReadme, readmeSource: readmeSource },
|
|
2308
2420
|
message: `Successfully fetched README for ${name}@${versionToUse}.`,
|
|
2309
2421
|
};
|
|
2310
2422
|
}
|
|
@@ -2326,7 +2438,19 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2326
2438
|
message: `README fetching status for ${args.packages.length} package(s).`,
|
|
2327
2439
|
};
|
|
2328
2440
|
const responseJson = JSON.stringify(finalResponse, null, 2);
|
|
2329
|
-
return {
|
|
2441
|
+
return {
|
|
2442
|
+
content: [
|
|
2443
|
+
{
|
|
2444
|
+
type: 'text',
|
|
2445
|
+
text: responseJson,
|
|
2446
|
+
_meta: {
|
|
2447
|
+
untrustedExternalContent: true,
|
|
2448
|
+
sources: ['npm-registry', 'cdn'],
|
|
2449
|
+
},
|
|
2450
|
+
},
|
|
2451
|
+
],
|
|
2452
|
+
isError: false,
|
|
2453
|
+
};
|
|
2330
2454
|
}
|
|
2331
2455
|
catch (error) {
|
|
2332
2456
|
const errorResponse = JSON.stringify({
|
|
@@ -2496,7 +2620,8 @@ export async function handleNpmLicenseCompatibility(args) {
|
|
|
2496
2620
|
};
|
|
2497
2621
|
}
|
|
2498
2622
|
try {
|
|
2499
|
-
const
|
|
2623
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, versionTag);
|
|
2624
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
2500
2625
|
if (!response.ok) {
|
|
2501
2626
|
let errorMsg = `Failed to fetch package info: ${response.status} ${response.statusText}`;
|
|
2502
2627
|
if (response.status === 404) {
|
|
@@ -2723,43 +2848,48 @@ export async function handleNpmRepoStats(args) {
|
|
|
2723
2848
|
return resultNotGitHub;
|
|
2724
2849
|
}
|
|
2725
2850
|
const [, owner, repo] = githubMatch;
|
|
2726
|
-
const
|
|
2727
|
-
const
|
|
2728
|
-
|
|
2729
|
-
Accept: 'application/vnd.github.v3+json',
|
|
2730
|
-
},
|
|
2731
|
-
});
|
|
2732
|
-
if (!githubResponse.ok) {
|
|
2851
|
+
const cleanRepo = repo.replace(/\.git$/, '');
|
|
2852
|
+
const depsDevData = await fetchRepoStatsFromDepsDev(owner, cleanRepo, args.ignoreCache);
|
|
2853
|
+
if (!depsDevData) {
|
|
2733
2854
|
const errorData = {
|
|
2734
2855
|
packageInput: pkgInput,
|
|
2735
2856
|
packageName: name,
|
|
2736
2857
|
status: 'error',
|
|
2737
|
-
error: `Failed to fetch
|
|
2738
|
-
data: {
|
|
2739
|
-
message: `Could not retrieve
|
|
2858
|
+
error: `Failed to fetch project stats for github.com/${owner}/${cleanRepo} from deps.dev`,
|
|
2859
|
+
data: { repositoryUrl: repoUrl },
|
|
2860
|
+
message: `Could not retrieve repository statistics from deps.dev.`,
|
|
2740
2861
|
};
|
|
2741
|
-
// Do not cache GitHub API call failures for now
|
|
2742
2862
|
return errorData;
|
|
2743
2863
|
}
|
|
2744
|
-
|
|
2864
|
+
let ghRepoMeta = {};
|
|
2865
|
+
try {
|
|
2866
|
+
const ghResponse = await fetchWithRetry(`https://api.github.com/repos/${owner}/${cleanRepo}`, { headers: { Accept: 'application/vnd.github.v3+json' } }, { maxRetries: 0 });
|
|
2867
|
+
if (ghResponse.ok) {
|
|
2868
|
+
ghRepoMeta = await ghResponse.json();
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
catch {
|
|
2872
|
+
// Optional GitHub REST API fallback
|
|
2873
|
+
}
|
|
2745
2874
|
const successResult = {
|
|
2746
2875
|
packageInput: pkgInput,
|
|
2747
2876
|
packageName: name,
|
|
2748
2877
|
status: 'success',
|
|
2749
2878
|
error: null,
|
|
2750
2879
|
data: {
|
|
2751
|
-
githubRepoUrl: `https://github.com/${owner}/${
|
|
2752
|
-
stars:
|
|
2753
|
-
forks:
|
|
2754
|
-
openIssues:
|
|
2755
|
-
watchers:
|
|
2756
|
-
createdAt:
|
|
2757
|
-
updatedAt:
|
|
2758
|
-
defaultBranch:
|
|
2759
|
-
hasWiki:
|
|
2760
|
-
topics:
|
|
2880
|
+
githubRepoUrl: `https://github.com/${owner}/${cleanRepo}`,
|
|
2881
|
+
stars: depsDevData.starsCount || ghRepoMeta.stargazers_count || 0,
|
|
2882
|
+
forks: depsDevData.forksCount || ghRepoMeta.forks_count || 0,
|
|
2883
|
+
openIssues: depsDevData.openIssuesCount || ghRepoMeta.open_issues_count || 0,
|
|
2884
|
+
watchers: ghRepoMeta.subscribers_count || ghRepoMeta.watchers_count || 0,
|
|
2885
|
+
createdAt: ghRepoMeta.created_at || null,
|
|
2886
|
+
updatedAt: ghRepoMeta.pushed_at || ghRepoMeta.updated_at || null,
|
|
2887
|
+
defaultBranch: ghRepoMeta.default_branch || null,
|
|
2888
|
+
hasWiki: typeof ghRepoMeta.has_wiki === 'boolean' ? ghRepoMeta.has_wiki : null,
|
|
2889
|
+
topics: Array.isArray(ghRepoMeta.topics) ? ghRepoMeta.topics : [],
|
|
2890
|
+
scorecard: depsDevData.scorecard,
|
|
2761
2891
|
},
|
|
2762
|
-
message: '
|
|
2892
|
+
message: 'Repository statistics fetched successfully from deps.dev and GitHub API.',
|
|
2763
2893
|
};
|
|
2764
2894
|
cacheSet(cacheKey, successResult, CACHE_TTL_LONG);
|
|
2765
2895
|
return successResult;
|
|
@@ -2858,16 +2988,7 @@ export async function handleNpmDeprecated(args) {
|
|
|
2858
2988
|
};
|
|
2859
2989
|
}
|
|
2860
2990
|
const mainPkgData = (await mainPkgResponse.json());
|
|
2861
|
-
|
|
2862
|
-
if (version === 'latest') {
|
|
2863
|
-
versionToFetch = mainPkgData['dist-tags']?.latest || 'latest';
|
|
2864
|
-
if (versionToFetch === 'latest' && !mainPkgData.versions?.[versionToFetch]) {
|
|
2865
|
-
const availableVersions = Object.keys(mainPkgData.versions || {});
|
|
2866
|
-
if (availableVersions.length > 0) {
|
|
2867
|
-
versionToFetch = availableVersions.sort().pop() || 'latest'; // Basic sort
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2991
|
+
const versionToFetch = resolvePackageVersion(mainPkgData, version) || version;
|
|
2871
2992
|
const finalPackageNameForOutput = `${name}@${versionToFetch}`;
|
|
2872
2993
|
const versionInfo = mainPkgData.versions?.[versionToFetch];
|
|
2873
2994
|
if (!versionInfo) {
|
|
@@ -3137,20 +3258,24 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3137
3258
|
let changelogContent = null;
|
|
3138
3259
|
let changelogSourceUrl = null;
|
|
3139
3260
|
let hasChangelogFile = false;
|
|
3140
|
-
for (const
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3261
|
+
for (const branch of ['main', 'master']) {
|
|
3262
|
+
for (const file of changelogFiles) {
|
|
3263
|
+
try {
|
|
3264
|
+
const rawChangelogUrl = `https://raw.githubusercontent.com/${owner}/${repoNameForUrl}/${branch}/${file}`;
|
|
3265
|
+
const response = await fetchWithRetry(rawChangelogUrl, {}, { maxRetries: 0 });
|
|
3266
|
+
if (response.ok) {
|
|
3267
|
+
changelogContent = await response.text();
|
|
3268
|
+
changelogSourceUrl = rawChangelogUrl;
|
|
3269
|
+
hasChangelogFile = true;
|
|
3270
|
+
break;
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
catch {
|
|
3274
|
+
// Sigue intentando
|
|
3149
3275
|
}
|
|
3150
3276
|
}
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
}
|
|
3277
|
+
if (hasChangelogFile)
|
|
3278
|
+
break;
|
|
3154
3279
|
}
|
|
3155
3280
|
let githubReleases = [];
|
|
3156
3281
|
try {
|
|
@@ -3158,19 +3283,34 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3158
3283
|
headers: {
|
|
3159
3284
|
Accept: 'application/vnd.github.v3+json',
|
|
3160
3285
|
},
|
|
3161
|
-
});
|
|
3286
|
+
}, { maxRetries: 0 });
|
|
3162
3287
|
if (githubApiResponse.ok) {
|
|
3163
3288
|
const releasesData = (await githubApiResponse.json());
|
|
3164
3289
|
githubReleases = releasesData.map((r) => ({
|
|
3165
3290
|
tag_name: r.tag_name || null,
|
|
3166
3291
|
name: r.name || null,
|
|
3167
3292
|
published_at: r.published_at || null,
|
|
3293
|
+
source: 'github-api',
|
|
3168
3294
|
}));
|
|
3169
3295
|
}
|
|
3170
3296
|
}
|
|
3171
3297
|
catch (error) {
|
|
3172
3298
|
console.debug(`Error fetching GitHub releases for ${name}: ${error}`);
|
|
3173
3299
|
}
|
|
3300
|
+
// Fallback to NPM Registry time/publish history if GitHub releases couldn't be fetched
|
|
3301
|
+
const publishTime = npmData.time;
|
|
3302
|
+
if (githubReleases.length === 0 && publishTime) {
|
|
3303
|
+
const timeKeys = Object.keys(publishTime).filter((k) => k !== 'modified' && k !== 'created');
|
|
3304
|
+
const sortedVersions = timeKeys.sort((a, b) => {
|
|
3305
|
+
return new Date(publishTime[b]).getTime() - new Date(publishTime[a]).getTime();
|
|
3306
|
+
});
|
|
3307
|
+
githubReleases = sortedVersions.slice(0, 5).map((v) => ({
|
|
3308
|
+
tag_name: `v${v}`,
|
|
3309
|
+
name: `Release ${v} (NPM Publish)`,
|
|
3310
|
+
published_at: publishTime[v],
|
|
3311
|
+
source: 'npm-registry',
|
|
3312
|
+
}));
|
|
3313
|
+
}
|
|
3174
3314
|
const versions = Object.keys(npmData.versions || {});
|
|
3175
3315
|
const npmVersionHistory = {
|
|
3176
3316
|
totalVersions: versions.length,
|
|
@@ -3184,7 +3324,7 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3184
3324
|
? `No changelog file or GitHub releases found for ${name}.`
|
|
3185
3325
|
: `Changelog analysis for ${name}.`;
|
|
3186
3326
|
const resultToCache = {
|
|
3187
|
-
packageInput: pkgInput,
|
|
3327
|
+
packageInput: pkgInput,
|
|
3188
3328
|
packageName: name,
|
|
3189
3329
|
versionQueried: versionQueried,
|
|
3190
3330
|
status: status,
|
|
@@ -3193,7 +3333,7 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3193
3333
|
repositoryUrl: repositoryUrl,
|
|
3194
3334
|
changelogSourceUrl: changelogSourceUrl,
|
|
3195
3335
|
changelogContent: changelogContent
|
|
3196
|
-
?
|
|
3336
|
+
? `<untrusted_external_content source="${changelogSourceUrl || 'github'}" package="${name}" type="changelog">\n${changelogContent.split('\n').slice(0, 50).join('\n')}...\n</untrusted_external_content>`
|
|
3197
3337
|
: null,
|
|
3198
3338
|
hasChangelogFile: hasChangelogFile,
|
|
3199
3339
|
githubReleases: githubReleases,
|
|
@@ -3222,7 +3362,19 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3222
3362
|
results: processedResults,
|
|
3223
3363
|
};
|
|
3224
3364
|
const responseJson = JSON.stringify(finalResponse, null, 2);
|
|
3225
|
-
return {
|
|
3365
|
+
return {
|
|
3366
|
+
content: [
|
|
3367
|
+
{
|
|
3368
|
+
type: 'text',
|
|
3369
|
+
text: responseJson,
|
|
3370
|
+
_meta: {
|
|
3371
|
+
untrustedExternalContent: true,
|
|
3372
|
+
sources: ['github-releases', 'github-raw', 'npm-registry'],
|
|
3373
|
+
},
|
|
3374
|
+
},
|
|
3375
|
+
],
|
|
3376
|
+
isError: false,
|
|
3377
|
+
};
|
|
3226
3378
|
}
|
|
3227
3379
|
catch (error) {
|
|
3228
3380
|
const errorResponse = JSON.stringify({
|
|
@@ -3236,11 +3388,38 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3236
3388
|
};
|
|
3237
3389
|
}
|
|
3238
3390
|
}
|
|
3391
|
+
function isAlternativeCandidate(candidateName, candidateDesc, originalName) {
|
|
3392
|
+
const lowerCandidate = candidateName.toLowerCase();
|
|
3393
|
+
const lowerOriginal = originalName.toLowerCase();
|
|
3394
|
+
const lowerDesc = (candidateDesc || '').toLowerCase();
|
|
3395
|
+
if (lowerCandidate === lowerOriginal)
|
|
3396
|
+
return false;
|
|
3397
|
+
if (lowerCandidate.startsWith('@types/'))
|
|
3398
|
+
return false;
|
|
3399
|
+
if (lowerCandidate.startsWith(`${lowerOriginal}-`) ||
|
|
3400
|
+
lowerCandidate.startsWith(`${lowerOriginal}_`) ||
|
|
3401
|
+
lowerCandidate.startsWith(`${lowerOriginal}.`) ||
|
|
3402
|
+
lowerCandidate.endsWith(`-${lowerOriginal}`) ||
|
|
3403
|
+
lowerCandidate.endsWith(`_${lowerOriginal}`) ||
|
|
3404
|
+
lowerCandidate.includes(lowerOriginal)) {
|
|
3405
|
+
return false;
|
|
3406
|
+
}
|
|
3407
|
+
if (lowerDesc.includes(`middleware for ${lowerOriginal}`) ||
|
|
3408
|
+
lowerDesc.includes(`plugin for ${lowerOriginal}`) ||
|
|
3409
|
+
lowerDesc.includes(`adapter for ${lowerOriginal}`) ||
|
|
3410
|
+
lowerDesc.includes(`wrapper for ${lowerOriginal}`) ||
|
|
3411
|
+
lowerDesc.includes(`extension for ${lowerOriginal}`) ||
|
|
3412
|
+
lowerDesc.includes(`${lowerOriginal} middleware`) ||
|
|
3413
|
+
lowerDesc.includes(`${lowerOriginal} plugin`)) {
|
|
3414
|
+
return false;
|
|
3415
|
+
}
|
|
3416
|
+
return true;
|
|
3417
|
+
}
|
|
3239
3418
|
export async function handleNpmAlternatives(args) {
|
|
3240
3419
|
try {
|
|
3241
3420
|
const packagesToProcess = args.packages || [];
|
|
3242
3421
|
if (packagesToProcess.length === 0) {
|
|
3243
|
-
|
|
3422
|
+
return createEmptyArrayErrorResponse('npmAlternatives');
|
|
3244
3423
|
}
|
|
3245
3424
|
const processedResults = await Promise.all(packagesToProcess.map(async (pkgInput) => {
|
|
3246
3425
|
let originalPackageName = '';
|
|
@@ -3284,33 +3463,31 @@ export async function handleNpmAlternatives(args) {
|
|
|
3284
3463
|
};
|
|
3285
3464
|
}
|
|
3286
3465
|
const cacheKey = generateCacheKey('handleNpmAlternatives', originalPackageName);
|
|
3287
|
-
const cachedResult = args.ignoreCache ? undefined : cacheGet(cacheKey);
|
|
3466
|
+
const cachedResult = args.ignoreCache ? undefined : cacheGet(cacheKey);
|
|
3288
3467
|
if (cachedResult) {
|
|
3289
3468
|
return {
|
|
3290
3469
|
...cachedResult,
|
|
3291
|
-
packageInput: pkgInput,
|
|
3292
|
-
packageName: originalPackageName,
|
|
3293
|
-
// versionQueried is part of cachedResult.data or similar if stored, or add if needed
|
|
3470
|
+
packageInput: pkgInput,
|
|
3471
|
+
packageName: originalPackageName,
|
|
3294
3472
|
status: `${cachedResult.status}_cache`,
|
|
3295
3473
|
message: `${cachedResult.message} (from cache)`,
|
|
3296
3474
|
};
|
|
3297
3475
|
}
|
|
3298
3476
|
try {
|
|
3299
|
-
|
|
3300
|
-
if (!searchResponse.ok) {
|
|
3301
|
-
const errorResult = {
|
|
3302
|
-
packageInput: pkgInput,
|
|
3303
|
-
packageName: originalPackageName,
|
|
3304
|
-
status: 'error',
|
|
3305
|
-
error: `Failed to search for alternatives: ${searchResponse.status} ${searchResponse.statusText}`,
|
|
3306
|
-
data: null,
|
|
3307
|
-
message: 'Could not perform search for alternatives.',
|
|
3308
|
-
};
|
|
3309
|
-
return errorResult; // Do not cache API errors for search
|
|
3310
|
-
}
|
|
3311
|
-
const searchData = (await searchResponse.json());
|
|
3312
|
-
const alternativePackagesRaw = searchData.objects || [];
|
|
3477
|
+
let originalPackageKeywords = [];
|
|
3313
3478
|
let originalPackageDownloads = 0;
|
|
3479
|
+
try {
|
|
3480
|
+
const pkgManifestResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/${encodeURIComponent(originalPackageName)}/latest`);
|
|
3481
|
+
if (pkgManifestResponse.ok) {
|
|
3482
|
+
const pkgManifest = (await pkgManifestResponse.json());
|
|
3483
|
+
if (Array.isArray(pkgManifest.keywords)) {
|
|
3484
|
+
originalPackageKeywords = pkgManifest.keywords;
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
catch {
|
|
3489
|
+
// Optional manifest retrieval failure
|
|
3490
|
+
}
|
|
3314
3491
|
try {
|
|
3315
3492
|
const dlResponse = await fetchWithRetry(`https://api.npmjs.org/downloads/point/last-month/${originalPackageName}`);
|
|
3316
3493
|
if (dlResponse.ok) {
|
|
@@ -3321,31 +3498,112 @@ export async function handleNpmAlternatives(args) {
|
|
|
3321
3498
|
catch (e) {
|
|
3322
3499
|
console.debug(`Failed to fetch downloads for original package ${originalPackageName}: ${e}`);
|
|
3323
3500
|
}
|
|
3324
|
-
const originalPackageKeywords = alternativePackagesRaw.find((p) => p.package.name === originalPackageName)?.package
|
|
3325
|
-
.keywords || [];
|
|
3326
3501
|
const originalPackageStats = {
|
|
3327
3502
|
name: originalPackageName,
|
|
3328
3503
|
monthlyDownloads: originalPackageDownloads,
|
|
3329
3504
|
keywords: originalPackageKeywords,
|
|
3330
3505
|
};
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3506
|
+
const KNOWN_ALTERNATIVES_MAP = {
|
|
3507
|
+
express: ['fastify', 'koa', 'hono', 'restify', 'nestjs'],
|
|
3508
|
+
lodash: ['ramda', 'remeda', 'radash', 'underscore'],
|
|
3509
|
+
moment: ['dayjs', 'date-fns', 'luxon'],
|
|
3510
|
+
request: ['axios', 'node-fetch', 'got', 'ky', 'superagent'],
|
|
3511
|
+
react: ['preact', 'vue', 'svelte', 'solid-js'],
|
|
3512
|
+
vue: ['react', 'svelte', 'solid-js', 'preact'],
|
|
3513
|
+
jest: ['vitest', 'mocha', 'ava'],
|
|
3514
|
+
axios: ['got', 'ky', 'node-fetch', 'superagent'],
|
|
3515
|
+
chalk: ['kleur', 'colorette', 'picocolors', 'ansis'],
|
|
3516
|
+
commander: ['yargs', 'cac', 'clipanion'],
|
|
3517
|
+
winston: ['pino', 'bunyan', 'loglevel'],
|
|
3518
|
+
mongoose: ['prisma', 'typeorm', 'drizzle-orm', 'sequelize'],
|
|
3519
|
+
webpack: ['vite', 'esbuild', 'rollup', 'parcel', 'turbopack'],
|
|
3520
|
+
};
|
|
3521
|
+
let validAlternativesRaw = [];
|
|
3522
|
+
const pkgLower = originalPackageName.toLowerCase();
|
|
3523
|
+
const knownCandidates = Object.hasOwn(KNOWN_ALTERNATIVES_MAP, pkgLower)
|
|
3524
|
+
? KNOWN_ALTERNATIVES_MAP[pkgLower]
|
|
3525
|
+
: undefined;
|
|
3526
|
+
if (Array.isArray(knownCandidates) && knownCandidates.length > 0) {
|
|
3527
|
+
try {
|
|
3528
|
+
const knownResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/-/v1/search?text=${encodeURIComponent(knownCandidates.join(' '))}&size=20`);
|
|
3529
|
+
if (knownResponse.ok) {
|
|
3530
|
+
const knownData = (await knownResponse.json());
|
|
3531
|
+
validAlternativesRaw = (knownData.objects || []).filter((alt) => knownCandidates.includes(alt.package.name.toLowerCase()) &&
|
|
3532
|
+
alt.package.name.toLowerCase() !== originalPackageName.toLowerCase());
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
catch {
|
|
3536
|
+
// Known candidate search failure fallback
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
if (validAlternativesRaw.length === 0) {
|
|
3540
|
+
const genericKeywords = originalPackageKeywords.filter((kw) => kw.toLowerCase() !== originalPackageName.toLowerCase() &&
|
|
3541
|
+
!kw.toLowerCase().includes(originalPackageName.toLowerCase()) &&
|
|
3542
|
+
kw.length > 2);
|
|
3543
|
+
const domainKeywords = genericKeywords.filter((kw) => ![
|
|
3544
|
+
'mobile',
|
|
3545
|
+
'ionic',
|
|
3546
|
+
'component',
|
|
3547
|
+
'components',
|
|
3548
|
+
'ui',
|
|
3549
|
+
'css',
|
|
3550
|
+
'react',
|
|
3551
|
+
'vue',
|
|
3552
|
+
'angular',
|
|
3553
|
+
'stencil',
|
|
3554
|
+
'storybook',
|
|
3555
|
+
'icon',
|
|
3556
|
+
'icons',
|
|
3557
|
+
].includes(kw.toLowerCase()));
|
|
3558
|
+
const selectedKeywords = domainKeywords.length > 0 ? domainKeywords : genericKeywords;
|
|
3559
|
+
let searchQuery = originalPackageName;
|
|
3560
|
+
if (selectedKeywords.length >= 2) {
|
|
3561
|
+
searchQuery = selectedKeywords.slice(0, 3).join(' ');
|
|
3562
|
+
}
|
|
3563
|
+
else if (selectedKeywords.length === 1) {
|
|
3564
|
+
searchQuery = selectedKeywords[0];
|
|
3565
|
+
}
|
|
3566
|
+
const searchResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/-/v1/search?text=${encodeURIComponent(searchQuery)}&size=30`);
|
|
3567
|
+
if (!searchResponse.ok) {
|
|
3568
|
+
const errorResult = {
|
|
3569
|
+
packageInput: pkgInput,
|
|
3570
|
+
packageName: originalPackageName,
|
|
3571
|
+
status: 'error',
|
|
3572
|
+
error: `Failed to search for alternatives: ${searchResponse.status} ${searchResponse.statusText}`,
|
|
3573
|
+
data: null,
|
|
3574
|
+
message: 'Could not perform search for alternatives.',
|
|
3575
|
+
};
|
|
3576
|
+
return errorResult;
|
|
3577
|
+
}
|
|
3578
|
+
const searchData = (await searchResponse.json());
|
|
3579
|
+
const alternativePackagesRaw = searchData.objects || [];
|
|
3580
|
+
validAlternativesRaw = alternativePackagesRaw.filter((alt) => isAlternativeCandidate(alt.package.name, alt.package.description || '', originalPackageName));
|
|
3581
|
+
if (validAlternativesRaw.length === 0 && searchQuery !== originalPackageName) {
|
|
3582
|
+
try {
|
|
3583
|
+
const fallbackResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/-/v1/search?text=${encodeURIComponent(originalPackageName)}&size=30`);
|
|
3584
|
+
if (fallbackResponse.ok) {
|
|
3585
|
+
const fallbackData = (await fallbackResponse.json());
|
|
3586
|
+
validAlternativesRaw = (fallbackData.objects || []).filter((alt) => isAlternativeCandidate(alt.package.name, alt.package.description || '', originalPackageName));
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
catch {
|
|
3590
|
+
// Fallback failure
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
if (validAlternativesRaw.length === 0) {
|
|
3334
3595
|
const resultNoAlternatives = {
|
|
3335
3596
|
packageInput: pkgInput,
|
|
3336
3597
|
packageName: originalPackageName,
|
|
3337
3598
|
status: 'no_alternatives_found',
|
|
3338
3599
|
error: null,
|
|
3339
3600
|
data: { originalPackageStats, alternatives: [] },
|
|
3340
|
-
message: `No significant alternatives found for ${originalPackageName} based on
|
|
3601
|
+
message: `No significant alternatives found for ${originalPackageName} based on search.`,
|
|
3341
3602
|
};
|
|
3342
3603
|
cacheSet(cacheKey, resultNoAlternatives, CACHE_TTL_MEDIUM);
|
|
3343
3604
|
return resultNoAlternatives;
|
|
3344
3605
|
}
|
|
3345
|
-
const alternativesData = await Promise.all(
|
|
3346
|
-
.filter((alt) => alt.package.name !== originalPackageName)
|
|
3347
|
-
.slice(0, 5)
|
|
3348
|
-
.map(async (alt) => {
|
|
3606
|
+
const alternativesData = await Promise.all(validAlternativesRaw.slice(0, 5).map(async (alt) => {
|
|
3349
3607
|
let altDownloads = 0;
|
|
3350
3608
|
try {
|
|
3351
3609
|
const altDlResponse = await fetchWithRetry(`https://api.npmjs.org/downloads/point/last-month/${alt.package.name}`);
|
|
@@ -3411,430 +3669,8 @@ export async function handleNpmAlternatives(args) {
|
|
|
3411
3669
|
};
|
|
3412
3670
|
}
|
|
3413
3671
|
}
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
export const configSchema = z.object({
|
|
3417
|
-
NPM_REGISTRY_URL: z.string().optional().describe('URL of the NPM registry to use'),
|
|
3418
|
-
});
|
|
3419
|
-
// Create server function for Smithery CLI
|
|
3420
|
-
export default function createServer({ config }) {
|
|
3421
|
-
// Apply config overrides
|
|
3422
|
-
if (config.NPM_REGISTRY_URL) {
|
|
3423
|
-
NPM_REGISTRY_URL = config.NPM_REGISTRY_URL.replace(/\/$/, '');
|
|
3424
|
-
}
|
|
3425
|
-
// Handle both ESM and CJS environments
|
|
3426
|
-
let __filename;
|
|
3427
|
-
let __dirname;
|
|
3428
|
-
try {
|
|
3429
|
-
__filename = fileURLToPath(import.meta.url);
|
|
3430
|
-
__dirname = path.dirname(__filename);
|
|
3431
|
-
}
|
|
3432
|
-
catch {
|
|
3433
|
-
// Fallback for CJS environment (Smithery HTTP build)
|
|
3434
|
-
__filename = process.argv[1] || '.';
|
|
3435
|
-
__dirname = path.dirname(__filename);
|
|
3436
|
-
}
|
|
3437
|
-
// Determine package root
|
|
3438
|
-
let packageRoot = __dirname;
|
|
3439
|
-
if (fs.existsSync(path.join(__dirname, 'package.json'))) {
|
|
3440
|
-
packageRoot = __dirname;
|
|
3441
|
-
}
|
|
3442
|
-
else if (fs.existsSync(path.join(__dirname, '..', 'package.json'))) {
|
|
3443
|
-
packageRoot = path.join(__dirname, '..');
|
|
3444
|
-
}
|
|
3445
|
-
// Read version from package.json
|
|
3446
|
-
let serverVersion = '1.0.0';
|
|
3447
|
-
try {
|
|
3448
|
-
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
3449
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
3450
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
3451
|
-
serverVersion = packageJson.version;
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
catch (error) {
|
|
3455
|
-
console.error('Error reading package.json version:', error);
|
|
3456
|
-
}
|
|
3457
|
-
// Create server instance
|
|
3458
|
-
const server = new McpServer({
|
|
3459
|
-
name: 'npm-sentinel-mcp',
|
|
3460
|
-
version: serverVersion,
|
|
3461
|
-
});
|
|
3462
|
-
// Update paths to be relative to the package
|
|
3463
|
-
const README_PATH = path.join(packageRoot, 'README.md');
|
|
3464
|
-
const LLMS_FULL_TEXT_PATH = path.join(packageRoot, 'llms-full.txt');
|
|
3465
|
-
// Register README.md resource
|
|
3466
|
-
server.registerResource('serverReadme', 'doc://server/readme', {
|
|
3467
|
-
description: 'Main documentation and usage guide for this NPM Info Server.',
|
|
3468
|
-
mimeType: 'text/markdown',
|
|
3469
|
-
}, async (uri) => {
|
|
3470
|
-
try {
|
|
3471
|
-
const readmeContent = fs.readFileSync(README_PATH, 'utf-8');
|
|
3472
|
-
return {
|
|
3473
|
-
contents: [
|
|
3474
|
-
{
|
|
3475
|
-
uri: uri.href,
|
|
3476
|
-
text: readmeContent,
|
|
3477
|
-
mimeType: 'text/markdown',
|
|
3478
|
-
},
|
|
3479
|
-
],
|
|
3480
|
-
};
|
|
3481
|
-
}
|
|
3482
|
-
catch (error) {
|
|
3483
|
-
console.error(`Error reading README.md for resource ${uri.href}:`, error.message);
|
|
3484
|
-
throw {
|
|
3485
|
-
code: -32002,
|
|
3486
|
-
message: `Resource not found or unreadable: ${uri.href}`,
|
|
3487
|
-
data: { uri: uri.href, cause: error.message },
|
|
3488
|
-
};
|
|
3489
|
-
}
|
|
3490
|
-
});
|
|
3491
|
-
// Register llms-full.txt resource (MCP Specification)
|
|
3492
|
-
server.registerResource('mcpSpecification', 'doc://mcp/specification', {
|
|
3493
|
-
description: 'The llms-full.txt content providing a comprehensive overview of the Model Context Protocol.',
|
|
3494
|
-
mimeType: 'text/plain',
|
|
3495
|
-
}, async (uri) => {
|
|
3496
|
-
try {
|
|
3497
|
-
const specContent = fs.readFileSync(LLMS_FULL_TEXT_PATH, 'utf-8');
|
|
3498
|
-
return {
|
|
3499
|
-
contents: [
|
|
3500
|
-
{
|
|
3501
|
-
uri: uri.href,
|
|
3502
|
-
text: specContent,
|
|
3503
|
-
mimeType: 'text/plain',
|
|
3504
|
-
},
|
|
3505
|
-
],
|
|
3506
|
-
};
|
|
3507
|
-
}
|
|
3508
|
-
catch (error) {
|
|
3509
|
-
console.error(`Error reading llms-full.txt for resource ${uri.href}:`, error.message);
|
|
3510
|
-
throw {
|
|
3511
|
-
code: -32002,
|
|
3512
|
-
message: `Resource not found or unreadable: ${uri.href}`,
|
|
3513
|
-
data: { uri: uri.href, cause: error.message },
|
|
3514
|
-
};
|
|
3515
|
-
}
|
|
3516
|
-
});
|
|
3517
|
-
// Register prompts
|
|
3518
|
-
server.registerPrompt('analyze-package', {
|
|
3519
|
-
description: 'Analyze an NPM package for security and quality',
|
|
3520
|
-
argsSchema: {
|
|
3521
|
-
package: z.string().describe('Name of the npm package to analyze'),
|
|
3522
|
-
},
|
|
3523
|
-
}, ({ package: pkgName }) => ({
|
|
3524
|
-
messages: [
|
|
3525
|
-
{
|
|
3526
|
-
role: 'user',
|
|
3527
|
-
content: {
|
|
3528
|
-
type: 'text',
|
|
3529
|
-
text: `Please analyze the npm package "${pkgName}". Check for vulnerabilities, maintenance status, and recent issues. Use the available tools to gather information.`,
|
|
3530
|
-
},
|
|
3531
|
-
},
|
|
3532
|
-
],
|
|
3533
|
-
}));
|
|
3534
|
-
// Add NPM tools - Ensuring each tool registration is complete and correct
|
|
3535
|
-
server.registerTool('npmVersions', {
|
|
3536
|
-
description: 'Get all available versions of an NPM package',
|
|
3537
|
-
inputSchema: {
|
|
3538
|
-
packages: z.array(z.string()).describe('List of package names to get versions for'),
|
|
3539
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3540
|
-
},
|
|
3541
|
-
annotations: {
|
|
3542
|
-
title: 'Get All Package Versions',
|
|
3543
|
-
readOnlyHint: true,
|
|
3544
|
-
openWorldHint: true,
|
|
3545
|
-
idempotentHint: true,
|
|
3546
|
-
},
|
|
3547
|
-
}, async (args) => {
|
|
3548
|
-
return await handleNpmVersions(args);
|
|
3549
|
-
});
|
|
3550
|
-
server.registerTool('npmLatest', {
|
|
3551
|
-
description: 'Get the latest version and changelog of an NPM package',
|
|
3552
|
-
inputSchema: {
|
|
3553
|
-
packages: z.array(z.string()).describe('List of package names to get latest versions for'),
|
|
3554
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3555
|
-
},
|
|
3556
|
-
annotations: {
|
|
3557
|
-
title: 'Get Latest Package Information',
|
|
3558
|
-
readOnlyHint: true,
|
|
3559
|
-
openWorldHint: true,
|
|
3560
|
-
idempotentHint: true, // Result for 'latest' tag can change, but call itself is idempotent
|
|
3561
|
-
},
|
|
3562
|
-
}, async (args) => {
|
|
3563
|
-
return await handleNpmLatest(args);
|
|
3564
|
-
});
|
|
3565
|
-
server.registerTool('npmDeps', {
|
|
3566
|
-
description: 'Analyze dependencies and devDependencies of an NPM package',
|
|
3567
|
-
inputSchema: {
|
|
3568
|
-
packages: z.array(z.string()).describe('List of package names to analyze dependencies for'),
|
|
3569
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3570
|
-
},
|
|
3571
|
-
annotations: {
|
|
3572
|
-
title: 'Get Package Dependencies',
|
|
3573
|
-
readOnlyHint: true,
|
|
3574
|
-
openWorldHint: true,
|
|
3575
|
-
idempotentHint: true,
|
|
3576
|
-
},
|
|
3577
|
-
}, async (args) => {
|
|
3578
|
-
return await handleNpmDeps(args);
|
|
3579
|
-
});
|
|
3580
|
-
server.registerTool('npmTypes', {
|
|
3581
|
-
description: 'Check TypeScript types availability and version for a package',
|
|
3582
|
-
inputSchema: {
|
|
3583
|
-
packages: z.array(z.string()).describe('List of package names to check types for'),
|
|
3584
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3585
|
-
},
|
|
3586
|
-
annotations: {
|
|
3587
|
-
title: 'Check TypeScript Type Availability',
|
|
3588
|
-
readOnlyHint: true,
|
|
3589
|
-
openWorldHint: true,
|
|
3590
|
-
idempotentHint: true,
|
|
3591
|
-
},
|
|
3592
|
-
}, async (args) => {
|
|
3593
|
-
return await handleNpmTypes(args);
|
|
3594
|
-
});
|
|
3595
|
-
server.registerTool('npmSize', {
|
|
3596
|
-
description: 'Get package size information including dependencies and bundle size',
|
|
3597
|
-
inputSchema: {
|
|
3598
|
-
packages: z.array(z.string()).describe('List of package names to get size information for'),
|
|
3599
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3600
|
-
},
|
|
3601
|
-
annotations: {
|
|
3602
|
-
title: 'Get Package Size (Bundlephobia)',
|
|
3603
|
-
readOnlyHint: true,
|
|
3604
|
-
openWorldHint: true,
|
|
3605
|
-
idempotentHint: true,
|
|
3606
|
-
},
|
|
3607
|
-
}, async (args) => {
|
|
3608
|
-
return await handleNpmSize(args);
|
|
3609
|
-
});
|
|
3610
|
-
server.registerTool('npmVulnerabilities', {
|
|
3611
|
-
description: 'Check for known vulnerabilities in packages',
|
|
3612
|
-
inputSchema: {
|
|
3613
|
-
packages: z
|
|
3614
|
-
.array(z.string())
|
|
3615
|
-
.describe('List of package names to check for vulnerabilities'),
|
|
3616
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3617
|
-
},
|
|
3618
|
-
annotations: {
|
|
3619
|
-
title: 'Check Package Vulnerabilities (OSV.dev)',
|
|
3620
|
-
readOnlyHint: true,
|
|
3621
|
-
openWorldHint: true,
|
|
3622
|
-
idempotentHint: false, // Vulnerability data can change frequently
|
|
3623
|
-
},
|
|
3624
|
-
}, async (args) => {
|
|
3625
|
-
return await handleNpmVulnerabilities(args);
|
|
3626
|
-
});
|
|
3627
|
-
server.registerTool('npmTrends', {
|
|
3628
|
-
description: 'Get download trends and popularity metrics for packages',
|
|
3629
|
-
inputSchema: {
|
|
3630
|
-
packages: z.array(z.string()).describe('List of package names to get trends for'),
|
|
3631
|
-
period: z
|
|
3632
|
-
.enum(['last-week', 'last-month', 'last-year'])
|
|
3633
|
-
.describe('Time period for trends. Options: "last-week", "last-month", "last-year"')
|
|
3634
|
-
.optional()
|
|
3635
|
-
.default('last-month'),
|
|
3636
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3637
|
-
},
|
|
3638
|
-
annotations: {
|
|
3639
|
-
title: 'Get NPM Package Download Trends',
|
|
3640
|
-
readOnlyHint: true,
|
|
3641
|
-
openWorldHint: true,
|
|
3642
|
-
idempotentHint: true, // Trends for a fixed past period are idempotent
|
|
3643
|
-
},
|
|
3644
|
-
}, async (args) => {
|
|
3645
|
-
return await handleNpmTrends(args);
|
|
3646
|
-
});
|
|
3647
|
-
server.registerTool('npmCompare', {
|
|
3648
|
-
description: 'Compare multiple NPM packages based on various metrics',
|
|
3649
|
-
inputSchema: {
|
|
3650
|
-
packages: z.array(z.string()).describe('List of package names to compare'),
|
|
3651
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3652
|
-
},
|
|
3653
|
-
annotations: {
|
|
3654
|
-
title: 'Compare NPM Packages',
|
|
3655
|
-
readOnlyHint: true,
|
|
3656
|
-
openWorldHint: true,
|
|
3657
|
-
idempotentHint: true,
|
|
3658
|
-
},
|
|
3659
|
-
}, async (args) => {
|
|
3660
|
-
return await handleNpmCompare(args);
|
|
3661
|
-
});
|
|
3662
|
-
server.registerTool('npmMaintainers', {
|
|
3663
|
-
description: 'Get maintainers information for NPM packages',
|
|
3664
|
-
inputSchema: {
|
|
3665
|
-
packages: z.array(z.string()).describe('List of package names to get maintainers for'),
|
|
3666
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3667
|
-
},
|
|
3668
|
-
annotations: {
|
|
3669
|
-
title: 'Get NPM Package Maintainers',
|
|
3670
|
-
readOnlyHint: true,
|
|
3671
|
-
openWorldHint: true,
|
|
3672
|
-
idempotentHint: true,
|
|
3673
|
-
},
|
|
3674
|
-
}, async (args) => {
|
|
3675
|
-
return await handleNpmMaintainers(args);
|
|
3676
|
-
});
|
|
3677
|
-
server.registerTool('npmScore', {
|
|
3678
|
-
description: 'Get consolidated package score based on quality, maintenance, and popularity metrics',
|
|
3679
|
-
inputSchema: {
|
|
3680
|
-
packages: z.array(z.string()).describe('List of package names to get scores for'),
|
|
3681
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3682
|
-
},
|
|
3683
|
-
annotations: {
|
|
3684
|
-
title: 'Get NPM Package Score (NPMS.io)',
|
|
3685
|
-
readOnlyHint: true,
|
|
3686
|
-
openWorldHint: true,
|
|
3687
|
-
idempotentHint: true, // Score for a version is stable, for 'latest' can change
|
|
3688
|
-
},
|
|
3689
|
-
}, async (args) => {
|
|
3690
|
-
return await handleNpmScore(args);
|
|
3691
|
-
});
|
|
3692
|
-
server.registerTool('npmPackageReadme', {
|
|
3693
|
-
description: 'Get the README content for NPM packages',
|
|
3694
|
-
inputSchema: {
|
|
3695
|
-
packages: z.array(z.string()).describe('List of package names to get READMEs for'),
|
|
3696
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3697
|
-
},
|
|
3698
|
-
annotations: {
|
|
3699
|
-
title: 'Get NPM Package README',
|
|
3700
|
-
readOnlyHint: true,
|
|
3701
|
-
openWorldHint: true,
|
|
3702
|
-
idempotentHint: true,
|
|
3703
|
-
},
|
|
3704
|
-
}, async (args) => {
|
|
3705
|
-
return await handleNpmPackageReadme(args);
|
|
3706
|
-
});
|
|
3707
|
-
server.registerTool('npmSearch', {
|
|
3708
|
-
description: 'Search for NPM packages with optional limit',
|
|
3709
|
-
inputSchema: {
|
|
3710
|
-
query: z.string().describe('Search query for packages'),
|
|
3711
|
-
limit: z
|
|
3712
|
-
.number()
|
|
3713
|
-
.min(1)
|
|
3714
|
-
.max(50)
|
|
3715
|
-
.optional()
|
|
3716
|
-
.describe('Maximum number of results to return (default: 10)'),
|
|
3717
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3718
|
-
},
|
|
3719
|
-
annotations: {
|
|
3720
|
-
title: 'Search NPM Packages',
|
|
3721
|
-
readOnlyHint: true,
|
|
3722
|
-
openWorldHint: true,
|
|
3723
|
-
idempotentHint: false, // Search results can change
|
|
3724
|
-
},
|
|
3725
|
-
}, async (args) => {
|
|
3726
|
-
return await handleNpmSearch(args);
|
|
3727
|
-
});
|
|
3728
|
-
server.registerTool('npmLicenseCompatibility', {
|
|
3729
|
-
description: 'Check license compatibility between multiple packages',
|
|
3730
|
-
inputSchema: {
|
|
3731
|
-
packages: z
|
|
3732
|
-
.array(z.string())
|
|
3733
|
-
.min(1)
|
|
3734
|
-
.describe('List of package names to check for license compatibility'),
|
|
3735
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3736
|
-
},
|
|
3737
|
-
annotations: {
|
|
3738
|
-
title: 'Check NPM License Compatibility',
|
|
3739
|
-
readOnlyHint: true,
|
|
3740
|
-
openWorldHint: true,
|
|
3741
|
-
idempotentHint: true,
|
|
3742
|
-
},
|
|
3743
|
-
}, async (args) => {
|
|
3744
|
-
return await handleNpmLicenseCompatibility(args);
|
|
3745
|
-
});
|
|
3746
|
-
server.registerTool('npmRepoStats', {
|
|
3747
|
-
description: 'Get repository statistics for NPM packages',
|
|
3748
|
-
inputSchema: {
|
|
3749
|
-
packages: z.array(z.string()).describe('List of package names to get repository stats for'),
|
|
3750
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3751
|
-
},
|
|
3752
|
-
annotations: {
|
|
3753
|
-
title: 'Get NPM Package Repository Stats (GitHub)',
|
|
3754
|
-
readOnlyHint: true,
|
|
3755
|
-
openWorldHint: true,
|
|
3756
|
-
idempotentHint: true, // Stats for a repo at a point in time, though they change over time
|
|
3757
|
-
},
|
|
3758
|
-
}, async (args) => {
|
|
3759
|
-
return await handleNpmRepoStats(args);
|
|
3760
|
-
});
|
|
3761
|
-
server.registerTool('npmDeprecated', {
|
|
3762
|
-
description: 'Check if packages are deprecated',
|
|
3763
|
-
inputSchema: {
|
|
3764
|
-
packages: z.array(z.string()).describe('List of package names to check for deprecation'),
|
|
3765
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3766
|
-
},
|
|
3767
|
-
annotations: {
|
|
3768
|
-
title: 'Check NPM Package Deprecation Status',
|
|
3769
|
-
readOnlyHint: true,
|
|
3770
|
-
openWorldHint: true,
|
|
3771
|
-
idempotentHint: true, // Deprecation status is generally stable for a version
|
|
3772
|
-
},
|
|
3773
|
-
}, async (args) => {
|
|
3774
|
-
return await handleNpmDeprecated(args);
|
|
3775
|
-
});
|
|
3776
|
-
server.registerTool('npmChangelogAnalysis', {
|
|
3777
|
-
description: 'Analyze changelog and release history of packages',
|
|
3778
|
-
inputSchema: {
|
|
3779
|
-
packages: z.array(z.string()).describe('List of package names to analyze changelogs for'),
|
|
3780
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3781
|
-
},
|
|
3782
|
-
annotations: {
|
|
3783
|
-
title: 'Analyze NPM Package Changelog (GitHub)',
|
|
3784
|
-
readOnlyHint: true,
|
|
3785
|
-
openWorldHint: true,
|
|
3786
|
-
idempotentHint: true,
|
|
3787
|
-
},
|
|
3788
|
-
}, async (args) => {
|
|
3789
|
-
return await handleNpmChangelogAnalysis(args);
|
|
3790
|
-
});
|
|
3791
|
-
server.registerTool('npmAlternatives', {
|
|
3792
|
-
description: 'Find alternative packages with similar functionality',
|
|
3793
|
-
inputSchema: {
|
|
3794
|
-
packages: z.array(z.string()).describe('List of package names to find alternatives for'),
|
|
3795
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3796
|
-
},
|
|
3797
|
-
annotations: {
|
|
3798
|
-
title: 'Find NPM Package Alternatives',
|
|
3799
|
-
readOnlyHint: true,
|
|
3800
|
-
openWorldHint: true,
|
|
3801
|
-
idempotentHint: false, // Search-based, results can change
|
|
3802
|
-
},
|
|
3803
|
-
}, async (args) => {
|
|
3804
|
-
return await handleNpmAlternatives(args);
|
|
3805
|
-
});
|
|
3806
|
-
server.registerTool('npmQuality', {
|
|
3807
|
-
description: 'Analyze package quality metrics',
|
|
3808
|
-
inputSchema: {
|
|
3809
|
-
packages: z.array(z.string()).describe('List of package names to analyze'),
|
|
3810
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3811
|
-
},
|
|
3812
|
-
annotations: {
|
|
3813
|
-
title: 'Analyze NPM Package Quality (NPMS.io)',
|
|
3814
|
-
readOnlyHint: true,
|
|
3815
|
-
openWorldHint: true,
|
|
3816
|
-
idempotentHint: true, // Score for a version is stable, for 'latest' can change
|
|
3817
|
-
},
|
|
3818
|
-
}, async (args) => {
|
|
3819
|
-
return await handleNpmQuality(args);
|
|
3820
|
-
});
|
|
3821
|
-
server.registerTool('npmMaintenance', {
|
|
3822
|
-
description: 'Analyze package maintenance metrics',
|
|
3823
|
-
inputSchema: {
|
|
3824
|
-
packages: z.array(z.string()).describe('List of package names to analyze'),
|
|
3825
|
-
ignoreCache: z.boolean().optional().describe('Force a fresh lookup, ignoring the cache'),
|
|
3826
|
-
},
|
|
3827
|
-
annotations: {
|
|
3828
|
-
title: 'Analyze NPM Package Maintenance (NPMS.io)',
|
|
3829
|
-
readOnlyHint: true,
|
|
3830
|
-
openWorldHint: true,
|
|
3831
|
-
idempotentHint: true, // Score for a version is stable, for 'latest' can change
|
|
3832
|
-
},
|
|
3833
|
-
}, async (args) => {
|
|
3834
|
-
return await handleNpmMaintenance(args);
|
|
3835
|
-
});
|
|
3836
|
-
return server.server;
|
|
3837
|
-
}
|
|
3672
|
+
export { createServer };
|
|
3673
|
+
export default createServer;
|
|
3838
3674
|
// STDIO compatibility for backward compatibility
|
|
3839
3675
|
async function main() {
|
|
3840
3676
|
// Create server with empty configuration
|
|
@@ -3875,8 +3711,10 @@ function isNpmPackageVersionData(data) {
|
|
|
3875
3711
|
}
|
|
3876
3712
|
}
|
|
3877
3713
|
// Run STDIO server when executed directly (for backward compatibility)
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3714
|
+
if (process.env.NODE_ENV !== 'test' && !process.env.VITEST) {
|
|
3715
|
+
main().catch((error) => {
|
|
3716
|
+
console.error('Server error:', error);
|
|
3717
|
+
process.exit(1);
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3882
3720
|
//# sourceMappingURL=index.js.map
|