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

Method fetchAndValidate

server/src/validator.ts:68–154  ·  view source on GitHub ↗
(
    normalizedDomain: string,
    agentUrl: string,
    normalizedAgentUrl: string,
    scope: NormalizedScope
  )

Source from the content-addressed store, hash-verified

66 }
67
68 private async fetchAndValidate(
69 normalizedDomain: string,
70 agentUrl: string,
71 normalizedAgentUrl: string,
72 scope: NormalizedScope
73 ): Promise<AuthorizationResult> {
74 const adagentsUrl = this.buildAdAgentsUrl(normalizedDomain);
75
76 try {
77 const fetched = await this.fetchAdAgentsJson(adagentsUrl);
78 if (!fetched.data) {
79 return {
80 authorized: false,
81 domain: normalizedDomain,
82 agent_url: agentUrl,
83 checked_at: new Date().toISOString(),
84 error: fetched.error || "Unknown error",
85 source: fetched.source,
86 };
87 }
88
89 const data = fetched.data;
90 if (!data.authorized_agents || !Array.isArray(data.authorized_agents)) {
91 return {
92 authorized: false,
93 domain: normalizedDomain,
94 agent_url: agentUrl,
95 checked_at: new Date().toISOString(),
96 error: "Invalid adagents.json format: missing authorized_agents array",
97 source: fetched.source,
98 };
99 }
100
101 const matchedAuthorization = data.authorized_agents.find((agent) =>
102 this.matchesAuthorization(
103 agent,
104 normalizedDomain,
105 normalizedAgentUrl,
106 scope,
107 data.properties || [],
108 data.placements || [],
109 data.placement_tags || {}
110 )
111 );
112
113 return {
114 authorized: !!matchedAuthorization,
115 domain: normalizedDomain,
116 agent_url: agentUrl,
117 checked_at: new Date().toISOString(),
118 source: fetched.source || adagentsUrl.toString(),
119 matched_authorization: matchedAuthorization
120 ? {
121 authorization_type: matchedAuthorization.authorization_type,
122 delegation_type: matchedAuthorization.delegation_type,
123 exclusive: matchedAuthorization.exclusive,
124 countries: matchedAuthorization.countries,
125 collection_ids: this.flattenCollectionIds(matchedAuthorization.collections, normalizedDomain),

Callers 1

validateMethod · 0.95

Calls 4

buildAdAgentsUrlMethod · 0.95
fetchAdAgentsJsonMethod · 0.95
matchesAuthorizationMethod · 0.95
flattenCollectionIdsMethod · 0.95

Tested by

no test coverage detected