MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / populateFederatedIndex

Method populateFederatedIndex

server/src/crawler.ts:351–487  ·  view source on GitHub ↗

* Populate the federated index with discovered agents and publishers. * This is called after the PropertyCrawler finishes to persist data to PostgreSQL. * Returns the set of domains that were crawled (for brand scanning).

(agents: Agent[])

Source from the content-addressed store, hash-verified

349 * Returns the set of domains that were crawled (for brand scanning).
350 */
351 private async populateFederatedIndex(agents: Agent[]): Promise<Set<string>> {
352 log.debug('Populating federated index');
353 const index = getPropertyIndex();
354
355 // Track domains we've already processed to avoid duplicates
356 const processedDomains = new Set<string>();
357
358 // 1. Crawl registered publishers' adagents.json files
359 const profiles = await this.memberDb.listProfiles({ is_public: true });
360 const registeredPublisherDomains: string[] = [];
361 for (const profile of profiles) {
362 for (const pubConfig of profile.publishers || []) {
363 if (pubConfig.is_public && pubConfig.domain) {
364 registeredPublisherDomains.push(pubConfig.domain);
365 }
366 }
367 }
368 log.debug({ count: registeredPublisherDomains.length }, 'Crawling registered publishers');
369
370 for (const profile of profiles) {
371 for (const pubConfig of profile.publishers || []) {
372 if (!pubConfig.is_public || !pubConfig.domain) continue;
373 if (processedDomains.has(pubConfig.domain)) continue;
374
375 try {
376 const validation = await this.adAgentsManager.validateDomain(pubConfig.domain);
377 processedDomains.add(pubConfig.domain);
378
379 if (validation.valid && validation.raw_data?.authorized_agents) {
380 const agentCount = validation.raw_data.authorized_agents.length;
381 const propCount = validation.raw_data.properties?.length || 0;
382 log.debug({ domain: pubConfig.domain, agentCount, propCount }, 'Domain crawled');
383
384 await this.cacheAdagentsManifest(pubConfig.domain, validation.raw_data as AdagentsManifest);
385
386 // Record agents
387 for (const authorizedAgent of validation.raw_data.authorized_agents) {
388 if (!authorizedAgent.url) continue;
389
390 await this.federatedIndex.recordAgentFromAdagentsJson(
391 authorizedAgent.url,
392 pubConfig.domain,
393 authorizedAgent.authorized_for,
394 authorizedAgent.property_ids
395 );
396
397 // Record properties and link to this agent
398 await this.recordPropertiesForAgent(
399 validation.raw_data.properties || [],
400 pubConfig.domain,
401 authorizedAgent.url,
402 authorizedAgent.authorized_for,
403 authorizedAgent.property_ids
404 );
405 }
406 } else {
407 log.debug({ domain: pubConfig.domain }, 'No valid adagents.json');
408 }

Callers 1

crawlAllAgentsMethod · 0.95

Calls 12

cacheAdagentsManifestMethod · 0.95
refreshAgentSnapshotsMethod · 0.95
listProfilesMethod · 0.80
hasMethod · 0.80
addMethod · 0.80
warnMethod · 0.80
validateDomainMethod · 0.45
getStatsMethod · 0.45

Tested by

no test coverage detected