Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ miftah setup

On a bare interactive `miftah setup`, Miftah starts with `What do you already have? (connector, remote HTTPS, local executable, browser sign-in, import) [connector]`; choose `connector`, `remote`, `local`, `browser sign-in`, or `import` based on what you already have. At that prompt, enter `remote` for a remote HTTPS endpoint, `local` for a reviewed executable and argument array, or `connector` for a known connector or pinned package. It then collects only the safe metadata that path needs and an output location, and can print an optional client JSON snippet for manual review. Choose `browser sign-in` when the remote MCP opens a browser to authenticate you. Miftah asks for the configuration name, account profile, and exact HTTPS endpoint, then discovers whether it can safely own a supported standards-based OAuth flow. It writes nothing if the endpoint does not prove one supported authorization server with dynamic registration. Keep `miftah setup --native-oauth` for scripted or repeatable setup. The generic `remote` path does not discover authentication or call the endpoint; use it for no-auth or documented API-key/header setup. Choose `import` when you already have one MCP entry in a client JSON file: Miftah asks for that explicit absolute file, lists only entry names, and asks you to select one. It never prints the source entry's command, arguments, headers, environment values, or credentials, and it does not scan or modify the source client file. It never asks for a token, password, or browser cookie. For `local`, it collects one literal argument at a time, shows a no-secret review summary, and requires an explicit acknowledgement. Miftah does not run the local executable during setup. Miftah validates the complete configuration before it writes an owner-restricted file, never overwrites an existing one, and never edits a Claude, Cursor, VS Code, or other MCP client file. Recognized adapters can then offer one explicit, provider-declared read-only readiness check; Miftah never guesses a tool or auto-approves a policy prompt. Use `miftah init` when you want the same catalog in a scripted command.

If a selected client entry cannot be safely imported, Miftah writes no configuration from it. Miftah does not retain rejected arguments, headers, environment values, or credentials. The guided CLI keeps the non-secret configuration name and output location, then takes you to manual transport setup: re-enter a reviewed local executable with literal arguments, or a canonical HTTPS endpoint. In the Console, choose **Set up local executable manually** or **Set up remote HTTPS MCP manually**; it clears the pasted client JSON before opening the existing form. Configure authentication separately through the upstream's documented flow and Miftah secret references.

When setup finishes, Miftah tells you whether it ran a reviewed check, skipped one, or had no declared safe check at all. Browser sign-in setup can finish with browser authorization still outstanding. It saves a discovered connection plan, not a credential; use the later connect action to start the provider's browser flow. A completed configuration is not the same as a working client. You still review and merge any client JSON yourself, then restart or reconnect the client.

## First setup: GitHub with Claude Desktop
Expand Down
4 changes: 3 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ miftah validate --config "$HOME/Miftah configs/work wrapper.json"

For a static local account, noninteractive use requires `--profile` and `--credential-env`; the latter is an environment-variable name, never a secret value. This path accepts only a configuration with exactly one unnamed `stdio` upstream, one direct `${ENV_NAME}` credential binding in every profile, one shared destination/policy, no provider adapter, no native OAuth, and no named upstreams or other profile overrides. It atomically adds one profile that points at a different environment variable, enforces profile-switch confirmation and explicit destructive selection, and never starts the upstream or reads the credential. Remote HTTP credentials use headers rather than profile environments, so remote configurations fail closed with `ENVIRONMENT_PROFILE_ADDITION_UNSUPPORTED`. Generic `--verify` is deliberately rejected because Miftah has no declared safe probe. The durable default changes only when `--make-default` is present, so existing MCP clients still need a restart or new connection.

`miftah setup <name> --import-file <absolute-json-file> --import-entry <name>` is a separate no-secret flow, not a generic client migration. The same flow is available to a first-time interactive user: run bare `miftah setup`, choose `import` at `What do you already have? (connector, remote HTTPS, local executable, browser sign-in, import) [connector]`, provide the exact file, and select one listed entry by number or exact name. The source file must be an absolute regular non-symlink file. Miftah reads it through one bounded verified handle, requires an explicitly selected entry, and never changes the source. Guided import lists safe entry names only; it does not print source command, argument, header, environment, or credential data. It accepts either a local `stdio` entry under `mcpServers` (Claude Desktop, Claude Code, or Cursor) or `servers` (VS Code) that fits its finite static launch grammar—literal executable, optional absolute working directory, and either an exact-version package-runner launch with only that runner's fixed safe prefix flags and no arguments after the package, a script path plus non-sensitive flags, or a direct executable plus non-sensitive flags—or one credential-free HTTPS remote entry. A remote import uses `url` under `mcpServers` or `servers` and must explicitly declare `type: "http"` or `"streamable-http"`. It requires HTTPS without userinfo, query, fragment, or opaque credential-shaped path segments, and does not discover OAuth or call the remote endpoint. On Windows, a local import accepts only a direct absolute `.exe` or `.com` executable; bare runners such as `npx` or `node`, and `.cmd`/`.bat` shims, are rejected rather than being dispatched through a command processor. It rejects `env`, headers, shell settings, unknown fields, environment wrappers, inline code, opaque values or assignments, unsupported remote transports, URL userinfo, opaque credential-shaped URL path segments, unpinned package references, and credential-shaped arguments. It creates a read-only default profile with unknown tool risk set to destructive and does not launch the imported program. `--verify` is rejected before publication because no reviewed provider adapter is inferred. Use advanced manual setup when the existing entry does not fit this grammar; configure upstream credentials or OAuth separately through the upstream's documented path and Miftah secret references.
`miftah setup <name> --import-file <absolute-json-file> --import-entry <name>` is a separate no-secret flow, not a generic client migration. The same flow is available to a first-time interactive user: run bare `miftah setup`, choose `import` at `What do you already have? (connector, remote HTTPS, local executable, browser sign-in, import) [connector]`, provide the exact file, and select one listed entry by number or exact name. The source file must be an absolute regular non-symlink file. Miftah reads it through one bounded verified handle, requires an explicitly selected entry, and never changes the source. Guided import lists safe entry names only; it does not print source command, argument, header, environment, or credential data. It accepts either a local `stdio` entry under `mcpServers` (Claude Desktop, Claude Code, or Cursor) or `servers` (VS Code) that fits its finite static launch grammar—literal executable, optional absolute working directory, and either an exact-version package-runner launch with only that runner's fixed safe prefix flags and no arguments after the package, a script path plus non-sensitive flags, or a direct executable plus non-sensitive flags—or one credential-free HTTPS remote entry. A remote import uses `url` under `mcpServers` or `servers` and must explicitly declare `type: "http"` or `"streamable-http"`. It requires HTTPS without userinfo, query, fragment, or opaque credential-shaped path segments, and does not discover OAuth or call the remote endpoint. On Windows, a local import accepts only a direct absolute `.exe` or `.com` executable; bare runners such as `npx` or `node`, and `.cmd`/`.bat` shims, are rejected rather than being dispatched through a command processor. It rejects `env`, headers, shell settings, unknown fields, environment wrappers, inline code, opaque values or assignments, unsupported remote transports, URL userinfo, opaque credential-shaped URL path segments, unpinned package references, and credential-shaped arguments. It creates a read-only default profile with unknown tool risk set to destructive and does not launch the imported program. `--verify` is rejected before publication because no reviewed provider adapter is inferred.

If guided import refuses a selected entry, Miftah keeps no rejected source values and writes no configuration from it. It preserves only the non-secret configuration name and output location already collected, then moves to the existing interactive manual transport setup. Re-enter either a reviewed local executable with literal arguments or a canonical HTTPS endpoint; do not copy the rejected entry wholesale. Configure credentials or OAuth separately through the upstream's documented flow and Miftah secret references. This recovery applies only to bare interactive `miftah setup`; the explicit `--import-file` and `--import-entry` command remains fail-closed with a safe error for scripts and automation.

### Setup completion

Expand Down
21 changes: 16 additions & 5 deletions src/cli/setup-client-entry-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { mkdir } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import {
ClientEntryImportError,
createImportedClientConfiguration
createImportedClientConfiguration,
type ClientEntryImportErrorReason
} from "../setup/client-entry-import.js";
import { readClientEntryImportFile } from "../setup/client-entry-import-file.js";
import {
Expand All @@ -22,8 +23,18 @@ import type { CliOptions } from "./parse.js";

type ClientEntryImportSetupOptions = InitCommandOptions & Pick<CliOptions, "importFile" | "importEntry">;

function usageError(message: string): never {
throw new CliUsageError(message);
/**
* Preserves the safe importer reason for the guided setup flow while retaining
* the public CLI usage-error contract for direct imports.
*/
export class ClientEntryImportSetupError extends CliUsageError {
constructor(message: string, readonly importReason?: ClientEntryImportErrorReason) {
super(message);
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

function usageError(message: string, importReason?: ClientEntryImportErrorReason): never {
throw new ClientEntryImportSetupError(message, importReason);
}

function isClientSelection(value: string): value is ClientSelection {
Expand Down Expand Up @@ -107,7 +118,7 @@ export async function runClientEntryImportSetup(
try {
document = await readClientEntryImportFile(options.importFile);
} catch (error) {
if (error instanceof ClientEntryImportError) usageError(error.message);
if (error instanceof ClientEntryImportError) usageError(error.message, error.reason);
throw error;
}
return runClientEntryImportSetupFromDocument(options, context, document);
Expand Down Expand Up @@ -141,7 +152,7 @@ export async function runClientEntryImportSetupFromDocument(
entry: options.importEntry
});
} catch (error) {
if (error instanceof ClientEntryImportError) usageError(error.message);
if (error instanceof ClientEntryImportError) usageError(error.message, error.reason);
throw error;
}

Expand Down
64 changes: 47 additions & 17 deletions src/cli/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CliUsageError } from "./parse.js";
import type { CliOptions } from "./parse.js";
import { runInitCommand, type InitCommandContext, type InitCommandOptions } from "./init.js";
import {
ClientEntryImportSetupError,
runClientEntryImportSetup,
runClientEntryImportSetupFromDocument
} from "./setup-client-entry-import.js";
Expand Down Expand Up @@ -41,6 +42,10 @@ export interface SetupCommandResult {
type ReadinessDecision = "verify" | "skip" | "cancelled";
type AccountAdditionKind = "provider" | "environment";
type GuidedSetupStartingPoint = "connector" | "remote" | "local" | "remote-sign-in" | "import";
type GuidedClientEntryImportResult = Awaited<ReturnType<typeof runClientEntryImportSetupFromDocument>>;
type GuidedClientEntryImportOutcome =
| { readonly kind: "imported"; readonly result: GuidedClientEntryImportResult }
| { readonly kind: "manual-recovery"; readonly name: string; readonly output: string; readonly client?: string };

interface InteractivePromptSession {
prompt(label: string, defaultValue?: string): Promise<string | undefined>;
Expand Down Expand Up @@ -160,7 +165,7 @@ function selectedGuidedClientEntry(answer: string | undefined, entries: readonly
*/
async function runGuidedClientEntryImport(
context: InitCommandContext
): Promise<Awaited<ReturnType<typeof runClientEntryImportSetupFromDocument>>> {
): Promise<GuidedClientEntryImportOutcome> {
const prompts = createInteractivePromptSession(context, "Guided client-entry import was cancelled.");
try {
const importFile = await prompts.prompt("Client configuration file (absolute path)");
Expand Down Expand Up @@ -188,13 +193,28 @@ async function runGuidedClientEntryImport(
"Client (claude-desktop, claude-code, cursor, vscode, all; blank for config only)"
);

return runClientEntryImportSetupFromDocument({
name,
output,
...(client === undefined ? {} : { client }),
importFile,
importEntry
}, context, document);
try {
const result = await runClientEntryImportSetupFromDocument({
name,
output,
...(client === undefined ? {} : { client }),
importFile,
importEntry
}, context, document);
return { kind: "imported", result };
} catch (error) {
if (!(error instanceof ClientEntryImportSetupError) || error.importReason === undefined) throw error;
context.output.write(
"Miftah did not import this entry or write a configuration from it. It did not retain its arguments, headers, environment values, or credentials.\n" +
"Choose 'local' to re-enter a reviewed executable and literal arguments, or 'remote' for a canonical HTTPS endpoint. Configure authentication separately.\n"
);
return {
kind: "manual-recovery",
name,
output,
...(client === undefined ? {} : { client })
};
}
} finally {
prompts.close();
}
Expand Down Expand Up @@ -389,28 +409,38 @@ export async function runSetupCommand(options: SetupCommandOptions, context: Ini
return { verification: "not-applicable", exitCode: 0, reports: [] };
}
let guidedPreset: "streamable-http" | "local-stdio" | undefined;
let recoveredManualConfiguration: Awaited<ReturnType<typeof runInitCommand>> | undefined;
if (isTty(context) && !hasExplicitNewConfigurationInput(options)) {
const startingPoint = await chooseGuidedSetupStartingPoint(context);
if (startingPoint === "import") {
const imported = await runGuidedClientEntryImport(context);
writeCliSetupCompletion(context, {
verification: "not-declared",
clientHandoff: imported.clientHandoff ?? "not-generated",
configPath: imported.output
});
return { verification: "not-applicable", exitCode: 0, reports: [] };
if (imported.kind === "imported") {
writeCliSetupCompletion(context, {
verification: "not-declared",
clientHandoff: imported.result.clientHandoff ?? "not-generated",
configPath: imported.result.output
});
return { verification: "not-applicable", exitCode: 0, reports: [] };
}
recoveredManualConfiguration = await runInitCommand({
...options,
name: imported.name,
output: imported.output,
interactive: true,
...(imported.client === undefined ? {} : { client: imported.client })
}, context);
}
if (startingPoint === "remote-sign-in") {
if (recoveredManualConfiguration === undefined && startingPoint === "remote-sign-in") {
await runNativeOAuthSetup(options, context, {
...(context.nativeOAuthFetch === undefined ? {} : { fetch: context.nativeOAuthFetch })
});
return { verification: "not-applicable", exitCode: 0, reports: [] };
}
if (startingPoint === "remote" || startingPoint === "local") {
if (recoveredManualConfiguration === undefined && (startingPoint === "remote" || startingPoint === "local")) {
guidedPreset = startingPoint === "remote" ? "streamable-http" : "local-stdio";
}
}
const created = await runInitCommand({
const created = recoveredManualConfiguration ?? await runInitCommand({
...options,
interactive: true,
...(guidedPreset === undefined ? {} : { preset: guidedPreset })
Expand Down
Loading