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
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path to the configuration file | |
| key | No | Optional 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 }; } } );
- src/index.ts:66-76 (handler)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 }; } }
- src/index.ts:62-65 (schema)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')"), },
- src/lib/files.ts:19-34 (helper)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); } }
- src/lib/files.ts:10-17 (helper)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"; }