init
Purpose
The init command creates a workspace — a directory with a swag2mcp.yaml config file and subdirectories for cache, specs, responses, and auth scripts. This is the first command to run when setting up swag2mcp.
When to use
- You are setting up swag2mcp for the first time
- You want to create a new workspace in a specific directory
- You need to re-initialize a corrupted or missing workspace
Syntax
bash
swag2mcp init [path] [flags]Arguments
| Argument | Position | Required | Description |
|---|---|---|---|
path | 1 | No | Workspace directory. If omitted, defaults to ~/.swag2mcp. |
Flags
| Flag | Shorthand | Type | Default | Description |
|---|---|---|---|---|
--interactive | -i | bool | false | Run the interactive TUI wizard |
--force | -f | bool | false | Overwrite existing configuration in a non-empty directory |
How it works
Non-interactive mode (default)
Creates a minimal swag2mcp.yaml with no specs. You edit the file manually afterwards.
bash
swag2mcp init
# Creates ~/.swag2mcp/swag2mcp.yaml
swag2mcp init ./my-project
# Creates ./my-project/swag2mcp.yaml
swag2mcp init /absolute/path
# Creates /absolute/path/swag2mcp.yamlInteractive mode (-i)
Launches an 18-step TUI wizard that guides you through:
- Choosing the workspace directory
- Adding specs with domain, title, base URL
- Configuring collections with location URLs
- Setting up authentication (all 9 methods)
- Configuring HTTP client settings (timeout, proxy, headers, etc.)
bash
swag2mcp init -iForce mode (--force)
By default, init refuses to run in a non-empty directory. Use --force to overwrite:
bash
swag2mcp init -f
swag2mcp init ./existing-dir -fWhat gets created
~/.swag2mcp/
├── swag2mcp.yaml # Configuration file
├── cache/ # Downloaded remote spec files
├── specs/ # Local spec files
├── responses/ # Saved API invocation responses
└── auth_scripts/ # Authentication scripts (for ScriptAuth type)Post-command verification
bash
ls ~/.swag2mcp/swag2mcp.yaml
# If the file exists, init succeededNuances
- Path resolution:
[path]is a workspace directory, not a file path. The CLI appendsswag2mcp.yamlautomatically. Resolution order: explicit[path]→ current directory (./) →~/.swag2mcp/. - Non-empty directory check: Without
--force,initreturns an error if the target directory exists and is not empty. This prevents accidental overwrites. - Auth script stubs: If any spec uses
ScriptAuth,initcreates stub script files (.shon Unix,.baton Windows) inauth_scripts/. - Output: On success, prints the config path and a hint:
"Next step: edit swag2mcp.yaml or run 'swag2mcp ls' to list configured specs".