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
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The .env file content to parse and import | |
| scope | No | Scope: global or project | global |
| projectPath | No | Project root path for project-scoped secrets | |
| skipExisting | No | Skip keys that already exist in q-ring | |
| dryRun | No | Preview what would be imported without saving |
Implementation Reference
- src/core/import.ts:69-114 (handler)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; } - src/mcp/server.ts:296-325 (registration)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)`, ];