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

  • 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 };
      }
    }
  • 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 };
        }
      }
    );
  • 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);
      }
    }

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