@nekzus/mcp-server 1.20.0 → 1.21.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.
- package/README.md +23 -12
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +187 -42
- package/dist/index.js.map +1 -1
- package/llms-full.txt +11 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,19 @@ export declare function fetchWithRetry(url: string, options?: any, config?: {
|
|
|
5
5
|
maxRetries?: number;
|
|
6
6
|
skipThrottle?: boolean;
|
|
7
7
|
}): Promise<any>;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a requested version string requires resolution against the package manifest/packument.
|
|
10
|
+
* Returns false for known dist-tags and exact SemVer versions (e.g., '1.2.3').
|
|
11
|
+
* Returns true for version shorthands or ranges (e.g., '2', 'v4', '4.x', '^4', '~4.18').
|
|
12
|
+
*/
|
|
13
|
+
export declare function needsVersionResolution(version: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a requested version string (shorthand, tag, range, exact) against package manifest data.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolvePackageVersion(packageData: {
|
|
18
|
+
versions?: Record<string, any>;
|
|
19
|
+
'dist-tags'?: Record<string, string>;
|
|
20
|
+
} | null | undefined, requestedVersion: string): string | null;
|
|
8
21
|
export declare const NpmMaintainerSchema: z.ZodObject<{
|
|
9
22
|
name: z.ZodString;
|
|
10
23
|
email: z.ZodOptional<z.ZodString>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts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AC,OAAO,UAAU,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqhBxF"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { z } from 'zod';
|
|
|
10
10
|
// Cache configuration
|
|
11
11
|
let NPM_REGISTRY_URL = (process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org').replace(/\/$/, '');
|
|
12
12
|
// Cache configuration
|
|
13
|
+
const CACHE_TTL_SHORT = 5 * 60 * 1000; // 5 minutes
|
|
13
14
|
const CACHE_TTL_MEDIUM = 60 * 60 * 1000; // 1 hour
|
|
14
15
|
const CACHE_TTL_LONG = 6 * 60 * 60 * 1000; // 6 hours
|
|
15
16
|
const CACHE_TTL_VERY_LONG = 24 * 60 * 60 * 1000; // 24 hours
|
|
@@ -117,7 +118,7 @@ export async function fetchWithRetry(url, options = {}, config = {}) {
|
|
|
117
118
|
const retryAfter = response.headers.get('retry-after');
|
|
118
119
|
const waitMs = retryAfter
|
|
119
120
|
? parseInt(retryAfter, 10) * 1000
|
|
120
|
-
: HTTP_INITIAL_BACKOFF_MS *
|
|
121
|
+
: HTTP_INITIAL_BACKOFF_MS * 2 ** attempt;
|
|
121
122
|
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
122
123
|
continue;
|
|
123
124
|
}
|
|
@@ -126,7 +127,7 @@ export async function fetchWithRetry(url, options = {}, config = {}) {
|
|
|
126
127
|
}
|
|
127
128
|
catch (err) {
|
|
128
129
|
if (attempt < maxRetries) {
|
|
129
|
-
const waitMs = HTTP_INITIAL_BACKOFF_MS *
|
|
130
|
+
const waitMs = HTTP_INITIAL_BACKOFF_MS * 2 ** attempt;
|
|
130
131
|
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
131
132
|
continue;
|
|
132
133
|
}
|
|
@@ -142,6 +143,108 @@ export async function fetchWithRetry(url, options = {}, config = {}) {
|
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
}
|
|
146
|
+
const KNOWN_DIST_TAGS = new Set([
|
|
147
|
+
'latest',
|
|
148
|
+
'next',
|
|
149
|
+
'beta',
|
|
150
|
+
'rc',
|
|
151
|
+
'canary',
|
|
152
|
+
'alpha',
|
|
153
|
+
'dev',
|
|
154
|
+
'experimental',
|
|
155
|
+
'nightly',
|
|
156
|
+
'stable',
|
|
157
|
+
]);
|
|
158
|
+
const EXACT_SEMVER_REGEX = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
159
|
+
/**
|
|
160
|
+
* Checks if a requested version string requires resolution against the package manifest/packument.
|
|
161
|
+
* Returns false for known dist-tags and exact SemVer versions (e.g., '1.2.3').
|
|
162
|
+
* Returns true for version shorthands or ranges (e.g., '2', 'v4', '4.x', '^4', '~4.18').
|
|
163
|
+
*/
|
|
164
|
+
export function needsVersionResolution(version) {
|
|
165
|
+
if (!version)
|
|
166
|
+
return false;
|
|
167
|
+
const trimmed = version.trim();
|
|
168
|
+
if (KNOWN_DIST_TAGS.has(trimmed.toLowerCase()))
|
|
169
|
+
return false;
|
|
170
|
+
if (EXACT_SEMVER_REGEX.test(trimmed))
|
|
171
|
+
return false;
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Resolves a requested version string (shorthand, tag, range, exact) against package manifest data.
|
|
176
|
+
*/
|
|
177
|
+
export function resolvePackageVersion(packageData, requestedVersion) {
|
|
178
|
+
if (!packageData || !requestedVersion)
|
|
179
|
+
return null;
|
|
180
|
+
const versionsObj = packageData.versions || {};
|
|
181
|
+
const availableVersions = Object.keys(versionsObj);
|
|
182
|
+
if (availableVersions.length === 0)
|
|
183
|
+
return null;
|
|
184
|
+
const distTags = packageData['dist-tags'] || {};
|
|
185
|
+
// 1. Direct dist-tag match
|
|
186
|
+
if (Object.hasOwn(distTags, requestedVersion)) {
|
|
187
|
+
return distTags[requestedVersion];
|
|
188
|
+
}
|
|
189
|
+
// 2. Exact version match
|
|
190
|
+
if (Object.hasOwn(versionsObj, requestedVersion)) {
|
|
191
|
+
return requestedVersion;
|
|
192
|
+
}
|
|
193
|
+
// 3. Clean and match shorthands/ranges (e.g., '2', 'v2', '2.x', '^2', '~2.5')
|
|
194
|
+
const cleaned = requestedVersion
|
|
195
|
+
.replace(/^v/i, '')
|
|
196
|
+
.replace(/[.*]+x$/i, '')
|
|
197
|
+
.replace(/[\^~]/, '')
|
|
198
|
+
.trim();
|
|
199
|
+
if (cleaned) {
|
|
200
|
+
const matchingVersions = availableVersions.filter((v) => {
|
|
201
|
+
return v === cleaned || v.startsWith(`${cleaned}.`);
|
|
202
|
+
});
|
|
203
|
+
if (matchingVersions.length > 0) {
|
|
204
|
+
matchingVersions.sort((a, b) => {
|
|
205
|
+
const partsA = a.split('-')[0].split('.').map(Number);
|
|
206
|
+
const partsB = b.split('-')[0].split('.').map(Number);
|
|
207
|
+
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
|
|
208
|
+
const valA = partsA[i] || 0;
|
|
209
|
+
const valB = partsB[i] || 0;
|
|
210
|
+
if (valA !== valB)
|
|
211
|
+
return valA - valB;
|
|
212
|
+
}
|
|
213
|
+
return a.localeCompare(b);
|
|
214
|
+
});
|
|
215
|
+
return matchingVersions.pop() || null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// 4. Fallback to dist-tag latest or highest available version
|
|
219
|
+
return distTags.latest || availableVersions.sort().pop() || null;
|
|
220
|
+
}
|
|
221
|
+
async function resolveVersionIfShorthand(name, version) {
|
|
222
|
+
if (!needsVersionResolution(version)) {
|
|
223
|
+
return version;
|
|
224
|
+
}
|
|
225
|
+
const cacheKey = generateCacheKey('abbreviatedPackument', name);
|
|
226
|
+
let packument = cacheGet(cacheKey);
|
|
227
|
+
if (!packument) {
|
|
228
|
+
try {
|
|
229
|
+
const res = await fetchWithRetry(`${NPM_REGISTRY_URL}/${encodeURIComponent(name)}`, {
|
|
230
|
+
headers: { Accept: 'application/vnd.npm.install-v1+json' },
|
|
231
|
+
});
|
|
232
|
+
if (res.ok) {
|
|
233
|
+
packument = await res.json();
|
|
234
|
+
cacheSet(cacheKey, packument, CACHE_TTL_SHORT);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
// Ignore error and fall back to original version
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (packument) {
|
|
242
|
+
const resolved = resolvePackageVersion(packument, version);
|
|
243
|
+
if (resolved)
|
|
244
|
+
return resolved;
|
|
245
|
+
}
|
|
246
|
+
return version;
|
|
247
|
+
}
|
|
145
248
|
// Zod schemas for npm package data
|
|
146
249
|
export const NpmMaintainerSchema = z
|
|
147
250
|
.object({
|
|
@@ -525,7 +628,8 @@ export async function handleNpmLatest(args) {
|
|
|
525
628
|
};
|
|
526
629
|
}
|
|
527
630
|
try {
|
|
528
|
-
const
|
|
631
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, versionTag);
|
|
632
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
529
633
|
if (!response.ok) {
|
|
530
634
|
let errorMsg = `Failed to fetch package version: ${response.status} ${response.statusText}`;
|
|
531
635
|
if (response.status === 404) {
|
|
@@ -659,7 +763,8 @@ export async function handleNpmDeps(args) {
|
|
|
659
763
|
};
|
|
660
764
|
}
|
|
661
765
|
try {
|
|
662
|
-
const
|
|
766
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, version);
|
|
767
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
663
768
|
if (!response.ok) {
|
|
664
769
|
return {
|
|
665
770
|
package: packageNameForOutput,
|
|
@@ -785,7 +890,8 @@ export async function handleNpmTypes(args) {
|
|
|
785
890
|
};
|
|
786
891
|
}
|
|
787
892
|
try {
|
|
788
|
-
const
|
|
893
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, version);
|
|
894
|
+
const response = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
789
895
|
if (!response.ok) {
|
|
790
896
|
return {
|
|
791
897
|
package: packageNameForOutput,
|
|
@@ -1032,14 +1138,16 @@ export async function fetchRepoStatsFromDepsDev(owner, repo, ignoreCache = false
|
|
|
1032
1138
|
license: data.license ?? 'unknown',
|
|
1033
1139
|
description: data.description ?? '',
|
|
1034
1140
|
homepage: data.homepage ?? '',
|
|
1035
|
-
scorecard: data.scorecard
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1141
|
+
scorecard: data.scorecard
|
|
1142
|
+
? {
|
|
1143
|
+
overallScore: data.scorecard.overallScore,
|
|
1144
|
+
checks: (data.scorecard.checks || []).map((c) => ({
|
|
1145
|
+
name: c.name,
|
|
1146
|
+
score: c.score,
|
|
1147
|
+
reason: c.reason,
|
|
1148
|
+
})),
|
|
1149
|
+
}
|
|
1150
|
+
: undefined,
|
|
1043
1151
|
};
|
|
1044
1152
|
cacheSet(cacheKey, result, CACHE_TTL_VERY_LONG);
|
|
1045
1153
|
return result;
|
|
@@ -1210,7 +1318,7 @@ export async function handleNpmVulnerabilities(args) {
|
|
|
1210
1318
|
// Start fetching dependencies with deps.dev
|
|
1211
1319
|
await processPackage(name, version);
|
|
1212
1320
|
// Ecosystem Check: Scan associated packages that share the same version
|
|
1213
|
-
if (ECOSYSTEM_MAP[name]) {
|
|
1321
|
+
if (Object.hasOwn(ECOSYSTEM_MAP, name) && Array.isArray(ECOSYSTEM_MAP[name])) {
|
|
1214
1322
|
for (const associatedPkg of ECOSYSTEM_MAP[name]) {
|
|
1215
1323
|
await processPackage(associatedPkg, version);
|
|
1216
1324
|
}
|
|
@@ -1527,8 +1635,9 @@ export async function handleNpmCompare(args) {
|
|
|
1527
1635
|
};
|
|
1528
1636
|
}
|
|
1529
1637
|
try {
|
|
1638
|
+
const resolvedVersion = await resolveVersionIfShorthand(name, versionTag);
|
|
1530
1639
|
// Fetch package version details from registry
|
|
1531
|
-
const pkgResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${
|
|
1640
|
+
const pkgResponse = await fetchWithRetry(`${NPM_REGISTRY_URL}/${name}/${resolvedVersion}`);
|
|
1532
1641
|
if (!pkgResponse.ok) {
|
|
1533
1642
|
throw new Error(`Failed to fetch package info for ${name}@${versionTag}: ${pkgResponse.status} ${pkgResponse.statusText}`);
|
|
1534
1643
|
}
|
|
@@ -1699,19 +1808,20 @@ export async function getLocalPackageMetrics(name, ignoreCache = false) {
|
|
|
1699
1808
|
let popularity = popularityNPM;
|
|
1700
1809
|
if (github.hasGitHubData) {
|
|
1701
1810
|
const popularityGH = Math.min(1, github.starsCount / 50000);
|
|
1702
|
-
popularity =
|
|
1703
|
-
}
|
|
1704
|
-
const quality = (
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
: lastPublishDaysAgo < 365
|
|
1811
|
+
popularity = popularityNPM * 0.7 + popularityGH * 0.3;
|
|
1812
|
+
}
|
|
1813
|
+
const quality = (hasTypes ? 0.3 : 0) + (hasReadme ? 0.2 : 0) + Math.max(0, 0.5 - dependencyCount * 0.005);
|
|
1814
|
+
const maintenancePublish = lastPublishDaysAgo < 30
|
|
1815
|
+
? 1.0
|
|
1816
|
+
: lastPublishDaysAgo < 90
|
|
1817
|
+
? 0.8
|
|
1818
|
+
: lastPublishDaysAgo < 365
|
|
1819
|
+
? 0.5
|
|
1710
1820
|
: 0.2;
|
|
1711
1821
|
let maintenance = maintenancePublish;
|
|
1712
1822
|
if (github.hasGitHubData) {
|
|
1713
1823
|
const issuesScore = github.openIssuesCount < 50 ? 0.3 : github.openIssuesCount < 200 ? 0.2 : 0.1;
|
|
1714
|
-
maintenance =
|
|
1824
|
+
maintenance = maintenancePublish * 0.7 + issuesScore;
|
|
1715
1825
|
}
|
|
1716
1826
|
const finalScore = popularity * 0.4 + quality * 0.3 + maintenance * 0.3;
|
|
1717
1827
|
const result = {
|
|
@@ -2304,8 +2414,10 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2304
2414
|
data: null,
|
|
2305
2415
|
};
|
|
2306
2416
|
}
|
|
2307
|
-
const versionToUse = versionTag
|
|
2308
|
-
if (!versionToUse ||
|
|
2417
|
+
const versionToUse = resolvePackageVersion(packageInfo, versionTag) || versionTag;
|
|
2418
|
+
if (!versionToUse ||
|
|
2419
|
+
!packageInfo.versions ||
|
|
2420
|
+
!Object.hasOwn(packageInfo.versions, versionToUse)) {
|
|
2309
2421
|
return {
|
|
2310
2422
|
packageInput: pkgInput,
|
|
2311
2423
|
packageName: name,
|
|
@@ -2327,8 +2439,11 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2327
2439
|
}
|
|
2328
2440
|
}
|
|
2329
2441
|
const hasReadme = !!readmeContent;
|
|
2442
|
+
const demarcatedReadme = readmeContent
|
|
2443
|
+
? `<untrusted_external_content source="${readmeSource || 'registry'}" package="${name}" type="readme">\n${readmeContent}\n</untrusted_external_content>`
|
|
2444
|
+
: null;
|
|
2330
2445
|
const readmeResultData = {
|
|
2331
|
-
readme:
|
|
2446
|
+
readme: demarcatedReadme,
|
|
2332
2447
|
hasReadme: hasReadme,
|
|
2333
2448
|
readmeSource: readmeSource,
|
|
2334
2449
|
versionFetched: versionToUse, // Store the actually fetched version
|
|
@@ -2341,7 +2456,7 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2341
2456
|
versionFetched: versionToUse,
|
|
2342
2457
|
status: 'success',
|
|
2343
2458
|
error: null,
|
|
2344
|
-
data: { readme:
|
|
2459
|
+
data: { readme: demarcatedReadme, hasReadme: hasReadme, readmeSource: readmeSource }, // Return only readme and hasReadme in data field for consistency
|
|
2345
2460
|
message: `Successfully fetched README for ${name}@${versionToUse}.`,
|
|
2346
2461
|
};
|
|
2347
2462
|
}
|
|
@@ -2363,7 +2478,19 @@ export async function handleNpmPackageReadme(args) {
|
|
|
2363
2478
|
message: `README fetching status for ${args.packages.length} package(s).`,
|
|
2364
2479
|
};
|
|
2365
2480
|
const responseJson = JSON.stringify(finalResponse, null, 2);
|
|
2366
|
-
return {
|
|
2481
|
+
return {
|
|
2482
|
+
content: [
|
|
2483
|
+
{
|
|
2484
|
+
type: 'text',
|
|
2485
|
+
text: responseJson,
|
|
2486
|
+
_meta: {
|
|
2487
|
+
untrustedExternalContent: true,
|
|
2488
|
+
sources: ['npm-registry', 'cdn'],
|
|
2489
|
+
},
|
|
2490
|
+
},
|
|
2491
|
+
],
|
|
2492
|
+
isError: false,
|
|
2493
|
+
};
|
|
2367
2494
|
}
|
|
2368
2495
|
catch (error) {
|
|
2369
2496
|
const errorResponse = JSON.stringify({
|
|
@@ -2445,7 +2572,19 @@ export async function handleNpmSearch(args) {
|
|
|
2445
2572
|
};
|
|
2446
2573
|
cacheSet(cacheKey, finalResponse, CACHE_TTL_MEDIUM);
|
|
2447
2574
|
const responseJson = JSON.stringify(finalResponse, null, 2);
|
|
2448
|
-
return {
|
|
2575
|
+
return {
|
|
2576
|
+
content: [
|
|
2577
|
+
{
|
|
2578
|
+
type: 'text',
|
|
2579
|
+
text: responseJson,
|
|
2580
|
+
_meta: {
|
|
2581
|
+
untrustedExternalContent: true,
|
|
2582
|
+
sources: ['npm-registry', 'cdn'],
|
|
2583
|
+
},
|
|
2584
|
+
},
|
|
2585
|
+
],
|
|
2586
|
+
isError: false,
|
|
2587
|
+
};
|
|
2449
2588
|
}
|
|
2450
2589
|
catch (error) {
|
|
2451
2590
|
const errorResponse = JSON.stringify({
|
|
@@ -2890,16 +3029,7 @@ export async function handleNpmDeprecated(args) {
|
|
|
2890
3029
|
};
|
|
2891
3030
|
}
|
|
2892
3031
|
const mainPkgData = (await mainPkgResponse.json());
|
|
2893
|
-
|
|
2894
|
-
if (version === 'latest') {
|
|
2895
|
-
versionToFetch = mainPkgData['dist-tags']?.latest || 'latest';
|
|
2896
|
-
if (versionToFetch === 'latest' && !mainPkgData.versions?.[versionToFetch]) {
|
|
2897
|
-
const availableVersions = Object.keys(mainPkgData.versions || {});
|
|
2898
|
-
if (availableVersions.length > 0) {
|
|
2899
|
-
versionToFetch = availableVersions.sort().pop() || 'latest'; // Basic sort
|
|
2900
|
-
}
|
|
2901
|
-
}
|
|
2902
|
-
}
|
|
3032
|
+
const versionToFetch = resolvePackageVersion(mainPkgData, version) || version;
|
|
2903
3033
|
const finalPackageNameForOutput = `${name}@${versionToFetch}`;
|
|
2904
3034
|
const versionInfo = mainPkgData.versions?.[versionToFetch];
|
|
2905
3035
|
if (!versionInfo) {
|
|
@@ -3112,6 +3242,9 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3112
3242
|
return errorResult; // Do not cache this type of error
|
|
3113
3243
|
}
|
|
3114
3244
|
const npmData = await npmResponse.json();
|
|
3245
|
+
if (versionQueried) {
|
|
3246
|
+
versionQueried = resolvePackageVersion(npmData, versionQueried) || versionQueried;
|
|
3247
|
+
}
|
|
3115
3248
|
if (!isNpmPackageInfo(npmData)) {
|
|
3116
3249
|
const errorResult = {
|
|
3117
3250
|
packageInput: pkgInput,
|
|
@@ -3244,7 +3377,7 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3244
3377
|
repositoryUrl: repositoryUrl,
|
|
3245
3378
|
changelogSourceUrl: changelogSourceUrl,
|
|
3246
3379
|
changelogContent: changelogContent
|
|
3247
|
-
?
|
|
3380
|
+
? `<untrusted_external_content source="${changelogSourceUrl || 'github'}" package="${name}" type="changelog">\n${changelogContent.split('\n').slice(0, 50).join('\n')}...\n</untrusted_external_content>`
|
|
3248
3381
|
: null,
|
|
3249
3382
|
hasChangelogFile: hasChangelogFile,
|
|
3250
3383
|
githubReleases: githubReleases,
|
|
@@ -3273,7 +3406,19 @@ export async function handleNpmChangelogAnalysis(args) {
|
|
|
3273
3406
|
results: processedResults,
|
|
3274
3407
|
};
|
|
3275
3408
|
const responseJson = JSON.stringify(finalResponse, null, 2);
|
|
3276
|
-
return {
|
|
3409
|
+
return {
|
|
3410
|
+
content: [
|
|
3411
|
+
{
|
|
3412
|
+
type: 'text',
|
|
3413
|
+
text: responseJson,
|
|
3414
|
+
_meta: {
|
|
3415
|
+
untrustedExternalContent: true,
|
|
3416
|
+
sources: ['github-releases', 'github-raw', 'npm-registry'],
|
|
3417
|
+
},
|
|
3418
|
+
},
|
|
3419
|
+
],
|
|
3420
|
+
isError: false,
|
|
3421
|
+
};
|
|
3277
3422
|
}
|
|
3278
3423
|
catch (error) {
|
|
3279
3424
|
const errorResponse = JSON.stringify({
|