Skip to content

Commit 8669ec8

Browse files
authored
Merge pull request #7 from bitrefill/auth
Headless CLI and agentic account auth
2 parents 1d54053 + 160cb78 commit 8669ec8

15 files changed

Lines changed: 966 additions & 667 deletions

.env.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,49 @@ npm install -g @bitrefill/cli
1414

1515
## Quick start (`init`)
1616

17-
The fastest way to set up the CLI:
18-
19-
```bash
20-
bitrefill init
21-
```
22-
23-
This walks you through a one-time setup:
24-
25-
1. Prompts for your API key (masked input) -- get one at [bitrefill.com/account/developers](https://www.bitrefill.com/account/developers)
26-
2. Validates the key against the Bitrefill MCP server
27-
3. Stores the key in `~/.config/bitrefill-cli/credentials.json` (permissions `0600`)
28-
4. If [OpenClaw](https://github.com/openclaw/openclaw) is detected, registers Bitrefill as an MCP server and generates a `SKILL.md` for agents
29-
3017
Non-interactive and agent-driven usage:
3118

3219
```bash
33-
# Pass the key directly (scripts, CI, OpenClaw agents)
34-
bitrefill init --api-key YOUR_API_KEY --non-interactive
35-
36-
# Or via environment variable
37-
export BITREFILL_API_KEY=YOUR_API_KEY
38-
bitrefill init --non-interactive
20+
# Initialize in non-interactive mode
21+
bitrefill init
3922

4023
# Force OpenClaw integration even if not auto-detected
4124
bitrefill init --openclaw
4225
```
4326

44-
After `init`, the stored key is picked up automatically -- no need to pass `--api-key` on every invocation.
27+
```bash
28+
bitrefill login --email you@example.com
29+
bitrefill verify --code 123456
30+
```
4531

4632
### OpenClaw + Telegram
4733

4834
If you use [OpenClaw](https://github.com/openclaw/openclaw) as your AI agent gateway (e.g. via Telegram), `bitrefill init` does extra work:
4935

50-
- Writes `BITREFILL_API_KEY` to `~/.openclaw/.env` (read by the gateway at activation)
51-
- Adds an MCP server entry to `~/.openclaw/openclaw.json` using `${BITREFILL_API_KEY}` -- the config file never contains the actual key
36+
- Adds an MCP server entry to `~/.openclaw/openclaw.json`
5237
- Generates `~/.openclaw/skills/bitrefill/SKILL.md` so the agent knows about all available tools
5338

5439
After init, tell your Telegram bot: *"Search for Netflix gift cards on Bitrefill"*.
5540

5641
## Authentication
5742

58-
### API Key (recommended)
59-
60-
Generate an API key at [bitrefill.com/account/developers](https://www.bitrefill.com/account/developers). After running `bitrefill init`, the key is stored locally and used automatically.
43+
### Sign in
6144

62-
You can also pass it explicitly:
45+
Two steps. Use the emailed verification `--code`; add `--otp` if your account also requires a second factor (for example TOTP).
6346

6447
```bash
65-
# Flag
66-
bitrefill --api-key YOUR_API_KEY search-products --query "Netflix"
67-
68-
# Environment variable
69-
export BITREFILL_API_KEY=YOUR_API_KEY
70-
bitrefill search-products --query "Netflix"
48+
bitrefill login --email you@example.com
49+
bitrefill verify --code 123456
7150
```
7251

73-
Key resolution priority: `--api-key` flag > `BITREFILL_API_KEY` env var > stored credentials file.
74-
75-
### OAuth
76-
77-
On first run without an API key, the CLI opens your browser for OAuth authorization. Credentials are stored in `~/.config/bitrefill-cli/`.
78-
7952
### Non-interactive / CI
8053

81-
In environments without a TTY (e.g. CI, Docker, scripts), or when `CI=true`, the CLI cannot complete browser-based OAuth. Use `bitrefill init` first, or pass `--api-key` / `BITREFILL_API_KEY`.
82-
83-
Node does not load `.env` files automatically. After editing `.env`, either export variables in your shell (`set -a && source .env && set +a` in bash/zsh) or pass `--api-key` on the command line.
54+
In environments without a TTY (e.g. CI, Docker, scripts), ensure credentials are provided by your runtime and then run `bitrefill init`.
8455

8556
## Usage
8657

8758
```bash
88-
bitrefill [--api-key <key>] [--json] [--no-interactive] <command> [options]
59+
bitrefill [--json] [--no-interactive] <command> [options]
8960
```
9061

9162
### Human-readable output (default)
@@ -110,11 +81,10 @@ bitrefill --json search-products --query "Amazon" --per_page 1 | jq '.products[0
11081
Generates Markdown from the MCP `tools/list` response: tool names, descriptions, parameter tables, JSON Schema, example `bitrefill …` invocations, and example MCP `tools/call` payloads. Intended for **CLAUDE.md**, **Cursor** rules, or **`.github/copilot-instructions.md`**.
11182

11283
- **stdout** by default, or **`-o` / `--output <file>`** to write a file.
113-
- Uses the same auth as other commands (`--api-key`, `BITREFILL_API_KEY`, or OAuth).
114-
- The generated **Connection** line shows a redacted MCP URL (`…/mcp/<API_KEY>`), not your real key.
84+
- Uses the same auth as other commands.
85+
- The generated **Connection** line shows a redacted MCP URL, not sensitive credentials.
11586

11687
```bash
117-
export BITREFILL_API_KEY=YOUR_API_KEY
11888
bitrefill llm-context -o BITREFILL-MCP.md
11989
# or: bitrefill llm-context > BITREFILL-MCP.md
12090
```
@@ -140,7 +110,7 @@ bitrefill list-orders
140110
# List available commands
141111
bitrefill --help
142112

143-
# Clear stored credentials
113+
# Clear local login session
144114
bitrefill logout
145115

146116
# Export tool docs for coding agents (see "LLM context" above)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
],
2323
"packageManager": "pnpm@10.27.0",
2424
"dependencies": {
25-
"@modelcontextprotocol/sdk": "^1.27.1",
25+
"@modelcontextprotocol/sdk": "^1.29.0",
2626
"@toon-format/toon": "^2.1.0",
2727
"commander": "^14.0.3"
2828
},
2929
"devDependencies": {
30-
"@types/node": "^25.3.0",
30+
"@types/node": "^25.7.0",
3131
"prettier": "^3.8.1",
3232
"tsx": "^4.21.0",
3333
"typescript": "^5.8.3",

pnpm-lock.yaml

Lines changed: 29 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
overrides:
2+
mcp-oauth-server: link:../../dev/mcpoauth

src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const DEFAULT_BASE_MCP_URL = 'https://api.bitrefill.com/mcp';
2+
3+
export const BASE_MCP_URL = process.env.BASE_URL || DEFAULT_BASE_MCP_URL;
4+
5+
export const IS_DEFAULT_BASE_MCP_URL = BASE_MCP_URL === DEFAULT_BASE_MCP_URL;

0 commit comments

Comments
 (0)