@atercates/bitbucket-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +347 -0
  3. package/dist/client.d.ts +16 -0
  4. package/dist/client.js +35 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/config.d.ts +11 -0
  7. package/dist/config.js +54 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/handlers/branching-model.d.ts +2 -0
  10. package/dist/handlers/branching-model.js +324 -0
  11. package/dist/handlers/branching-model.js.map +1 -0
  12. package/dist/handlers/commits.d.ts +2 -0
  13. package/dist/handlers/commits.js +78 -0
  14. package/dist/handlers/commits.js.map +1 -0
  15. package/dist/handlers/index.d.ts +17 -0
  16. package/dist/handlers/index.js +29 -0
  17. package/dist/handlers/index.js.map +1 -0
  18. package/dist/handlers/pipelines.d.ts +2 -0
  19. package/dist/handlers/pipelines.js +538 -0
  20. package/dist/handlers/pipelines.js.map +1 -0
  21. package/dist/handlers/pr-comments.d.ts +2 -0
  22. package/dist/handlers/pr-comments.js +509 -0
  23. package/dist/handlers/pr-comments.js.map +1 -0
  24. package/dist/handlers/pr-content.d.ts +2 -0
  25. package/dist/handlers/pr-content.js +332 -0
  26. package/dist/handlers/pr-content.js.map +1 -0
  27. package/dist/handlers/pr-tasks.d.ts +2 -0
  28. package/dist/handlers/pr-tasks.js +275 -0
  29. package/dist/handlers/pr-tasks.js.map +1 -0
  30. package/dist/handlers/pull-requests.d.ts +2 -0
  31. package/dist/handlers/pull-requests.js +902 -0
  32. package/dist/handlers/pull-requests.js.map +1 -0
  33. package/dist/handlers/refs.d.ts +2 -0
  34. package/dist/handlers/refs.js +225 -0
  35. package/dist/handlers/refs.js.map +1 -0
  36. package/dist/handlers/repositories.d.ts +2 -0
  37. package/dist/handlers/repositories.js +131 -0
  38. package/dist/handlers/repositories.js.map +1 -0
  39. package/dist/handlers/source.d.ts +2 -0
  40. package/dist/handlers/source.js +35 -0
  41. package/dist/handlers/source.js.map +1 -0
  42. package/dist/handlers/types.d.ts +42 -0
  43. package/dist/handlers/types.js +2 -0
  44. package/dist/handlers/types.js.map +1 -0
  45. package/dist/handlers/users.d.ts +2 -0
  46. package/dist/handlers/users.js +38 -0
  47. package/dist/handlers/users.js.map +1 -0
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.js +4 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/logger.d.ts +3 -0
  52. package/dist/logger.js +60 -0
  53. package/dist/logger.js.map +1 -0
  54. package/dist/pagination.d.ts +32 -0
  55. package/dist/pagination.js +116 -0
  56. package/dist/pagination.js.map +1 -0
  57. package/dist/schemas.d.ts +21 -0
  58. package/dist/schemas.js +23 -0
  59. package/dist/schemas.js.map +1 -0
  60. package/dist/server.d.ts +33 -0
  61. package/dist/server.js +124 -0
  62. package/dist/server.js.map +1 -0
  63. package/dist/types.d.ts +296 -0
  64. package/dist/types.js +3 -0
  65. package/dist/types.js.map +1 -0
  66. package/dist/utils.d.ts +18 -0
  67. package/dist/utils.js +17 -0
  68. package/dist/utils.js.map +1 -0
  69. package/docs/README.md +216 -0
  70. package/docs/TOOLS.md +464 -0
  71. package/docs/architecture/ARCHITECTURE.md +302 -0
  72. package/docs/guides/ENVIRONMENT_VARIABLES.md +306 -0
  73. package/docs/guides/GETTING_STARTED.md +267 -0
  74. package/docs/guides/GITHUB_ACTIONS_SETUP.md +148 -0
  75. package/docs/guides/NPM_DEPLOYMENT.md +266 -0
  76. package/docs/guides/PROJECT_STRUCTURE.md +317 -0
  77. package/package.json +84 -0
@@ -0,0 +1,302 @@
1
+ # Architecture Overview
2
+
3
+ This document describes the architecture of the Bitbucket MCP server.
4
+
5
+ ## High-Level Overview
6
+
7
+ The Bitbucket MCP server is a Model Context Protocol (MCP) implementation that provides programmatic access to Bitbucket Cloud and Server APIs. It's designed as a modular, maintainable system that separates concerns by feature domain.
8
+
9
+ ```
10
+ ┌─────────────────────────────────────────┐
11
+ │ MCP Client (e.g., Cursor, Claude) │
12
+ └──────────────┬──────────────────────────┘
13
+ │ stdio/HTTP
14
+
15
+ ┌──────────────────────────────────────────┐
16
+ │ BitbucketMcpServer (src/server.ts) │
17
+ │ - Tool Registration │
18
+ │ - Request Routing │
19
+ │ - MCP Protocol Handling │
20
+ └──────────────┬───────────────────────────┘
21
+
22
+ ┌──────▼──────────────────────────┐
23
+ │ Handler Modules (/handlers/) │
24
+ ├─────────────────────────────────┤
25
+ │ • repositories.ts │
26
+ │ • pull-requests.ts │
27
+ │ • pr-comments.ts │
28
+ │ • pr-tasks.ts │
29
+ │ • pr-content.ts │
30
+ │ • pipelines.ts │
31
+ │ • refs.ts (branches/tags) │
32
+ │ • commits.ts │
33
+ │ • source.ts │
34
+ │ • users.ts │
35
+ │ • branching-model.ts │
36
+ └──────┬───────────────────────────┘
37
+
38
+ ┌──────────┴──────────────┐
39
+ ▼ ▼
40
+ ┌──────────────────┐ ┌──────────────────┐
41
+ │ BitbucketClient │ │ Logger │
42
+ │ (src/client.ts) │ │ (src/logger.ts) │
43
+ │ │ │ │
44
+ │ • API wrapper │ │ • File-based │
45
+ │ • Auth handling │ │ logging │
46
+ │ • URL normaliz. │ │ • Platform-aware │
47
+ │ • Pagination │ │ │
48
+ └────────┬─────────┘ └──────────────────┘
49
+
50
+
51
+ ┌─────────────────┐
52
+ │ Bitbucket API │
53
+ │ (api.bitbucket) │
54
+ └─────────────────┘
55
+ ```
56
+
57
+ ## Core Components
58
+
59
+ ### 1. Entry Point (`src/index.ts`)
60
+ - Minimal entry point that initializes the server
61
+ - Starts stdio transport for MCP communication
62
+ - Handles process lifecycle
63
+
64
+ ### 2. Server (`src/server.ts`)
65
+ The core orchestrator that:
66
+ - Manages MCP protocol events
67
+ - Dynamically registers tools from handler modules
68
+ - Routes tool calls to appropriate handlers
69
+ - Handles errors and response formatting
70
+
71
+ **Key Responsibilities:**
72
+ - `initializeListTools()`: Collects tools from all modules
73
+ - `handleCallTool()`: Routes calls to correct handler
74
+ - Security checks for dangerous tools
75
+
76
+ ### 3. Handler Modules (`src/handlers/`)
77
+ Each handler module follows the `HandlerModule` interface:
78
+
79
+ ```typescript
80
+ interface HandlerModule {
81
+ tools: Tool[];
82
+ dangerousTools?: string[];
83
+ createHandlers: (client: BitbucketClient) => Record<string, Handler>;
84
+ }
85
+ ```
86
+
87
+ **Module Pattern:**
88
+ - **tools**: Defines tool schemas (names, descriptions, input schemas)
89
+ - **dangerousTools**: Lists tools requiring `BITBUCKET_ALLOW_DANGEROUS`
90
+ - **createHandlers**: Factory function that returns handler implementations
91
+
92
+ **Example Structure:**
93
+ ```
94
+ repositories.ts
95
+ └─ tools: [
96
+ { name: "listRepositories", ... },
97
+ { name: "getRepository", ... },
98
+ { name: "createRepository", ... }
99
+ ]
100
+ └─ createHandlers: (client) => ({
101
+ listRepositories: async (args) => { ... },
102
+ getRepository: async (args) => { ... },
103
+ createRepository: async (args) => { ... }
104
+ })
105
+ ```
106
+
107
+ ### 4. BitbucketClient (`src/client.ts`)
108
+ Encapsulates all Bitbucket API interactions:
109
+
110
+ **Key Features:**
111
+ - **Authentication**: Supports token or username/password auth
112
+ - **URL Normalization**: Converts web URLs to API URLs
113
+ - **HTTP Client**: Axios instance with proper headers
114
+ - **Pagination**: Built-in paginator for large datasets
115
+ - **Error Handling**: Consistent error messages
116
+
117
+ **Methods:**
118
+ - `resolveWorkspace()`: Gets workspace from cache or args
119
+ - `api`: Direct Axios access for API calls
120
+ - `paginator`: Pagination helper
121
+
122
+ ### 5. Configuration (`src/config.ts`)
123
+ Centralized environment variable management:
124
+
125
+ **Environment Variables:**
126
+ - `BITBUCKET_URL`: API base URL (default: https://api.bitbucket.org/2.0)
127
+ - `BITBUCKET_TOKEN`: Authentication token
128
+ - `BITBUCKET_USERNAME`: For basic auth
129
+ - `BITBUCKET_PASSWORD`: For basic auth
130
+ - `BITBUCKET_WORKSPACE`: Default workspace
131
+ - `BITBUCKET_ALLOW_DANGEROUS`: Enable dangerous operations
132
+ - `BITBUCKET_LOG_*`: Logging configuration
133
+
134
+ ### 6. Logger (`src/logger.ts`)
135
+ File-based logging using Winston:
136
+
137
+ **Features:**
138
+ - Platform-aware log directory selection
139
+ - Structured JSON logging
140
+ - Per-CWD logging option
141
+ - Disableable via environment variable
142
+
143
+ **Log Locations:**
144
+ - macOS: `~/Library/Logs/bitbucket-mcp/`
145
+ - Windows: `%LOCALAPPDATA%/bitbucket-mcp/`
146
+ - Linux: `~/.local/state/bitbucket-mcp/` or `$XDG_STATE_HOME/bitbucket-mcp/`
147
+
148
+ ### 7. Utilities (`src/utils.ts`)
149
+ Response formatting helpers:
150
+
151
+ - `jsonResponse()`: Wrap JSON in MCP response format
152
+ - `textResponse()`: Wrap text in MCP response format
153
+
154
+ ### 8. Types (`src/types.ts`)
155
+ Complete TypeScript definitions for:
156
+ - Bitbucket API entities
157
+ - MCP request/response types
158
+ - Handler function signatures
159
+
160
+ ### 9. Schemas (`src/schemas.ts`)
161
+ JSON Schema definitions for tool inputs:
162
+ - Pagination parameters
163
+ - Common field definitions
164
+ - Reusable schema fragments
165
+
166
+ ### 10. Pagination (`src/pagination.ts`)
167
+ BitbucketPaginator class for handling paginated API responses:
168
+
169
+ **Features:**
170
+ - Automatic pagination following `next` links
171
+ - Configurable page size limits
172
+ - All-items mode with safety caps
173
+
174
+ ## Data Flow
175
+
176
+ ### Typical Request Flow
177
+
178
+ ```
179
+ 1. Client calls tool via MCP
180
+ Example: { name: "listRepositories", arguments: { workspace: "my-ws" } }
181
+
182
+ 2. MCP Server receives request in server.ts
183
+ └─ handleCallTool() method
184
+
185
+ 3. Server routes to handler module
186
+ └─ Finds correct handler in pull-requests.ts, repositories.ts, etc.
187
+
188
+ 4. Handler extracts parameters and validates
189
+ └─ Resolves workspace from config/args
190
+
191
+ 5. Handler calls BitbucketClient
192
+ └─ client.api.get() or client.paginator.fetchValues()
193
+
194
+ 6. BitbucketClient hits Bitbucket API
195
+ └─ With proper auth headers and error handling
196
+
197
+ 7. Response is formatted
198
+ └─ JSON or text response wrapping
199
+
200
+ 8. MCP Server sends back to client
201
+ └─ { content: [{ type: "text", text: "..." }] }
202
+ ```
203
+
204
+ ## Security
205
+
206
+ ### Dangerous Tools Gating
207
+
208
+ Some operations (delete, remove) are marked dangerous and require explicit enablement:
209
+
210
+ ```typescript
211
+ // In handler module
212
+ dangerousTools: ["deleteBranch", "deleteTag"]
213
+
214
+ // In server.ts - gates execution
215
+ if (isDangerous && !isDangerousAllowed) {
216
+ throw error("BITBUCKET_ALLOW_DANGEROUS not set");
217
+ }
218
+ ```
219
+
220
+ ### Authentication
221
+
222
+ Two supported methods (checked in order):
223
+ 1. **Token Auth**: `BITBUCKET_TOKEN` (preferred)
224
+ 2. **Basic Auth**: `BITBUCKET_USERNAME` + `BITBUCKET_PASSWORD`
225
+
226
+ Both are passed to Axios as Authorization headers.
227
+
228
+ ## Testing
229
+
230
+ The project uses Vitest with:
231
+ - Mock BitbucketClient for unit tests
232
+ - Mock Axios instance
233
+ - Handler-by-handler tests
234
+ - Edge case coverage
235
+
236
+ **Test Structure:**
237
+ ```
238
+ __tests__/
239
+ ├─ test-utils.ts (Mock helpers)
240
+ └─ handlers/
241
+ ├─ repositories.test.ts
242
+ ├─ pull-requests.test.ts
243
+ └─ ... (one per handler)
244
+ ```
245
+
246
+ ## Build System
247
+
248
+ - **TypeScript**: Compiles to ES2020 with strict mode
249
+ - **Module System**: ESM (type: "module")
250
+ - **Entry Point**: `dist/index.js` (executable with shebang)
251
+ - **Linting**: ESLint with flat config
252
+ - **Formatting**: Prettier
253
+ - **Testing**: Vitest
254
+
255
+ ## Extension Pattern
256
+
257
+ To add new functionality:
258
+
259
+ 1. **Create a handler module** `src/handlers/new-feature.ts`:
260
+ ```typescript
261
+ export const newFeatureModule: HandlerModule = {
262
+ tools: [{ name: "...", ... }],
263
+ createHandlers: (client) => ({
264
+ toolName: async (args) => { ... }
265
+ })
266
+ };
267
+ ```
268
+
269
+ 2. **Register in** `src/handlers/index.ts`:
270
+ ```typescript
271
+ export const allModules = [
272
+ repositoriesModule,
273
+ newFeatureModule, // Add here
274
+ // ...
275
+ ];
276
+ ```
277
+
278
+ 3. **The server will automatically pick it up** - no additional wiring needed!
279
+
280
+ ## Performance Considerations
281
+
282
+ - **Pagination**: Large datasets are paginated by default (100 items/page max)
283
+ - **Lazy Loading**: Handlers only loaded when server starts
284
+ - **Streaming**: Responses returned as-is without buffering
285
+ - **Caching**: Workspace resolution cached per session
286
+
287
+ ## Error Handling
288
+
289
+ All handlers use consistent error handling:
290
+
291
+ ```typescript
292
+ try {
293
+ // API call
294
+ return jsonResponse(data);
295
+ } catch (error) {
296
+ logger.error("Operation failed", { error, context });
297
+ throw new McpError(
298
+ ErrorCode.InternalError,
299
+ `Descriptive message: ${error.message}`
300
+ );
301
+ }
302
+ ```
@@ -0,0 +1,306 @@
1
+ # Environment Variables Reference
2
+
3
+ Complete list of environment variables needed to configure and deploy the Bitbucket MCP server.
4
+
5
+ ## Authentication (Required - Select One)
6
+
7
+ ### Token Authentication (Recommended)
8
+
9
+ ```bash
10
+ # App password from Bitbucket
11
+ BITBUCKET_TOKEN=your_app_password_here
12
+ ```
13
+
14
+ **How to get:**
15
+ 1. Go to https://bitbucket.org/account/settings/app-passwords/
16
+ 2. Click "Create app password"
17
+ 3. Select permissions: Pipelines:Read, Repositories:Read+Write, Pull requests:Read+Write
18
+ 4. Copy the generated password
19
+
20
+ ### Basic Authentication
21
+
22
+ ```bash
23
+ # Email and app password
24
+ BITBUCKET_USERNAME=your_email@example.com
25
+ BITBUCKET_PASSWORD=your_app_password_here
26
+ ```
27
+
28
+ ## Server Configuration (Optional)
29
+
30
+ ```bash
31
+ # API base URL (defaults to Bitbucket Cloud)
32
+ BITBUCKET_URL=https://api.bitbucket.org/2.0
33
+
34
+ # For self-hosted Bitbucket Server:
35
+ BITBUCKET_URL=https://bitbucket.mycompany.com/rest/api/2.0
36
+
37
+ # Default workspace (auto-extracted if not set)
38
+ BITBUCKET_WORKSPACE=my-workspace
39
+
40
+ # Allow dangerous operations (delete branch, delete tag, etc.)
41
+ BITBUCKET_ALLOW_DANGEROUS=true # default: false
42
+ ```
43
+
44
+ ## Logging Configuration (Optional)
45
+
46
+ ```bash
47
+ # Disable file-based logging
48
+ BITBUCKET_LOG_DISABLE=true
49
+
50
+ # Custom log file path
51
+ BITBUCKET_LOG_FILE=/var/log/bitbucket-mcp/server.log
52
+
53
+ # Custom log directory
54
+ BITBUCKET_LOG_DIR=/var/log/bitbucket-mcp
55
+
56
+ # Create per-working-directory subdirectories
57
+ BITBUCKET_LOG_PER_CWD=true
58
+ ```
59
+
60
+ ## NPM Publishing (Deployment)
61
+
62
+ ### Local Deployment
63
+
64
+ ```bash
65
+ # npm account credentials
66
+ # These are configured via: npm login
67
+ # Stored in: ~/.npmrc (do NOT commit)
68
+ ```
69
+
70
+ ### CI/CD Deployment (GitHub Actions, etc.)
71
+
72
+ ```bash
73
+ # npm access token for automation
74
+ NPM_TOKEN=npm_your_token_here_1234567890
75
+
76
+ # or use npm credentials
77
+ NPM_USERNAME=your_npm_username
78
+ NPM_PASSWORD=your_npm_password
79
+ NPM_EMAIL=your_email@example.com
80
+ ```
81
+
82
+ **How to get NPM_TOKEN:**
83
+ 1. Go to https://www.npmjs.com/settings/~/tokens
84
+ 2. Click "Generate New Token"
85
+ 3. Select type: "Automation" (for CI/CD)
86
+ 4. Copy the token
87
+ 5. Add to GitHub Secrets as `NPM_TOKEN`
88
+
89
+ ## Development Environment
90
+
91
+ ```bash
92
+ # Development mode (use tsx watch)
93
+ NODE_ENV=development
94
+ pnpm dev
95
+
96
+ # Production build
97
+ NODE_ENV=production
98
+ pnpm build
99
+ pnpm start
100
+ ```
101
+
102
+ ## Complete Example: Local Setup
103
+
104
+ ```bash
105
+ # Step 1: Create app password on Bitbucket
106
+ # Go to https://bitbucket.org/account/settings/app-passwords/
107
+
108
+ # Step 2: Set environment variables
109
+ export BITBUCKET_TOKEN="your_app_password"
110
+ export BITBUCKET_WORKSPACE="my-workspace"
111
+
112
+ # Optional: Enable logging
113
+ export BITBUCKET_LOG_DISABLE=false
114
+
115
+ # Optional: Allow dangerous operations
116
+ export BITBUCKET_ALLOW_DANGEROUS=true
117
+
118
+ # Step 3: Run the server
119
+ pnpm start
120
+ # OR
121
+ npx -y bitbucket-mcp@latest
122
+ ```
123
+
124
+ ## Complete Example: Docker Deployment
125
+
126
+ ```dockerfile
127
+ FROM node:18-alpine
128
+ WORKDIR /app
129
+ COPY . .
130
+ RUN pnpm install && pnpm build
131
+
132
+ ENV BITBUCKET_TOKEN=${BITBUCKET_TOKEN}
133
+ ENV BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE}
134
+ ENV BITBUCKET_LOG_DISABLE=false
135
+ ENV BITBUCKET_ALLOW_DANGEROUS=${BITBUCKET_ALLOW_DANGEROUS:-false}
136
+
137
+ CMD ["node", "dist/index.js"]
138
+ ```
139
+
140
+ ```bash
141
+ # Run Docker container
142
+ docker run -e BITBUCKET_TOKEN=your_token \
143
+ -e BITBUCKET_WORKSPACE=my-workspace \
144
+ bitbucket-mcp:latest
145
+ ```
146
+
147
+ ## Complete Example: GitHub Actions Workflow
148
+
149
+ ```yaml
150
+ name: Deploy to npm
151
+
152
+ on:
153
+ push:
154
+ tags:
155
+ - 'v*'
156
+
157
+ jobs:
158
+ publish:
159
+ runs-on: ubuntu-latest
160
+ steps:
161
+ - uses: actions/checkout@v3
162
+
163
+ - uses: pnpm/action-setup@v2
164
+ with:
165
+ version: 8
166
+
167
+ - uses: actions/setup-node@v3
168
+ with:
169
+ node-version: '18'
170
+ registry-url: 'https://registry.npmjs.org'
171
+ cache: 'pnpm'
172
+
173
+ - run: pnpm install
174
+ - run: pnpm build
175
+ - run: pnpm test
176
+ - run: pnpm publish
177
+ env:
178
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
179
+ ```
180
+
181
+ **GitHub Secrets to configure:**
182
+ - `NPM_TOKEN`: npm automation token
183
+
184
+ ## Configuration by Environment
185
+
186
+ ### Development
187
+
188
+ ```bash
189
+ BITBUCKET_TOKEN=dev_token
190
+ BITBUCKET_WORKSPACE=dev-workspace
191
+ BITBUCKET_LOG_DISABLE=false
192
+ BITBUCKET_ALLOW_DANGEROUS=true
193
+ NODE_ENV=development
194
+ ```
195
+
196
+ ### Staging
197
+
198
+ ```bash
199
+ BITBUCKET_TOKEN=staging_token
200
+ BITBUCKET_WORKSPACE=staging-workspace
201
+ BITBUCKET_LOG_DISABLE=false
202
+ BITBUCKET_ALLOW_DANGEROUS=false
203
+ NODE_ENV=production
204
+ ```
205
+
206
+ ### Production
207
+
208
+ ```bash
209
+ BITBUCKET_TOKEN=${BITBUCKET_TOKEN}
210
+ BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE}
211
+ BITBUCKET_LOG_DISABLE=false
212
+ BITBUCKET_ALLOW_DANGEROUS=false
213
+ NODE_ENV=production
214
+ ```
215
+
216
+ ## Environment Variable Priority
217
+
218
+ When multiple configuration sources exist, priority is:
219
+
220
+ 1. **Command-line environment variables** (highest)
221
+ ```bash
222
+ BITBUCKET_TOKEN=value pnpm start
223
+ ```
224
+
225
+ 2. **.env file in current directory**
226
+ ```bash
227
+ # .env
228
+ BITBUCKET_TOKEN=value
229
+ ```
230
+
231
+ 3. **.env.local file** (for local overrides)
232
+ ```bash
233
+ # .env.local (in .gitignore)
234
+ BITBUCKET_TOKEN=local_value
235
+ ```
236
+
237
+ 4. **System environment variables**
238
+ ```bash
239
+ export BITBUCKET_TOKEN=value
240
+ ```
241
+
242
+ 5. **Default values** (lowest, if any)
243
+
244
+ ## Security Best Practices
245
+
246
+ 1. **Never commit secrets**
247
+ - Add `.env` and `.env.local` to `.gitignore`
248
+ - Store tokens in environment or secret management
249
+
250
+ 2. **Use strong tokens**
251
+ - Use app passwords with minimal required scopes
252
+ - Rotate tokens regularly
253
+
254
+ 3. **Enable 2FA on npm account**
255
+ - https://docs.npmjs.com/about-two-factor-authentication
256
+
257
+ 4. **Use specific npm tokens for CI/CD**
258
+ - Create automation tokens instead of personal tokens
259
+ - Restrict token scope to "publish"
260
+
261
+ 5. **Disable dangerous operations in production**
262
+ - Only set `BITBUCKET_ALLOW_DANGEROUS=true` in development
263
+ - This prevents accidental data loss
264
+
265
+ ## Troubleshooting
266
+
267
+ ### "Invalid credentials" error
268
+
269
+ ```bash
270
+ # Verify token is set
271
+ echo $BITBUCKET_TOKEN
272
+
273
+ # Test credentials
274
+ curl -X GET https://api.bitbucket.org/2.0/user \
275
+ -H "Authorization: Bearer $BITBUCKET_TOKEN"
276
+ ```
277
+
278
+ ### "Workspace not found"
279
+
280
+ ```bash
281
+ # Verify workspace name
282
+ echo $BITBUCKET_WORKSPACE
283
+
284
+ # List your workspaces
285
+ curl -X GET https://api.bitbucket.org/2.0/workspaces \
286
+ -H "Authorization: Bearer $BITBUCKET_TOKEN"
287
+ ```
288
+
289
+ ### npm publish fails with "ENEEDAUTH"
290
+
291
+ ```bash
292
+ # Check npm login
293
+ npm whoami
294
+
295
+ # Login again
296
+ npm login
297
+
298
+ # Or use token directly
299
+ echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
300
+ ```
301
+
302
+ ## See Also
303
+
304
+ - [Getting Started Guide](GETTING_STARTED.md)
305
+ - [NPM Deployment Guide](NPM_DEPLOYMENT.md)
306
+ - [Architecture Documentation](../architecture/ARCHITECTURE.md)