Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK
project-info.ts3.27 kB
import fs from "fs"; import path from "path"; import { projectRoot } from "../config/server-config.js"; import { readJsonFile, getDirectoryContents } from "../utils/file-utils.js"; /** * Handle requests for project information * @param uri Resource URI * @returns Response with project information */ export async function handleProjectInfo(uri: string) { try { // Get default package info const defaultPackageInfo = { name: "Open Food Facts Server", version: "Unknown", description: "Open Food Facts is a food products database made by everyone, for everyone." }; // Try to read package.json if it exists const packageInfo = await readJsonFile('package.json', defaultPackageInfo); // Get project structure overview - list directories const dirs = fs.readdirSync(projectRoot, { withFileTypes: true }) .filter(dirent => dirent.isDirectory()) .map(dirent => dirent.name); const info = { name: packageInfo.name || defaultPackageInfo.name, version: packageInfo.version || defaultPackageInfo.version, description: packageInfo.description || defaultPackageInfo.description, mainDirectories: dirs, technologies: [ "Perl (core backend)", "JavaScript/TypeScript (frontend)", "HTML/CSS (UI)", "MongoDB (database)", "Docker (containerization)", "Foundation Framework (UI)" ] }; return { contents: [{ uri, text: JSON.stringify(info, null, 2), metadata: { contentType: "application/json" } }] }; } catch (error) { return { contents: [{ uri, text: `Error retrieving project info: ${error instanceof Error ? error.message : String(error)}`, isError: true }] }; } } /** * Handle requests for project structure * @param uri Resource URI * @returns Response with project structure information */ export async function handleProjectStructure(uri: string) { try { // Extract path from URI if provided (after "openfoodfacts://structure/") const structurePath = uri.replace("openfoodfacts://structure/", "").trim(); const dirPath = structurePath || "."; // Default to root if no path specified // Get directory contents with their types const contents = await getDirectoryContents(dirPath); // Build a hierarchical structure const structure = { path: dirPath, contents: contents.split("\n").map(line => { const match = line.match(/^(.+)\s\((.+)\)$/); if (!match) return { name: line, type: "unknown" }; const [, name, type] = match; return { name, type, uri: `openfoodfacts://structure/${dirPath === "." ? "" : dirPath + "/"}${name}` }; }) }; return { contents: [{ uri, text: JSON.stringify(structure, null, 2), metadata: { contentType: "application/json" } }] }; } catch (error) { return { contents: [{ uri, text: `Error retrieving project structure: ${error instanceof Error ? error.message : String(error)}`, isError: true }] }; } }

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/JagjeevanAK/OpenFoodFacts-MCP'

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