Skip to content

Commit fbf9a9c

Browse files
author
Lasim
committed
feat(backend): add optional namespace filtering for server data
1 parent 0810950 commit fbf9a9c

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

services/backend/src/services/registrySyncService.ts

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,36 @@ export class RegistrySyncService {
268268
}, 'Registry API metadata structure');
269269

270270
// Extract server data and filter for isLatest === true (CRITICAL: keep this filter!)
271+
// Optional: Filter out servers from specific namespaces (for testing/debugging)
272+
// Uncomment the EXCLUDED_NAMESPACES array below to enable namespace filtering
273+
274+
// const EXCLUDED_NAMESPACES = [
275+
// 'ai.smithery/',
276+
// // Add more namespaces to exclude:
277+
// // 'internal.example/',
278+
// // 'test.namespace/',
279+
// ];
280+
271281
const serverData = servers
272282
// eslint-disable-next-line @typescript-eslint/no-explicit-any
273283
.filter((item: any) => {
274284
const meta = item._meta?.['io.modelcontextprotocol.registry/official'];
275-
return meta?.isLatest === true; // KEEP THIS AT ALL COSTS
285+
// const server = item.server || item;
286+
// const serverName = server?.name || '';
287+
288+
// Filter conditions:
289+
// 1. Must be latest version
290+
const isLatest = meta?.isLatest === true;
291+
292+
// 2. Check if server is from an excluded namespace (if filtering enabled)
293+
// Uncomment the lines below to enable namespace filtering
294+
// const isExcluded = EXCLUDED_NAMESPACES.some(
295+
// prefix => serverName.startsWith(prefix)
296+
// );
297+
// return isLatest && !isExcluded;
298+
299+
// Default: Only filter by isLatest
300+
return isLatest;
276301
})
277302
// eslint-disable-next-line @typescript-eslint/no-explicit-any
278303
.map((item: any) => {
@@ -286,9 +311,9 @@ export class RegistrySyncService {
286311
this.logger.debug({
287312
pageNumber,
288313
rawBatchSize: servers.length,
289-
afterIsLatestFilter: serverData.length,
314+
afterFiltering: serverData.length,
290315
currentCursor: cursor,
291-
}, 'Fetched and filtered page from official registry');
316+
}, 'Fetched and filtered page from official registry (isLatest=true)');
292317

293318
// Filter this page against database (only check these 50 servers)
294319
const newServersInPage = await this.filterExistingServers(serverData);
@@ -387,11 +412,36 @@ export class RegistrySyncService {
387412
// Registry API returns: { servers: [{ _meta: {...}, server: {...} }] }
388413
// We need to attach _meta to the server object so it's available for metadata extraction
389414
// FILTER: Only include servers where _meta.io.modelcontextprotocol.registry/official.isLatest === true
415+
// Optional: Filter out servers from specific namespaces (for testing/debugging)
416+
// Uncomment the EXCLUDED_NAMESPACES array below to enable namespace filtering
417+
418+
// const EXCLUDED_NAMESPACES = [
419+
// 'ai.smithery/',
420+
// // Add more namespaces to exclude:
421+
// // 'internal.example/',
422+
// // 'test.namespace/',
423+
// ];
424+
390425
const serverData = servers
391426
// eslint-disable-next-line @typescript-eslint/no-explicit-any
392427
.filter((item: any) => {
393428
const meta = item._meta?.['io.modelcontextprotocol.registry/official'];
394-
return meta?.isLatest === true;
429+
// const server = item.server || item;
430+
// const serverName = server?.name || '';
431+
432+
// Filter conditions:
433+
// 1. Must be latest version
434+
const isLatest = meta?.isLatest === true;
435+
436+
// 2. Check if server is from an excluded namespace (if filtering enabled)
437+
// Uncomment the lines below to enable namespace filtering
438+
// const isExcluded = EXCLUDED_NAMESPACES.some(
439+
// prefix => serverName.startsWith(prefix)
440+
// );
441+
// return isLatest && !isExcluded;
442+
443+
// Default: Only filter by isLatest
444+
return isLatest;
395445
})
396446
// eslint-disable-next-line @typescript-eslint/no-explicit-any
397447
.map((item: any) => {

0 commit comments

Comments
 (0)