Skip to main content
Glama

Rules MCP Server

resources-provider.ts1.42 kB
import fs from "fs/promises"; import path from "path"; import { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js"; export class ResourcesProvider { private resourcesPath: string; constructor(resourcesPath: string) { this.resourcesPath = resourcesPath; } async readResource(uri: string): Promise<ReadResourceResult> { try { if (!uri.startsWith("file://")) { throw new Error("Invalid URI scheme"); } const filePath = uri.slice(7); const relativePath = path.relative(this.resourcesPath, filePath); if ( relativePath.startsWith("..") || path.isAbsolute(relativePath) ) { throw new Error( "Access denied: File is outside of resources directory" ); } const contents = await fs.readFile(filePath, "utf8"); return { contents: [ { uri, mimeType: filePath.endsWith(".md") ? "text/markdown" : "text/plain", text: contents } ] }; } catch (error) { console.error("Error reading resource:", error); throw error; } } }

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/markacianfrani/mcp-pattern-language'

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