Skip to main content
Glama

getConfig

Read configuration files in JSON, YAML, TOML, or JSONC format and extract specific settings using dot notation paths for workspace configuration management.

Instructions

Read a configuration file (JSON/JSONC/YAML/TOML) and optionally extract a specific key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the configuration file
keyNoOptional dot-separated key path (e.g., 'database.host')

Implementation Reference

  • src/index.ts:59-77 (registration)
    Registration of the getConfig tool with MCP server, including schema, description, and inline handler.
    mcp.tool( "getConfig", "Read a configuration file (JSON/JSONC/YAML/TOML) and optionally extract a specific key", { file: z.string().describe("Path to the configuration file"), key: z.string().optional().describe("Optional dot-separated key path (e.g., 'database.host')"), }, async ({ file, key }: { file: string; key?: string }) => { try { const data = await readConfigFile(file); const value = key ? key.split(".").reduce((o: any, k: string) => (o ? o[k] : undefined), data) : data; return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error reading config: ${error}` }], isError: true }; } } );
  • Executes the getConfig tool: reads config file using helper and extracts value at optional dot-path key.
    async ({ file, key }: { file: string; key?: string }) => { try { const data = await readConfigFile(file); const value = key ? key.split(".").reduce((o: any, k: string) => (o ? o[k] : undefined), data) : data; return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error reading config: ${error}` }], isError: true }; } }
  • Zod input schema defining 'file' path and optional 'key' for the getConfig tool.
    { file: z.string().describe("Path to the configuration file"), key: z.string().optional().describe("Optional dot-separated key path (e.g., 'database.host')"), },
  • Core helper for reading config files in multiple formats (JSON/JSONC/YAML/TOML), used by getConfig handler.
    export async function readConfigFile(file: string): Promise<any> { const fmt = detectFormat(file); const content = await fs.readFile(file, "utf8"); switch (fmt) { case "yaml": case "yml": return parseYaml(content); case "toml": return TOML.parse(content); case "jsonc": return parseCommentJson(content); case "json": default: return JSON.parse(content); } }
  • Detects config file format from extension, used by readConfigFile.
    function detectFormat(file: string): SupportedFormats { const ext = path.extname(file).toLowerCase().replace(/^\./, ""); if (ext === "yml") return "yml"; if (ext === "yaml") return "yaml"; if (ext === "toml") return "toml"; if (ext === "jsonc") return "jsonc"; return "json"; }

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/cloud-aspect/Config-MCP-Server'

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