@mseep/hyperbrowser-mcp
Version:
Hyperbrowser Model Context Protocol Server
51 lines (50 loc) • 1.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listAllResources = exports.getResource = void 0;
const summarized_json_1 = __importDefault(require("./data/summarized.json"));
const getPathname = (url) => {
return new URL(url).pathname ?? "/";
};
async function getResource(request) {
try {
let uri = request.params.uri;
if (!uri.startsWith("hyperbrowser://")) {
throw new Error(`Invalid resource uri: ${uri}. All resources must begin with hyperbrowser://`);
}
let pathname = getPathname(uri);
const resource = summarized_json_1.default.find((item) => item.pathname === pathname);
if (!(resource && resource.data.markdown)) {
throw new Error(`Resource not found: ${uri}`);
}
else {
return {
contents: [
{
uri,
mimeType: "text/markdown",
text: resource.data.markdown,
},
],
};
}
}
catch (error) {
console.error("error", error);
throw error;
}
}
exports.getResource = getResource;
function listAllResources() {
return {
resources: summarized_json_1.default.map((item) => ({
uri: `hyperbrowser://${item.pathname}`,
name: item.data.metadata?.title ?? "",
description: item.summary ?? "",
mimeType: "text/markdown",
})),
};
}
exports.listAllResources = listAllResources;