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:66-76 (handler)Handler function for the 'getConfig' tool. Reads the configuration file using readConfigFile helper and optionally extracts a value at a dot-separated key path, returning the result as JSON string or error.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 parameters for getConfig: 'file' (required path string) and 'key' (optional dot-separated path string).{ file: z.string().describe("Path to the configuration file"), key: z.string().optional().describe("Optional dot-separated key path (e.g., 'database.host')"), },
- src/index.ts:59-77 (registration)MCP tool registration for 'getConfig', including name, description, input schema, and inline handler implementation.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/lib/files.ts:19-34 (helper)Helper function that reads and parses configuration files in supported formats (JSON, JSONC, YAML/YML, TOML) by detecting the file extension and using appropriate parsers.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); } }