Skip to content

Commit 9bf1cde

Browse files
authored
Merge pull request #2 from bitrefill/json-output
JSON output, output modules, tests, and CI
2 parents 989e487 + 2feae25 commit 9bf1cde

11 files changed

Lines changed: 1137 additions & 115 deletions

File tree

.github/workflows/commit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ jobs:
2020
run: pnpm install --frozen-lockfile
2121
- name: Format
2222
run: pnpm format
23+
- name: Test
24+
run: pnpm test
2325
- name: Build
2426
run: pnpm build

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ jobs:
2121
registry-url: 'https://registry.npmjs.org'
2222
- run: pnpm install --frozen-lockfile
2323
- run: pnpm format
24+
- run: pnpm test
2425
- run: pnpm build
2526
- run: pnpm publish --provenance --access public --no-git-checks

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,29 @@ bitrefill search-products --query "Netflix"
3434
cp .env.example .env
3535
```
3636

37+
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.
38+
3739
## Usage
3840

3941
```bash
40-
bitrefill [--api-key <key>] <command> [options]
42+
bitrefill [--api-key <key>] [--json] <command> [options]
43+
```
44+
45+
### Human-readable output (default)
46+
47+
Tool results are pretty-printed JSON on stdout. Status messages (OAuth prompts, etc.) also go to stdout.
48+
49+
### Machine-readable output (`--json`)
50+
51+
Pass `--json` anywhere before the subcommand so scripts and `jq` get a single JSON value per invocation on stdout:
52+
53+
- **stdout**: Only the tool result (JSON). Text payloads from the server may be JSON or [TOON](https://toonformat.dev/); the CLI decodes TOON to JSON when needed.
54+
- **stderr**: Progress messages, errors, and client errors (JSON `{ "error": "..." }` for failures).
55+
56+
Example:
57+
58+
```bash
59+
bitrefill --json search-products --query "Amazon" --per_page 1 | jq '.products[0].name'
4160
```
4261

4362
### Examples
@@ -62,6 +81,18 @@ bitrefill --help
6281
bitrefill logout
6382
```
6483

84+
## Development
85+
86+
From the repository root (requires [pnpm](https://pnpm.io/)):
87+
88+
```bash
89+
pnpm install
90+
pnpm format # Prettier check
91+
pnpm test # Vitest unit tests
92+
pnpm build # Compile to dist/
93+
pnpm dev -- --help # Run CLI via tsx without building
94+
```
95+
6596
## Paying
6697

6798
**Flow:** `get-product-details` → pick `product_id` + `package_id``buy-products` with `--cart_items` and `--payment_method`.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"build": "tsc",
1111
"start": "node dist/index.js",
1212
"dev": "tsx src/index.ts",
13-
"format": "prettier --check ./src"
13+
"format": "prettier --check ./src",
14+
"test": "vitest run"
1415
},
1516
"repository": {
1617
"type": "git",
@@ -22,13 +23,15 @@
2223
"packageManager": "pnpm@10.27.0",
2324
"dependencies": {
2425
"@modelcontextprotocol/sdk": "^1.27.1",
26+
"@toon-format/toon": "^2.1.0",
2527
"commander": "^14.0.3"
2628
},
2729
"devDependencies": {
2830
"@types/node": "^25.3.0",
2931
"prettier": "^3.8.1",
3032
"tsx": "^4.21.0",
31-
"typescript": "^5.8.3"
33+
"typescript": "^5.8.3",
34+
"vitest": "^3.2.4"
3235
},
3336
"keywords": [
3437
"mcp",

0 commit comments

Comments
 (0)