npm package: @patchops/cli
Description: Command-line client for PatchOps MCP instance URLs.
Latest version: 0.1.0

# PatchOps CLI

PatchOps CLI supports both of the main PatchOps execution surfaces:

- direct invoke over `/api/v1/invoke` for automation-friendly `connector + method + args`
- MCP over `/api/mcp` for tool discovery, raw MCP inspection, and sandboxed code execution

The CLI still starts from a PatchOps MCP URL such as:

```text
https://patchops.ai/api/mcp/<instanceId>
```

It supports two auth modes:

- PatchOps OAuth login against the shared MCP endpoint, `https://patchops.ai/api/mcp`
- Personal access token auth against a direct instance URL such as `https://patchops.ai/api/mcp/<instanceId>`

That gives agents and local tools a normal CLI path without forcing them to speak MCP directly, while still leaving the MCP transport available when you need it.

## Install

From npm, once the package is published:

```bash
npm install -g @patchops/cli
patchops help
```

From the repo:

```bash
npm install
npm run cli:build
node cli/dist/index.js help
```

To expose a global `patchops` command from a local checkout:

```bash
cd cli
npm link
patchops help
```

## Build

From the repo root:

```bash
npm run cli:build
```

The compiled binary is written to `cli/dist/index.js`.

To produce the npm tarball locally:

```bash
npm run cli:pack
```

## Configure

Log in with your PatchOps account through OAuth:

```bash
node cli/dist/index.js login
```

This stores a refreshable CLI session and points the CLI at the shared MCP endpoint.

Set both the direct MCP URL and a personal access token with environment variables:

```bash
export PATCHOPS_URL="https://patchops.ai/api/mcp/<instanceId>"
export PATCHOPS_TOKEN="po_pat_..."
```

Or store them locally:

```bash
node cli/dist/index.js config set-url "https://patchops.ai/api/mcp/<instanceId>"
node cli/dist/index.js config set-token "po_pat_..."
```

You can inspect the current config with:

```bash
node cli/dist/index.js config show
```

Sign out and remove the stored OAuth session:

```bash
node cli/dist/index.js logout
```

## Commands

Direct invoke for automation:

```bash
node cli/dist/index.js invoke welldatabase getOperatorWells --input '{"county":"Loving","operator":"Mitsui"}'
node cli/dist/index.js invoke postgres query --input '{"sql":"select now() as ts"}' --json
```

List tools:

```bash
node cli/dist/index.js tools list
node cli/dist/index.js tools list corva
```

Call a built-in PatchOps tool over MCP:

```bash
node cli/dist/index.js call patchops_listSkills
node cli/dist/index.js call patchops_orgViewUsage --input '{"month":3,"year":2026}'
```

Agent-friendly JSON output:

```bash
node cli/dist/index.js tools list --json
node cli/dist/index.js call patchops_listSkills --json
```

Execute sandboxed connector code over MCP:

```bash
node cli/dist/index.js exec welldatabase ./examples/welldatabase.ts --timeout 60
```

Clear just the stored token:

```bash
node cli/dist/index.js config clear-token
```

Run a JSON-RPC batch file:

```bash
node cli/dist/index.js batch ./requests.json
```

Batch files can be either:

```json
[
  {
    "tool": "patchops_listSkills",
    "input": {}
  },
  {
    "tool": "patchops_orgListMembers",
    "input": {}
  }
]
```

or raw JSON-RPC:

```json
[
  {
    "jsonrpc": "2.0",
    "id": "members",
    "method": "tools/call",
    "params": {
      "name": "patchops_orgListMembers",
      "arguments": {}
    }
  }
]
```

## Publish

Local publish:

```bash
cd cli
npm publish --access public
```

GitHub Actions publish:

- add an `NPM_TOKEN` repository secret with publish access to the `@patchops` scope
- run the `Publish CLI` workflow from `main`