This is a small prose-only follow-up that rewrites clearly internal or explanatory Anthropic comment language to neutral wording in a handful of high-confidence files. It avoids runtime strings, flags, command labels, protocol identifiers, and provider-facing references. Constraint: Keep this pass narrowly scoped to comments/documentation only Rejected: Broader Anthropic comment sweep across functional API/protocol references | too ambiguous for a safe prose-only PR Confidence: high Scope-risk: narrow Reversibility: clean Directive: Leave functional Anthropic references (API behavior, SDKs, URLs, provider labels, protocol docs) for separate reviewed passes Tested: bun run build Tested: bun run smoke Tested: bun run verify:privacy Tested: bun run test:provider Tested: bun run test:provider-recommendation Not-tested: Full repo typecheck (upstream baseline remains noisy) Co-authored-by: anandh8x <test@example.com>
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import axios from 'axios'
|
|
import { logForDebugging } from '../../utils/debug.js'
|
|
import { errorMessage } from '../../utils/errors.js'
|
|
import { getAPIProvider } from '../../utils/model/providers.js'
|
|
|
|
type RegistryServer = {
|
|
server: {
|
|
remotes?: Array<{ url: string }>
|
|
}
|
|
}
|
|
|
|
type RegistryResponse = {
|
|
servers: RegistryServer[]
|
|
}
|
|
|
|
// URLs stripped of query string and trailing slash — matches the normalization
|
|
// done by getLoggingSafeMcpBaseUrl so direct Set.has() lookup works.
|
|
let officialUrls: Set<string> | undefined = undefined
|
|
|
|
function normalizeUrl(url: string): string | undefined {
|
|
try {
|
|
const u = new URL(url)
|
|
u.search = ''
|
|
return u.toString().replace(/\/$/, '')
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fire-and-forget fetch of the official MCP registry.
|
|
* Populates officialUrls for isOfficialMcpUrl lookups.
|
|
*/
|
|
export async function prefetchOfficialMcpUrls(): Promise<void> {
|
|
if (process.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC) {
|
|
return
|
|
}
|
|
|
|
// The official first-party MCP registry is only relevant for first-party mode.
|
|
if (getAPIProvider() !== 'firstParty') {
|
|
return
|
|
}
|
|
|
|
try {
|
|
const response = await axios.get<RegistryResponse>(
|
|
'https://api.anthropic.com/mcp-registry/v0/servers?version=latest&visibility=commercial',
|
|
{ timeout: 5000 },
|
|
)
|
|
|
|
const urls = new Set<string>()
|
|
for (const entry of response.data.servers) {
|
|
for (const remote of entry.server.remotes ?? []) {
|
|
const normalized = normalizeUrl(remote.url)
|
|
if (normalized) {
|
|
urls.add(normalized)
|
|
}
|
|
}
|
|
}
|
|
officialUrls = urls
|
|
logForDebugging(`[mcp-registry] Loaded ${urls.size} official MCP URLs`)
|
|
} catch (error) {
|
|
logForDebugging(`Failed to fetch MCP registry: ${errorMessage(error)}`, {
|
|
level: 'error',
|
|
})
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns true iff the given (already-normalized via getLoggingSafeMcpBaseUrl)
|
|
* URL is in the official MCP registry. Undefined registry → false (fail-closed).
|
|
*/
|
|
export function isOfficialMcpUrl(normalizedUrl: string): boolean {
|
|
return officialUrls?.has(normalizedUrl) ?? false
|
|
}
|
|
|
|
export function resetOfficialMcpUrlsForTesting(): void {
|
|
officialUrls = undefined
|
|
}
|