Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
88d4c0b
docs: design for a pure proxy with no bundled tool list
zchpeter Nov 22, 2026
9138606
Read the tool list from Bytebase; delete the bundled copy (slice 1)
zchpeter Nov 22, 2026
9964a95
Sessions, sign-in and the token lock (slice 2)
zchpeter Nov 22, 2026
5b991e2
docs: revision 2, a snapshot for directories and the instance for users
zchpeter Nov 23, 2026
8ac04d1
Revision 2, slice 1: the snapshot for directories, the instance for u…
zchpeter Nov 23, 2026
5a5ecc8
Revision 2, slice 2: pages and recovery
zchpeter Nov 23, 2026
a967161
Reopen a dropped session on tools/list when a sign-in is stored
zchpeter Nov 23, 2026
dfe5265
Never let tools/list wait on a sign-in
zchpeter Nov 23, 2026
8c0dd9f
Abort a timed-out tools/list instead of sending it late
zchpeter Nov 23, 2026
d8d55ca
Announce the tool list when a timed-out reconnect opens
zchpeter Nov 23, 2026
0371fee
Announce only a reopen, not a slow answer on an open session
zchpeter Nov 23, 2026
8faaa83
Cap the startup retry at ten attempts
zchpeter Nov 23, 2026
a640575
logout revokes each refresh token before deleting it
zchpeter Nov 23, 2026
885158b
Bound logout's requests; sign in again after a mid-session revoke
zchpeter Nov 23, 2026
2c3a37a
Retire a replaced session instead of closing it under in-flight calls
zchpeter Nov 23, 2026
e94249b
Tie sign-in permission to the opening, not a shared flag
zchpeter Nov 23, 2026
2e6160b
Keep an in-progress sign-in's state with its opening
zchpeter Nov 23, 2026
d834d36
Keep sign-ins in ~/.bytebase-mcp
zchpeter Nov 23, 2026
9b93acd
Forward confirmation forms without a deadline, and their withdrawal
zchpeter Nov 23, 2026
0b5d27b
docs: CONTRIBUTING.md with the local testing flow
zchpeter Nov 23, 2026
3839414
docs: the sign-in opens at startup, not on the first call
zchpeter Nov 23, 2026
2ac91f0
docs(readme): the sign-in opens when the server first starts
zchpeter Nov 23, 2026
a0fe2a3
Add a reconnect note to a successful reauthorize
zchpeter Nov 23, 2026
a78e2fa
Correct the reconnect note: it clears the old account, not names the new
zchpeter Nov 23, 2026
ed71ea8
Name the previous account in the reauthorize note only when it was named
zchpeter Nov 23, 2026
57546e8
Fix stale help text, pin the SDK, open only http(s) sign-in URLs
adela-bytebase Nov 23, 2026
876939c
Keep only the reconnect advice in the reauthorize note
zchpeter Nov 23, 2026
2e8c7e2
Follow up review: gateway 5xx is unreachable, no shell for the browse…
zchpeter Nov 24, 2026
86ff5a9
Retry startup when OAuth discovery gets a gateway's 502/503/504
zchpeter Nov 24, 2026
6a90232
Never retry a startup sign-in once its browser leg has started
zchpeter Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
.env
*.tgz
test/.tmp-home/
test/.tmp-home-*/
169 changes: 169 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Contributing

The design, with every state the server can be in, is in [docs/DESIGN.md](docs/DESIGN.md). This
file covers building, testing and releasing.

## Build and test

Node.js 20 or later.

```bash
npm install
npm run build
npm test
```

`npm test` drives the built server over stdio against a fake Bytebase (`test/fake-upstream.mjs`):
an OAuth server with PKCE and single-use refresh tokens, and an MCP endpoint. No instance or
browser is needed. It takes about two minutes; one test keeps a confirmation form open for longer
than a minute on purpose.

## Testing at four levels

Each level catches what the one before cannot.

1. **`npm test`**: every state, sign-in, the token lock, paging and recovery, against the fake.
2. **The directory view**: what an MCP directory sees with no instance configured. Open it in the
MCP Inspector:

```bash
npx @modelcontextprotocol/inspector node dist/index.js
```

Or print the tool list without the UI:

```bash
npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/list
```

It lists the bundled snapshot (`src/tools.json`), and every tool call answers that
`BYTEBASE_URL` is not set.
3. **A real instance**: `scripts/check-live.mjs` starts the server as a client would, lists tools,
and runs two read-only calls. Signed out, the first list is empty and the browser sign-in opens
as soon as the server starts; the first call waits for it.

```bash
BYTEBASE_URL=http://localhost:8080 BYTEBASE_MCP_HOME="$(mktemp -d)" node scripts/check-live.mjs
```

4. **A real client**, from a packed tarball, as users will run it (below).

## A Bytebase to sign in to

Sign-in goes through the instance's consent page: the authorize endpoint redirects the browser to
`/oauth2/consent` on the same host and port. So the instance must serve its console and its API
together:

- A backend built without the frontend answers that page with "This Bytebase build does not bundle
frontend and backend together", so sign-in cannot finish.
- The frontend dev server does not forward `/mcp`, so a frontend dev server in front of a separate
backend cannot complete sign-in either.

Build a bundled binary in the [bytebase](https://github.com/bytebase/bytebase) repository, as its
end-to-end tests do (`frontend/tests/e2e/README.md`), then run it with its external URL set, since
Bytebase binds MCP tokens to it:

```bash
(cd frontend && pnpm release)
bash frontend/tests/e2e/build-server.sh # writes ./bytebase-build/bytebase
./bytebase-build/bytebase --port 8080 --external-url http://localhost:8080 --data "$(mktemp -d)"
```

Without `PG_URL` it starts on embedded PostgreSQL. Sign up the first account in the browser at
`http://localhost:8080`.

## Testing a packed tarball in a client

```bash
npm run build
npm pack # writes bytebase-bytebase-mcp-<version>.tgz
```

Point the client at the tarball with `--package` and an absolute path:

```json
{
"mcpServers": {
"bytebase-local": {
"command": "npx",
"args": ["-y", "--package=/absolute/path/to/bytebase-bytebase-mcp-0.1.0.tgz", "bytebase-mcp"],
"env": {
"BYTEBASE_URL": "http://localhost:8080",
"BYTEBASE_MCP_HOME": "/tmp/bytebase-mcp-test"
}
}
}
}
```

In Claude Code:

```bash
claude mcp add bytebase-local -e BYTEBASE_URL=http://localhost:8080 -e BYTEBASE_MCP_HOME=/tmp/bytebase-mcp-test -- npx -y --package=/absolute/path/to/bytebase-bytebase-mcp-0.1.0.tgz bytebase-mcp
```

Two forms that look equivalent are not:

- `npx -y /absolute/path/to/x.tgz` fails with "Permission denied", and the client reports the
connection closed. npx looks for a local program by joining its argument onto
`node_modules/.bin`; an absolute path survives the join, the tarball exists, so npx tries to
execute the tarball itself.
- `npx -y ./x.tgz` works, but only when started from that folder, and a client does not start
there.

After re-packing, npx installs the new tarball even at the same path (checked with npm 11.6.1).
Its installs stay in the npx cache; find and remove them with:

```bash
grep -l bytebase-mcp ~/.npm/_npx/*/package.json # remove each listed file's directory
```

## Keeping test sign-ins apart

Sign-ins live in `~/.bytebase-mcp` by default. Set `BYTEBASE_MCP_HOME` to a throwaway directory
while testing, so your own sign-ins are untouched. To see and clear them:

```bash
BYTEBASE_MCP_HOME=/tmp/bytebase-mcp-test node dist/index.js status --url http://localhost:8080
BYTEBASE_MCP_HOME=/tmp/bytebase-mcp-test node dist/index.js logout --url http://localhost:8080
```

`logout` revokes each refresh token at the instance, then deletes it.

## Manual checks before a release

The automated tests do not cover these:

- [ ] The browser consent page names the client (`<client> via Bytebase MCP`), and allowing it
finishes the sign-in.
- [ ] On a first run, the tools appear after sign-in without restarting the client (the client
must honor `tools/list_changed`).
- [ ] A confirmation form (for example approving an issue) left open for more than a minute can
still be answered, and the answer reaches Bytebase.
- [ ] Clients not yet exercised: Cursor, Claude Desktop, Windsurf. Windows has never been run.

## Keeping the snapshot current

`src/tools.json` is the tool list MCP directories see before an instance is configured; a
configured server never reads it. Before a release, regenerate it from an instance on the latest
Bytebase release, never a development build, so directories list no tool users cannot get yet:

```bash
npm run build
BYTEBASE_URL=https://your-bytebase npm run sync-tools
```

The script signs in like the package does, writes the snapshot and the README's tools table, and
prints what changed.

## Releasing

```bash
npm version patch # bumps package.json and server.json together
git push origin main --follow-tags
```

A push to `main` that changes `package.json` runs
[`npm-publish.yml`](.github/workflows/npm-publish.yml): it publishes to npm with OIDC provenance,
then registers the version in the [MCP Registry](https://registry.modelcontextprotocol.io) with
`mcp-publisher`. No tokens are stored in the repository.
73 changes: 20 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

[![npm](https://img.shields.io/npm/v/@bytebase/bytebase-mcp)](https://www.npmjs.com/package/@bytebase/bytebase-mcp)

The official npm package for the [Bytebase](https://www.bytebase.com) MCP server. It lets AI assistants that run MCP servers as local commands (Claude Desktop, Cursor, Windsurf, and others) use the MCP server built into your Bytebase instance: query data, inspect schemas, and propose database changes, all under Bytebase's approvals, access control, data masking, and audit logging.
The official npm package for the [Bytebase](https://www.bytebase.com) MCP server. It lets AI assistants that can only run MCP servers as local commands use the MCP server built into your Bytebase instance: query data, inspect schemas, and propose database changes, all under Bytebase's approvals, access control, data masking, and audit logging.

```
AI assistant --stdio--> bytebase-mcp --HTTPS + OAuth--> <your Bytebase>/mcp --> your databases
```

The package contains no database logic of its own. It ships the tool definitions of Bytebase's built-in MCP server and forwards every call to your instance, where permissions, the workspace MCP access policy, approvals and audit apply exactly as in the console. Nothing is cached or executed locally except the OAuth token.
The package contains no Bytebase logic. Once you sign in, it lists your instance's own tools and forwards every call to the instance, where permissions, the workspace MCP access policy, approvals and audit apply exactly as in the console. Nothing is stored locally except the OAuth token.

> If your client supports remote MCP servers over HTTP (Claude Code, Codex, Copilot CLI, Gemini CLI, VS Code, Claude Desktop connectors), you do not need this package: point the client straight at `<your Bytebase URL>/mcp`. See the [MCP integration docs](https://docs.bytebase.com/integrations/mcp).
> Most clients, including Claude Code, Claude Desktop, Cursor, Codex, Copilot CLI, Gemini CLI and VS Code, connect to remote MCP servers over HTTP. They do not need this package: point them straight at `<your Bytebase URL>/mcp`. See the [MCP integration docs](https://docs.bytebase.com/integrations/mcp). This package is for clients that only start local commands, and for MCP directories.

## Requirements

- A Bytebase instance, 3.22 or later, with its [external URL](https://docs.bytebase.com/get-started/self-host/external-url) configured and the workspace MCP access policy not set to **Disabled**.
- Node.js 20 or later.
- Node.js 20 or later, on macOS or Linux. Windows has not been tested yet. If your browser does not open at sign-in there, find the sign-in URL in the server's output (your client's MCP log) and open it yourself.
- A Bytebase account. The package signs you in through Bytebase's own OAuth; it never sees your password.

## Setup
Expand All @@ -36,23 +36,15 @@ Add the server to your MCP client with your instance's external URL:
}
```

The first tool call opens your browser on Bytebase's authorization page. Sign in, review what the session may do, and click **Allow**. The token is stored under `~/.config/bytebase-mcp/` with owner-only permissions and refreshed automatically.

To sign in ahead of time, or on a machine without a browser:

```bash
BYTEBASE_URL=https://bytebase.example.com npx -y @bytebase/bytebase-mcp login
BYTEBASE_MCP_NO_BROWSER=1 BYTEBASE_URL=https://bytebase.example.com npx -y @bytebase/bytebase-mcp login # prints the URL instead
```
When the server first starts, it opens your browser on Bytebase's authorization page. Sign in, review what the session may do, and click **Allow**. Bytebase shows your AI client by name there, and each client application signs in once per instance. The token is stored under `~/.bytebase-mcp/` with owner-only permissions and refreshed automatically; several sessions share it safely. Set `BYTEBASE_MCP_NO_BROWSER=1` to print the sign-in URL instead of opening a browser.

### Commands

| Command | What it does |
| --- | --- |
| `bytebase-mcp` | Serve MCP over stdio (what your client runs) |
| `bytebase-mcp login` | Sign in now and store the token |
| `bytebase-mcp logout` | Forget the stored sign-in |
| `bytebase-mcp whoami` | Show the instance, token file, and the live tool list |
| `bytebase-mcp status` | Show the instance and the stored sign-ins, without signing in |
| `bytebase-mcp logout` | Revoke and forget every sign-in stored for the instance (does not sign you out of the console). To switch accounts: log out, reconnect the server in your client, sign in as the other account |

Every command takes `--url <bytebase-url>` in place of `BYTEBASE_URL`.

Expand All @@ -61,71 +53,46 @@ Every command takes `--url <bytebase-url>` in place of `BYTEBASE_URL`.
| Variable | Default | Purpose |
| --- | --- | --- |
| `BYTEBASE_URL` | – | External URL of the instance. Required to call tools. |
| `BYTEBASE_MCP_HOME` | `~/.config/bytebase-mcp` | Where token files live, one per instance host |
| `BYTEBASE_MCP_HOME` | `~/.bytebase-mcp` | Where sign-ins live, one per instance and client app |
| `BYTEBASE_MCP_CALLBACK_PORT` | `51789` | Loopback port that receives the OAuth redirect |
| `BYTEBASE_MCP_NO_BROWSER` | unset | Set to `1` to print the sign-in URL instead of opening a browser |

## Tools

The tools are Bytebase's. The list below is generated from the release named in `src/tools.json`; a connected instance's live list replaces it, so an older or newer Bytebase shows its own tools.
Once you sign in, the tools are the ones your instance serves, so an older or newer Bytebase shows its own. The table below is a snapshot, the list MCP directories see before any instance is configured:

<!-- tools:start -->
Generated from Bytebase 3.24.1.
Generated from Bytebase 3.25.0.

| Tool | Purpose |
| --- | --- |
| `administer_workspace` | Make a workspace administration change that the user confirms in this client first. |
| `call_api` | Execute a Bytebase API endpoint. |
| `decide_issue` | Approve or reject a Bytebase issue at its current approval step. |
| `get_gitops_workflow` | Return the workflow files that set up GitOps for a project. |
| `get_schema` | Inspect a Bytebase database's schema. |
| `get_skill` | Get step-by-step guides for Bytebase tasks. |
| `grant_masking_exemption` | Exempt one member from data masking in a Bytebase project, for one database (optionally one schema, table or column) or for every database in the project. |
| `grant_masking_exemption` | Exempt one member from data masking in a Bytebase project, for one database (optionally one schema, table, or columns of one table) or for every database in the project. |
| `propose_database_change` | Run DDL/DML changes (ALTER TABLE, CREATE TABLE, INSERT, UPDATE, migrations) against a Bytebase database. |
| `query_database` | Execute a SQL query against a Bytebase database. |
| `reauthorize` | Log out the current MCP OAuth connection so the client can run OAuth again. |
| `request_access_grant` | Request an access grant: time-boxed permission to run one read-only statement on one Bytebase database, optionally with results unmasked or exported. |
| `revoke_masking_exemption` | Remove one member's masking exemption in a Bytebase project. |
| `search_api` | Discover Bytebase API endpoints. |
| `set_just_in_time_access` | Turn just-in-time access on or off for one Bytebase project. |
<!-- tools:end -->

What each session may do is set on the instance: the signed-in user's permissions, narrowed by the workspace [MCP access policy](https://docs.bytebase.com/integrations/mcp#access-policy) (Disabled, Read-only, Read-write). Actions that need confirmation (approving an issue, granting a masking exemption) show a confirmation form in clients that support MCP elicitation; the package forwards the form to your client.

## How it works

1. On start, the server answers `initialize` and `tools/list` from the bundled definitions, so your client has the tool list at once, and so MCP directories can read it without an instance.
2. On the first `tools/call` (or in the background after `tools/list` when `BYTEBASE_URL` is set), it connects to `<BYTEBASE_URL>/mcp` over Streamable HTTP. If there is no valid token it runs the OAuth authorization-code flow with PKCE: discovery through `/.well-known/oauth-protected-resource/mcp`, dynamic client registration, browser sign-in, loopback redirect.
3. Tool calls, results and elicitation requests pass through unchanged. If the live tool list differs from the bundle, the server sends `tools/list_changed`.
1. With `BYTEBASE_URL` set, the server answers `initialize` at once. If you have signed in before, it opens a session first and passes on your instance's own instructions; otherwise it starts the browser sign-in, and announces your instance's tools with `tools/list_changed` once you have signed in.
2. It connects to `<BYTEBASE_URL>/mcp` over Streamable HTTP. With no valid token it runs the OAuth authorization-code flow with PKCE: discovery through `/.well-known/oauth-protected-resource/mcp`, dynamic client registration, browser sign-in, loopback redirect.
3. Tool lists, tool calls, results and confirmation forms pass through unchanged, paging included.
4. Without `BYTEBASE_URL`, the server lists the bundled snapshot so MCP directories can show Bytebase's tools, and every tool call says to set `BYTEBASE_URL`. A configured server never uses the snapshot.

Bytebase's refresh tokens are single-use and MCP clients start one process per session, so the token file is re-read before each refresh and written atomically.
The design, with every state the server can be in, is in [docs/DESIGN.md](docs/DESIGN.md).

## Development

Design notes for reviewers and maintainers: [docs/DESIGN.md](docs/DESIGN.md).

```bash
npm install
npm run build
npm test # unit + cold-start smoke tests, no instance needed
```

### Keeping the tool definitions in sync

`src/tools.json` is generated, never edited. Before each release, dump the tool list from an instance running the Bytebase version you want to ship with:

```bash
npm run build
BYTEBASE_URL=https://your-bytebase npm run sync-tools
```

The script signs in like the package does and prints what changed. Commit the result with the version bump.

### Releasing

```bash
npm version patch # bumps package.json and server.json together
git push origin main --follow-tags
```

A push to `main` that changes `package.json` runs [`npm-publish.yml`](.github/workflows/npm-publish.yml): it publishes to npm with OIDC provenance, then registers the version in the [MCP Registry](https://registry.modelcontextprotocol.io) with `mcp-publisher`. No tokens are stored in the repository.
Building, testing (against a local Bytebase and in a real client), keeping the tool snapshot current and releasing are covered in [CONTRIBUTING.md](CONTRIBUTING.md). The design is in [docs/DESIGN.md](docs/DESIGN.md).

## License

Expand Down
Loading
Loading