Skip to main content
Glama
get_resources.ts1.55 kB
import fs from "fs"; import { CrawledPage } from "@hyperbrowser/sdk/types"; import urlToDataMap from "./data/summarized.json"; import { ReadResourceRequest, ReadResourceResult, } from "@modelcontextprotocol/sdk/types.js"; type ResourceResponse = { uri: string; name: string; description: string; mimeType: "text/markdown"; }; const getPathname = (url: string) => { return new URL(url).pathname ?? "/"; }; export async function getResource( request: ReadResourceRequest ): Promise<ReadResourceResult> { 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 = urlToDataMap.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; } } export function listAllResources(): { resources: Array<ResourceResponse> } { return { resources: urlToDataMap.map((item) => ({ uri: `hyperbrowser://${item.pathname}`, name: (item.data.metadata?.title as string) ?? "", description: item.summary ?? "", mimeType: "text/markdown", })), }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BACH-AI-Tools/bach-hyperbrowser-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server