Skip to main content
Glama
storage.ts1.14 kB
import { promises as fs } from "node:fs"; import path from "node:path"; import type { PersistedIndex } from "./types.js"; const INDEX_FILE = "index.json"; export async function writeIndex( persistDir: string, data: PersistedIndex, ): Promise<void> { await fs.mkdir(persistDir, { recursive: true }); const filePath = path.join(persistDir, INDEX_FILE); const payload = JSON.stringify(data, null, 2); await fs.writeFile(filePath, payload, "utf-8"); } export async function readIndex(persistDir: string): Promise<PersistedIndex> { const filePath = path.join(persistDir, INDEX_FILE); const buffer = await fs.readFile(filePath, "utf-8"); const parsed = JSON.parse(buffer) as PersistedIndex; if (!Array.isArray(parsed.documents) || !parsed.documents.length) { throw new Error(`index at ${filePath} is empty or malformed`); } return parsed; } export async function ensureEmptyDir(targetDir: string): Promise<void> { await fs.rm(targetDir, { recursive: true, force: true }); await fs.mkdir(targetDir, { recursive: true }); } export function indexFilePath(persistDir: string): string { return path.join(persistDir, INDEX_FILE); }

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/JaxsonWang/docs-mcp'

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