Skip to main content
Glama
mednabouli

MCP Multi-Context Hook Generator

by mednabouli
swrHook.ts744 B
import fs from 'fs'; import path from 'path'; export function generateTypedSWRHookAuto(rootPath: string, apiPath: string, responseType: string) { const hooksDir = path.join(rootPath, 'hooks'); if (!fs.existsSync(hooksDir)) fs.mkdirSync(hooksDir); const hookName = 'use' + apiPath.split('/').pop()?.replace(/\W/g, '') + 's'; const code = ` import useSWR from "swr"; import type { ${responseType} } from "../types/${responseType}"; export function ${hookName}() { const { data,error } = useSWR<${responseType}>("${apiPath}", url=>fetch(url).then(r=>r.json())); return { data,error,isLoading:!error && !data }; } `; const filePath = path.join(hooksDir, `${hookName}.ts`); fs.writeFileSync(filePath, code); return filePath; }

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/mednabouli/MCPV2'

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