Skip to main content
Glama

MCP Documentation Service

test-utils.ts2.06 kB
import fs from "fs/promises"; import path from "path"; import { afterEach, beforeEach } from "vitest"; /** * Creates a temporary test directory for document operations */ export async function createTestDocsDir(): Promise<string> { const testDir = path.join(process.cwd(), "tests", "temp-docs"); try { // Check if directory exists await fs.access(testDir); // If it exists, clean it up first await fs.rm(testDir, { recursive: true, force: true }); } catch (error) { // Directory doesn't exist, which is fine } // Create the directory await fs.mkdir(testDir, { recursive: true }); return testDir; } /** * Cleans up the temporary test directory */ export async function cleanupTestDocsDir(testDir: string): Promise<void> { try { // Use recursive deletion with force option await fs.rm(testDir, { recursive: true, force: true }); } catch (error) { console.error("Error cleaning up test directory:", error); } } /** * Creates a sample document in the test directory */ export async function createSampleDocument( testDir: string, relativePath: string, content: string ): Promise<string> { const fullPath = path.join(testDir, relativePath); const dirPath = path.dirname(fullPath); // Ensure the directory exists await fs.mkdir(dirPath, { recursive: true }); // Write the file await fs.writeFile(fullPath, content); return fullPath; } /** * Setup function for tests that need a temporary docs directory */ export function setupDocsDirTest() { let testDocsDir: string; beforeEach(async () => { testDocsDir = await createTestDocsDir(); }); afterEach(async () => { await cleanupTestDocsDir(testDocsDir); }); return () => testDocsDir; } /** * Creates a sample document with frontmatter */ export function createSampleMarkdownContent( title: string, description: string, content: string ): string { return `--- title: ${title} description: ${description} author: Test date: ${new Date().toISOString().split("T")[0]} --- # ${title} ${content} `; }

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

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