# Sanplex CLI

![npm](https://img.shields.io/npm/v/sanplex-cli) ![Node.js](https://img.shields.io/node/v/sanplex-cli) ![License](https://img.shields.io/npm/l/sanplex-cli)

[简体中文](README.md) | English

A command-line tool for Sanplex that lets you access and manage Sanplex data from your favorite terminal, with support for AI agents.

## Features

* Built on Sanplex RESTful API 2.0, covering more than 40 modules and 300 API operations, with version compatibility checks before each request
* Run without installation using `npx sanplex-cli`
* Log in through your browser, store only tokens instead of passwords, and switch between multiple accounts
* Select fields, filter and sort data, and automatically convert HTML to Markdown
* Built for AI agents, with comprehensive help and Markdown and JSON output
* Install skills into AI agents with `sanplex add-skill`
* Run a local stdio or remote HTTP MCP service, with each client using its own Sanplex token

## Requirements

* Node.js 18 or later
* Sanplex Open Source `22.0`, Biz `biz13.0`, Max `max8.0`, or IPD `ipd5.0` or later

Some operations require a newer Sanplex version. The CLI checks compatibility and reports any requirements before sending a request. See [API coverage and version compatibility](docs/cli-usage.md#api-覆盖与版本兼容).

## Quick start

```bash
# Install globally
npm install -g sanplex-cli

# Alternatively, install with Bun or run without installation
# bun install -g sanplex-cli
# npx sanplex-cli
# pnpm dlx sanplex-cli

# Log in: a browser opens for you to enter your Sanplex URL, username, and password
sanplex login

# List products
sanplex product
```

In a terminal without a graphical environment, use `sanplex login --no-browser` for interactive login. For environment variables, account switching, and logout, see [Authentication](docs/cli-usage.md#用户验证).

## Common commands

Commands follow the format `sanplex <module> [action] [arguments]`. Omit the action to list items, or provide only an ID to view an item's details.

### Products

```bash
# List products
sanplex product

# View product details
sanplex product 1

# Create a product
sanplex product create --name="New product"

# Update a product's name
sanplex product update 1 --name="Updated product name"

# Delete a product
sanplex product delete 1
```

### Bugs

```bash
# List bugs for product #1
sanplex bug --product=1

# View bug details
sanplex bug 329

# Resolve a bug
sanplex bug resolve 329 --resolution=fixed
```

### Stories and tasks

```bash
# List stories for product #1
sanplex story --product=1

# Create a task in execution #10
sanplex task create --name="Implement login" --executionID=10
```

### Filtering and output formats

```bash
# Show only the selected fields
sanplex product --pick=id,name

# Filter by a condition
sanplex bug --product=1 --filter 'status=active'

# Fuzzy search
sanplex story --product=1 --search=login --search-fields=title

# Sort by a field
sanplex bug --product=1 --sort=id:desc

# Output JSON for use in scripts
sanplex product --format=json
```

### Help

```bash
# Show all commands
sanplex help

# Show a module's available actions and parameters
sanplex bug --help

# Show an action's parameters and minimum Sanplex version
sanplex bug resolve --help
```

### Get a token

Use `sanplex token` when you need a token for a script or MCP configuration:

```bash
# Read the saved token for the current account or a specific account
sanplex token
sanplex token 'admin@https://sanplex.example.com'

# Obtain a new token without saving it to the CLI configuration
sanplex token --server https://sanplex.example.com --user admin --password '<password>'
```

By default, the command outputs only the token on a single line. Reading a saved token does not validate it over the network, modify the configuration, or switch accounts. See [Get a token](docs/cli-usage.md#获取-token).

For more features, including piped input, batch operations, pagination, and configuration management, see the [CLI guide](docs/cli-usage.md).

## Use with AI agents

There are three ways to use Sanplex with AI agents:

| Method | Use case | CLI installation required |
| --- | --- | --- |
| Skill | Personal use; the agent runs CLI commands in a terminal | Yes |
| Local MCP | Personal use; the agent accesses the CLI through MCP tools | Yes |
| Remote MCP | A shared company deployment; users connect with their own tokens | No |

For full instructions, see [Use Sanplex with agents](docs/use-sanplex-in-agents.md).

### Use skills

```bash
# Install, log in, and install skills (choose the target agent interactively)
npm install -g sanplex-cli && sanplex login && sanplex add-skill

# Specify the target agent directly; all installs into every supported agent
sanplex add-skill claude-code
sanplex add-skill all

# Export all built-in skills to a directory
sanplex add-skill --output ./skills
```

Supported agents include Claude Code, Cursor, Cherry Studio, Codex, OpenCode, VS Code, Antigravity, and Gemini. After installation, ask your agent questions in natural language:

```txt
What products are available in Sanplex?

Which stories are under development for product xxx?

What risks are associated with story xxx?
```

When an agent starts the login flow, it should use `sanplex login --web` and keep the process running until the user finishes authentication in the browser. In CI or containers, you can inject credentials through environment variables or mount a configuration file. The agent can first run `sanplex profile --effective --format=json` to confirm which account is in use; the output contains no token or password. See [Credentials for agents, CI, and containers](docs/use-sanplex-in-agents.md#agentci-与容器中的凭据).

### Use local MCP

```bash
# Install, log in, and configure local stdio MCP (choose the target agent interactively)
npm install -g sanplex-cli && sanplex login && sanplex add-mcp
```

`sanplex add-mcp` reuses the current account's token and does not write your Sanplex password to the agent configuration. Add startup options to `args` in the MCP configuration to limit access:

```bash
# Allow only read operations and restrict the available modules
sanplex mcp --read-only --modules product,story,task,bug

# Split each module into separate read and write tools for separate client permissions
sanplex mcp --split-tools --modules product,story,task,bug
```

For the generated configuration format and all startup options, see [MCP service](docs/cli-usage.md#mcp-服务).

### Use remote MCP

`sanplex mcp-server` is designed for a shared deployment managed by a company administrator. Users need only the service URL and their own Sanplex tokens, without installing sanplex-cli. Sanplex handles requests according to each account's permissions.

```bash
# On the server, start the service with a fixed Sanplex site URL
sanplex mcp-server https://sanplex.example.com
```

After startup, open `http://127.0.0.1:9090/start`. Users can obtain their personal tokens on this page and copy the connection instructions for an agent to help with setup. Administrators must expose both `/start` and `/mcp` through an HTTPS reverse proxy.

* For administrators: [Sanplex MCP deployment guide](docs/mcp-server.md)
* For users: [Connect an agent to the Sanplex MCP service](docs/mcp-user-guide.md)

## Documentation

The linked guides and changelog are currently in Chinese.

| Document | Description |
| --- | --- |
| [Interactive command reference (HTML)](docs/command-reference.html) | Open in a browser to search commands and parameters, and filter by module and action type |
| [Command, parameter, and usage reference](docs/command-reference.md) | All built-in commands, module actions, parameter types, required fields, allowed values, and usage examples |
| [CLI guide](docs/cli-usage.md) | Authentication, data access and operations, data processing, output formats, configuration, and more |
| [Use Sanplex with agents](docs/use-sanplex-in-agents.md) | Use Sanplex in AI agents through skills or MCP |
| [Sanplex MCP deployment guide](docs/mcp-server.md) | Deploy a shared remote MCP service, configure an HTTPS reverse proxy, and make it available to users |
| [Connect an agent to the Sanplex MCP service](docs/mcp-user-guide.md) | Obtain a personal Sanplex token and configure remote MCP in an agent |
| [Development guide](docs/development.md) | Technology stack, project structure, testing, and builds |
| [Technical design and implementation](docs/implementation.md) | Internal API calling rules, authentication, and persistent configuration |
| [Troubleshooting and error reference](docs/errors.md) | Error code reference (Exxxx) |
| [Roadmap](docs/roadmap.md) | Planned features and improvements |
| [Changelog](CHANGES.md) | Changes in each release |



## License

[MIT](LICENSE)
