@just-every/mcp-read-website-fast
Version:
Markdown Content Preprocessor - Fetch web pages, extract content, convert to clean Markdown
30 lines (29 loc) • 937 B
JavaScript
import { Agent } from 'undici';
export function createPinnedDnsAgent(resolution) {
return new Agent({
connect: {
lookup: createPinnedLookup(resolution),
},
});
}
export function createPinnedLookup(resolution) {
return (hostname, options, callback) => {
const normalizedHostname = normalizeLookupHostname(hostname);
if (normalizedHostname !== resolution.hostname) {
callback(new Error(`Unexpected hostname lookup: ${normalizedHostname}`), '');
return;
}
if (options.all) {
callback(null, resolution.addresses);
return;
}
const address = resolution.addresses[0];
callback(null, address.address, address.family);
};
}
function normalizeLookupHostname(hostname) {
if (hostname.startsWith('[') && hostname.endsWith(']')) {
return hostname.slice(1, -1);
}
return hostname;
}