Skip to main content
Glama

import_dotenv

Parse .env file content to import secrets into q-ring, supporting standard syntax, scoped storage, and preview options.

Instructions

Import secrets from .env file content. Parses standard dotenv syntax (comments, quotes, multiline escapes) and stores each key/value pair in q-ring.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe .env file content to parse and import
scopeNoScope: global or projectglobal
projectPathNoProject root path for project-scoped secrets
skipExistingNoSkip keys that already exist in q-ring
dryRunNoPreview what would be imported without saving

Implementation Reference

  • The actual implementation of the importDotenv logic, which parses content and saves secrets to the keyring.
    export function importDotenv(
      filePathOrContent: string,
      options: ImportOptions = {},
    ): ImportResult {
      let content: string;
    
      try {
        content = readFileSync(filePathOrContent, "utf8");
      } catch {
        content = filePathOrContent;
      }
    
      const pairs = parseDotenv(content);
      const result: ImportResult = {
        imported: [],
        skipped: [],
        total: pairs.size,
      };
    
      for (const [key, value] of pairs) {
        if (options.skipExisting && hasSecret(key, {
          scope: options.scope,
          projectPath: options.projectPath,
          source: options.source ?? "cli",
        })) {
          result.skipped.push(key);
          continue;
        }
    
        if (options.dryRun) {
          result.imported.push(key);
          continue;
        }
    
        const setOpts: SetSecretOptions = {
          scope: options.scope ?? "global",
          projectPath: options.projectPath ?? process.cwd(),
          source: options.source ?? "cli",
        };
    
        setSecret(key, value, setOpts);
        result.imported.push(key);
      }
    
      return result;
    }
  • The MCP tool registration and handler wrapper for import_dotenv.
    server.tool(
      "import_dotenv",
      "Import secrets from .env file content. Parses standard dotenv syntax (comments, quotes, multiline escapes) and stores each key/value pair in q-ring.",
      {
        content: z.string().describe("The .env file content to parse and import"),
        scope: scopeSchema.default("global"),
        projectPath: projectPathSchema,
        skipExisting: z
          .boolean()
          .optional()
          .default(false)
          .describe("Skip keys that already exist in q-ring"),
        dryRun: z
          .boolean()
          .optional()
          .default(false)
          .describe("Preview what would be imported without saving"),
      },
      async (params) => {
        const result = importDotenv(params.content, {
          scope: params.scope as "global" | "project",
          projectPath: params.projectPath ?? process.cwd(),
          source: "mcp",
          skipExisting: params.skipExisting,
          dryRun: params.dryRun,
        });
    
        const lines = [
          params.dryRun ? "Dry run — no changes made" : `Imported ${result.imported.length} secret(s)`,
        ];

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/I4cTime/quantum_ring'

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