@zhanglc77/bitbucket-mcp-server 1.0.1

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 (56) hide show
  1. package/CHANGELOG.md +280 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1090 -0
  4. package/build/handlers/branch-handlers.d.ts +55 -0
  5. package/build/handlers/branch-handlers.d.ts.map +1 -0
  6. package/build/handlers/branch-handlers.js +522 -0
  7. package/build/handlers/branch-handlers.js.map +1 -0
  8. package/build/handlers/file-handlers.d.ts +33 -0
  9. package/build/handlers/file-handlers.d.ts.map +1 -0
  10. package/build/handlers/file-handlers.js +308 -0
  11. package/build/handlers/file-handlers.js.map +1 -0
  12. package/build/handlers/pull-request-handlers.d.ts +101 -0
  13. package/build/handlers/pull-request-handlers.d.ts.map +1 -0
  14. package/build/handlers/pull-request-handlers.js +955 -0
  15. package/build/handlers/pull-request-handlers.js.map +1 -0
  16. package/build/handlers/review-handlers.d.ts +67 -0
  17. package/build/handlers/review-handlers.d.ts.map +1 -0
  18. package/build/handlers/review-handlers.js +252 -0
  19. package/build/handlers/review-handlers.js.map +1 -0
  20. package/build/handlers/search-handlers.d.ts +20 -0
  21. package/build/handlers/search-handlers.d.ts.map +1 -0
  22. package/build/handlers/search-handlers.js +151 -0
  23. package/build/handlers/search-handlers.js.map +1 -0
  24. package/build/index.d.ts +3 -0
  25. package/build/index.d.ts.map +1 -0
  26. package/build/index.js +120 -0
  27. package/build/index.js.map +1 -0
  28. package/build/tools/definitions.d.ts +1191 -0
  29. package/build/tools/definitions.d.ts.map +1 -0
  30. package/build/tools/definitions.js +655 -0
  31. package/build/tools/definitions.js.map +1 -0
  32. package/build/types/bitbucket.d.ts +483 -0
  33. package/build/types/bitbucket.d.ts.map +1 -0
  34. package/build/types/bitbucket.js +2 -0
  35. package/build/types/bitbucket.js.map +1 -0
  36. package/build/types/guards.d.ts +140 -0
  37. package/build/types/guards.d.ts.map +1 -0
  38. package/build/types/guards.js +140 -0
  39. package/build/types/guards.js.map +1 -0
  40. package/build/utils/api-client.d.ts +22 -0
  41. package/build/utils/api-client.d.ts.map +1 -0
  42. package/build/utils/api-client.js +111 -0
  43. package/build/utils/api-client.js.map +1 -0
  44. package/build/utils/diff-parser.d.ts +42 -0
  45. package/build/utils/diff-parser.d.ts.map +1 -0
  46. package/build/utils/diff-parser.js +165 -0
  47. package/build/utils/diff-parser.js.map +1 -0
  48. package/build/utils/formatters.d.ts +8 -0
  49. package/build/utils/formatters.d.ts.map +1 -0
  50. package/build/utils/formatters.js +207 -0
  51. package/build/utils/formatters.js.map +1 -0
  52. package/build/utils/suggestion-formatter.d.ts +6 -0
  53. package/build/utils/suggestion-formatter.d.ts.map +1 -0
  54. package/build/utils/suggestion-formatter.js +17 -0
  55. package/build/utils/suggestion-formatter.js.map +1 -0
  56. package/package.json +55 -0
package/README.md ADDED
@@ -0,0 +1,1090 @@
1
+ # Bitbucket MCP Server
2
+
3
+ [![npm version](https://badge.fury.io/js/@nexus2520%2Fbitbucket-mcp-server.svg)](https://www.npmjs.com/package/@nexus2520/bitbucket-mcp-server)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ An MCP (Model Context Protocol) server that provides tools for interacting with the Bitbucket API, supporting both Bitbucket Cloud and Bitbucket Server.
7
+
8
+ ## Features
9
+
10
+ ### Currently Implemented Tools
11
+
12
+ #### Core PR Lifecycle Tools
13
+ - `get_pull_request` - Retrieve detailed information about a pull request
14
+ - `list_pull_requests` - List pull requests with filters (state, author, pagination)
15
+ - `create_pull_request` - Create new pull requests
16
+ - `update_pull_request` - Update PR details (title, description, reviewers, destination branch)
17
+ - `add_comment` - Add comments to pull requests (supports replies)
18
+ - `merge_pull_request` - Merge pull requests with various strategies
19
+ - `list_pr_commits` - List all commits that are part of a pull request
20
+ - `delete_branch` - Delete branches after merge
21
+
22
+ #### Branch Management Tools
23
+ - `list_branches` - List branches with filtering and pagination
24
+ - `delete_branch` - Delete branches (with protection checks)
25
+ - `get_branch` - Get detailed branch information including associated PRs
26
+ - `list_branch_commits` - List commits in a branch with advanced filtering
27
+
28
+ #### File and Directory Tools
29
+ - `list_directory_content` - List files and directories in a repository path
30
+ - `get_file_content` - Get file content with smart truncation for large files
31
+
32
+ #### Code Review Tools
33
+ - `get_pull_request_diff` - Get the diff/changes for a pull request
34
+ - `approve_pull_request` - Approve a pull request
35
+ - `unapprove_pull_request` - Remove approval from a pull request
36
+ - `request_changes` - Request changes on a pull request
37
+ - `remove_requested_changes` - Remove change request from a pull request
38
+
39
+ #### Search Tools
40
+ - `search_code` - Search for code across repositories (currently Bitbucket Server only)
41
+
42
+ ## Installation
43
+
44
+ ### Using npx (Recommended)
45
+
46
+ The easiest way to use this MCP server is directly with npx:
47
+
48
+ ```json
49
+ {
50
+ "mcpServers": {
51
+ "bitbucket": {
52
+ "command": "npx",
53
+ "args": [
54
+ "-y",
55
+ "@nexus2520/bitbucket-mcp-server"
56
+ ],
57
+ "env": {
58
+ "BITBUCKET_USERNAME": "your-username",
59
+ "BITBUCKET_APP_PASSWORD": "your-app-password"
60
+ }
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ For Bitbucket Server:
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "bitbucket": {
71
+ "command": "npx",
72
+ "args": [
73
+ "-y",
74
+ "@nexus2520/bitbucket-mcp-server"
75
+ ],
76
+ "env": {
77
+ "BITBUCKET_USERNAME": "your.email@company.com",
78
+ "BITBUCKET_TOKEN": "your-http-access-token",
79
+ "BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ### From Source
87
+
88
+ 1. Clone or download this repository
89
+ 2. Install dependencies:
90
+ ```bash
91
+ npm install
92
+ ```
93
+ 3. Build the TypeScript code:
94
+ ```bash
95
+ npm run build
96
+ ```
97
+
98
+ ## Authentication Setup
99
+
100
+ This server uses Bitbucket App Passwords for authentication.
101
+
102
+ ### Creating an App Password
103
+
104
+ 1. Log in to your Bitbucket account
105
+ 2. Navigate to: https://bitbucket.org/account/settings/app-passwords/
106
+ 3. Click "Create app password"
107
+ 4. Give it a descriptive label (e.g., "MCP Server")
108
+ 5. Select the following permissions:
109
+ - **Account**: Read
110
+ - **Repositories**: Read, Write
111
+ - **Pull requests**: Read, Write
112
+ 6. Click "Create"
113
+ 7. **Important**: Copy the generated password immediately (you won't be able to see it again!)
114
+
115
+ ### Running the Setup Script
116
+
117
+ ```bash
118
+ node scripts/setup-auth.js
119
+ ```
120
+
121
+ This will guide you through the authentication setup process.
122
+
123
+ ## Configuration
124
+
125
+ Add the server to your MCP settings file (usually located at `~/.vscode-server/data/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`):
126
+
127
+ ```json
128
+ {
129
+ "mcpServers": {
130
+ "bitbucket": {
131
+ "command": "node",
132
+ "args": ["/absolute/path/to/bitbucket-mcp-server/build/index.js"],
133
+ "env": {
134
+ "BITBUCKET_USERNAME": "your-username",
135
+ "BITBUCKET_APP_PASSWORD": "your-app-password"
136
+ }
137
+ }
138
+ }
139
+ }
140
+ ```
141
+
142
+ Replace:
143
+ - `/absolute/path/to/bitbucket-mcp-server` with the actual path to this directory
144
+ - `your-username` with your Bitbucket username (not email)
145
+ - `your-app-password` with the app password you created
146
+
147
+ For Bitbucket Server, use:
148
+ ```json
149
+ {
150
+ "mcpServers": {
151
+ "bitbucket": {
152
+ "command": "node",
153
+ "args": ["/absolute/path/to/bitbucket-mcp-server/build/index.js"],
154
+ "env": {
155
+ "BITBUCKET_USERNAME": "your.email@company.com",
156
+ "BITBUCKET_TOKEN": "your-http-access-token",
157
+ "BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
158
+ }
159
+ }
160
+ }
161
+ }
162
+ ```
163
+
164
+ **Important for Bitbucket Server users:**
165
+ - Use your full email address as the username (e.g., "john.doe@company.com")
166
+ - This is required for approval/review actions to work correctly
167
+
168
+ ## Usage
169
+
170
+ Once configured, you can use the available tools:
171
+
172
+ ### Get Pull Request
173
+
174
+ ```typescript
175
+ {
176
+ "tool": "get_pull_request",
177
+ "arguments": {
178
+ "workspace": "PROJ", // Required - your project key
179
+ "repository": "my-repo",
180
+ "pull_request_id": 123
181
+ }
182
+ }
183
+ ```
184
+
185
+ Returns detailed information about the pull request including:
186
+ - Title and description
187
+ - Author and reviewers
188
+ - Source and destination branches
189
+ - Approval status
190
+ - Links to web UI and diff
191
+ - **Merge commit details** (when PR is merged):
192
+ - `merge_commit_hash`: The hash of the merge commit
193
+ - `merged_by`: Who performed the merge
194
+ - `merged_at`: When the merge occurred
195
+ - `merge_commit_message`: The merge commit message
196
+ - **Active comments with nested replies** (unresolved comments that need attention):
197
+ - `active_comments`: Array of active comments (up to 20 most recent top-level comments)
198
+ - Comment text and author
199
+ - Creation date
200
+ - Whether it's an inline comment (with file path and line number)
201
+ - **Nested replies** (for Bitbucket Server):
202
+ - `replies`: Array of reply comments with same structure
203
+ - Replies can be nested multiple levels deep
204
+ - **Parent reference** (for Bitbucket Cloud):
205
+ - `parent_id`: ID of the parent comment for replies
206
+ - `active_comment_count`: Total count of unresolved comments (including nested replies)
207
+ - `total_comment_count`: Total count of all comments (including resolved and replies)
208
+ - **File changes**:
209
+ - `file_changes`: Array of all files modified in the PR
210
+ - File path
211
+ - Status (added, modified, removed, or renamed)
212
+ - Old path (for renamed files)
213
+ - `file_changes_summary`: Summary statistics
214
+ - Total files changed
215
+ - And more...
216
+
217
+ ### Search Code
218
+
219
+ Search for code across Bitbucket repositories (currently only supported for Bitbucket Server):
220
+
221
+ ```typescript
222
+ // Search in a specific repository
223
+ {
224
+ "tool": "search_code",
225
+ "arguments": {
226
+ "workspace": "PROJ",
227
+ "repository": "my-repo",
228
+ "search_query": "TODO",
229
+ "limit": 50
230
+ }
231
+ }
232
+
233
+ // Search across all repositories in a workspace
234
+ {
235
+ "tool": "search_code",
236
+ "arguments": {
237
+ "workspace": "PROJ",
238
+ "search_query": "deprecated",
239
+ "file_pattern": "*.java", // Optional: filter by file pattern
240
+ "limit": 100
241
+ }
242
+ }
243
+
244
+ // Search with file pattern filtering
245
+ {
246
+ "tool": "search_code",
247
+ "arguments": {
248
+ "workspace": "PROJ",
249
+ "repository": "frontend-app",
250
+ "search_query": "useState",
251
+ "file_pattern": "*.tsx", // Only search in .tsx files
252
+ "start": 0,
253
+ "limit": 25
254
+ }
255
+ }
256
+ ```
257
+
258
+ Returns search results with:
259
+ - File path and name
260
+ - Repository and project information
261
+ - Matched lines with:
262
+ - Line number
263
+ - Full line content
264
+ - Highlighted segments showing exact matches
265
+ - Pagination information
266
+
267
+ Example response:
268
+ ```json
269
+ {
270
+ "message": "Code search completed successfully",
271
+ "workspace": "PROJ",
272
+ "repository": "my-repo",
273
+ "search_query": "TODO",
274
+ "results": [
275
+ {
276
+ "file_path": "src/utils/helper.js",
277
+ "file_name": "helper.js",
278
+ "repository": "my-repo",
279
+ "project": "PROJ",
280
+ "matches": [
281
+ {
282
+ "line_number": 42,
283
+ "line_content": " // TODO: Implement error handling",
284
+ "highlighted_segments": [
285
+ { "text": " // ", "is_match": false },
286
+ { "text": "TODO", "is_match": true },
287
+ { "text": ": Implement error handling", "is_match": false }
288
+ ]
289
+ }
290
+ ]
291
+ }
292
+ ],
293
+ "total_count": 15,
294
+ "start": 0,
295
+ "limit": 50,
296
+ "has_more": false
297
+ }
298
+ ```
299
+
300
+ **Note**: This tool currently only works with Bitbucket Server. Bitbucket Cloud support is planned for a future release.
301
+
302
+ ### List Pull Requests
303
+
304
+ ```typescript
305
+ {
306
+ "tool": "list_pull_requests",
307
+ "arguments": {
308
+ "workspace": "PROJ", // Required - your project key
309
+ "repository": "my-repo",
310
+ "state": "OPEN", // Optional: OPEN, MERGED, DECLINED, ALL (default: OPEN)
311
+ "author": "username", // Optional: filter by author (see note below)
312
+ "limit": 25, // Optional: max results per page (default: 25)
313
+ "start": 0 // Optional: pagination start index (default: 0)
314
+ }
315
+ }
316
+ ```
317
+
318
+ Returns a paginated list of pull requests with:
319
+ - Array of pull requests with same details as get_pull_request
320
+ - Total count of matching PRs
321
+ - Pagination info (has_more, next_start)
322
+
323
+ **Note on Author Filter:**
324
+ - For Bitbucket Cloud: Use the username (e.g., "johndoe")
325
+ - For Bitbucket Server: Use the full email address (e.g., "john.doe@company.com")
326
+
327
+ ### Create Pull Request
328
+
329
+ ```typescript
330
+ {
331
+ "tool": "create_pull_request",
332
+ "arguments": {
333
+ "workspace": "PROJ",
334
+ "repository": "my-repo",
335
+ "title": "Add new feature",
336
+ "source_branch": "feature/new-feature",
337
+ "destination_branch": "main",
338
+ "description": "This PR adds a new feature...", // Optional
339
+ "reviewers": ["john.doe", "jane.smith"], // Optional
340
+ "close_source_branch": true // Optional (default: false)
341
+ }
342
+ }
343
+ ```
344
+
345
+ ### Update Pull Request
346
+
347
+ ```typescript
348
+ {
349
+ "tool": "update_pull_request",
350
+ "arguments": {
351
+ "workspace": "PROJ",
352
+ "repository": "my-repo",
353
+ "pull_request_id": 123,
354
+ "title": "Updated title", // Optional
355
+ "description": "Updated description", // Optional
356
+ "destination_branch": "develop", // Optional
357
+ "reviewers": ["new.reviewer"] // Optional - see note below
358
+ }
359
+ }
360
+ ```
361
+
362
+ **Important Note on Reviewers:**
363
+ - When updating a PR without specifying the `reviewers` parameter, existing reviewers and their approval status are preserved
364
+ - When providing the `reviewers` parameter:
365
+ - The reviewer list is replaced with the new list
366
+ - For reviewers that already exist on the PR, their approval status is preserved
367
+ - New reviewers are added without approval status
368
+ - This prevents accidentally removing reviewers when you only want to update the PR description or title
369
+
370
+ ### Add Comment
371
+
372
+ Add a comment to a pull request, either as a general comment or inline on specific code:
373
+
374
+ ```javascript
375
+ // General comment
376
+ {
377
+ "tool": "add_comment",
378
+ "arguments": {
379
+ "workspace": "PROJ",
380
+ "repository": "my-repo",
381
+ "pull_request_id": 123,
382
+ "comment_text": "Great work on this PR!"
383
+ }
384
+ }
385
+
386
+ // Inline comment on specific line
387
+ {
388
+ "tool": "add_comment",
389
+ "arguments": {
390
+ "workspace": "PROJ",
391
+ "repository": "my-repo",
392
+ "pull_request_id": 123,
393
+ "comment_text": "Consider extracting this into a separate function",
394
+ "file_path": "src/utils/helpers.js",
395
+ "line_number": 42,
396
+ "line_type": "CONTEXT" // ADDED, REMOVED, or CONTEXT
397
+ }
398
+ }
399
+
400
+ // Reply to existing comment
401
+ {
402
+ "tool": "add_comment",
403
+ "arguments": {
404
+ "workspace": "PROJ",
405
+ "repository": "my-repo",
406
+ "pull_request_id": 123,
407
+ "comment_text": "I agree with this suggestion",
408
+ "parent_comment_id": 456
409
+ }
410
+ }
411
+
412
+ // Add comment with code suggestion (single line)
413
+ {
414
+ "tool": "add_comment",
415
+ "arguments": {
416
+ "workspace": "PROJ",
417
+ "repository": "my-repo",
418
+ "pull_request_id": 123,
419
+ "comment_text": "This variable name could be more descriptive.",
420
+ "file_path": "src/utils/helpers.js",
421
+ "line_number": 42,
422
+ "line_type": "CONTEXT",
423
+ "suggestion": "const userAuthenticationToken = token;"
424
+ }
425
+ }
426
+
427
+ // Add comment with multi-line code suggestion
428
+ {
429
+ "tool": "add_comment",
430
+ "arguments": {
431
+ "workspace": "PROJ",
432
+ "repository": "my-repo",
433
+ "pull_request_id": 123,
434
+ "comment_text": "This function could be simplified using array methods.",
435
+ "file_path": "src/utils/calculations.js",
436
+ "line_number": 50,
437
+ "suggestion_end_line": 55,
438
+ "line_type": "CONTEXT",
439
+ "suggestion": "function calculateTotal(items) {\n return items.reduce((sum, item) => sum + item.price, 0);\n}"
440
+ }
441
+ }
442
+ ```
443
+
444
+ The suggestion feature formats comments using GitHub-style markdown suggestion blocks that Bitbucket can render. When adding a suggestion:
445
+ - `suggestion` is required and contains the replacement code
446
+ - `file_path` and `line_number` are required when using suggestions
447
+ - `suggestion_end_line` is optional and used for multi-line suggestions (defaults to `line_number`)
448
+ - The comment will be formatted with a ````suggestion` markdown block that may be applicable in the Bitbucket UI
449
+
450
+ ### Using Code Snippets Instead of Line Numbers
451
+
452
+ The `add_comment` tool now supports finding line numbers automatically using code snippets. This is especially useful when AI tools analyze diffs and may struggle with exact line numbers:
453
+
454
+ ```javascript
455
+ // Add comment using code snippet
456
+ {
457
+ "tool": "add_comment",
458
+ "arguments": {
459
+ "workspace": "PROJ",
460
+ "repository": "my-repo",
461
+ "pull_request_id": 123,
462
+ "comment_text": "This variable name could be more descriptive",
463
+ "file_path": "src/components/Button.res",
464
+ "code_snippet": "let isDisabled = false",
465
+ "search_context": {
466
+ "before": ["let onClick = () => {"],
467
+ "after": ["setLoading(true)"]
468
+ }
469
+ }
470
+ }
471
+
472
+ // Handle multiple matches with strategy
473
+ {
474
+ "tool": "add_comment",
475
+ "arguments": {
476
+ "workspace": "PROJ",
477
+ "repository": "my-repo",
478
+ "pull_request_id": 123,
479
+ "comment_text": "Consider extracting this",
480
+ "file_path": "src/utils/helpers.js",
481
+ "code_snippet": "return result;",
482
+ "search_context": {
483
+ "before": ["const result = calculate();"],
484
+ "after": ["}"]
485
+ },
486
+ "match_strategy": "best" // Auto-select highest confidence match
487
+ }
488
+ }
489
+ ```
490
+
491
+ **Code Snippet Parameters:**
492
+ - `code_snippet`: The exact code line to find (alternative to `line_number`)
493
+ - `search_context`: Optional context to disambiguate multiple matches
494
+ - `before`: Array of lines that should appear before the target
495
+ - `after`: Array of lines that should appear after the target
496
+ - `match_strategy`: How to handle multiple matches
497
+ - `"strict"` (default): Fail with error showing all matches
498
+ - `"best"`: Auto-select the highest confidence match
499
+
500
+ **Error Response for Multiple Matches (strict mode):**
501
+ ```json
502
+ {
503
+ "error": {
504
+ "code": "MULTIPLE_MATCHES_FOUND",
505
+ "message": "Code snippet 'return result;' found in 3 locations",
506
+ "occurrences": [
507
+ {
508
+ "line_number": 42,
509
+ "file_path": "src/utils/helpers.js",
510
+ "preview": " const result = calculate();\n> return result;\n}",
511
+ "confidence": 0.9,
512
+ "line_type": "ADDED"
513
+ },
514
+ // ... more matches
515
+ ],
516
+ "suggestion": "To resolve, either:\n1. Add more context...\n2. Use match_strategy: 'best'...\n3. Use line_number directly"
517
+ }
518
+ }
519
+ ```
520
+
521
+ This feature is particularly useful for:
522
+ - AI-powered code review tools that analyze diffs
523
+ - Scripts that automatically add comments based on code patterns
524
+ - Avoiding line number confusion in large diffs
525
+
526
+ **Note on comment replies:**
527
+ - Use `parent_comment_id` to reply to any comment (general or inline)
528
+ - In `get_pull_request` responses:
529
+ - Bitbucket Server shows replies nested in a `replies` array
530
+ - Bitbucket Cloud shows a `parent_id` field for reply comments
531
+ - You can reply to replies, creating nested conversations
532
+
533
+ **Note on inline comments:**
534
+ - `file_path`: The path to the file as shown in the diff
535
+ - `line_number`: The line number as shown in the diff
536
+ - `line_type`:
537
+ - `ADDED` - For newly added lines (green in diff)
538
+ - `REMOVED` - For deleted lines (red in diff)
539
+ - `CONTEXT` - For unchanged context lines
540
+
541
+ #### Add Comment - Complete Usage Guide
542
+
543
+ The `add_comment` tool supports multiple scenarios. Here's when and how to use each approach:
544
+
545
+ **1. General PR Comments (No file/line)**
546
+ - Use when: Making overall feedback about the PR
547
+ - Required params: `comment_text` only
548
+ - Example: "LGTM!", "Please update the documentation"
549
+
550
+ **2. Reply to Existing Comments**
551
+ - Use when: Continuing a conversation thread
552
+ - Required params: `comment_text`, `parent_comment_id`
553
+ - Works for both general and inline comment replies
554
+
555
+ **3. Inline Comments with Line Number**
556
+ - Use when: You know the exact line number from the diff
557
+ - Required params: `comment_text`, `file_path`, `line_number`
558
+ - Optional: `line_type` (defaults to CONTEXT)
559
+
560
+ **4. Inline Comments with Code Snippet**
561
+ - Use when: You have the code but not the line number (common for AI tools)
562
+ - Required params: `comment_text`, `file_path`, `code_snippet`
563
+ - The tool will automatically find the line number
564
+ - Add `search_context` if the code appears multiple times
565
+ - Use `match_strategy: "best"` to auto-select when multiple matches exist
566
+
567
+ **5. Code Suggestions**
568
+ - Use when: Proposing specific code changes
569
+ - Required params: `comment_text`, `file_path`, `line_number`, `suggestion`
570
+ - For multi-line: also add `suggestion_end_line`
571
+ - Creates applicable suggestion blocks in Bitbucket UI
572
+
573
+ **Decision Flow for AI/Automated Tools:**
574
+ ```
575
+ 1. Do you want to suggest code changes?
576
+ → Use suggestion with line_number
577
+
578
+ 2. Do you have the exact line number?
579
+ → Use line_number directly
580
+
581
+ 3. Do you have the code snippet but not line number?
582
+ → Use code_snippet (add search_context if needed)
583
+
584
+ 4. Is it a general comment about the PR?
585
+ → Use comment_text only
586
+
587
+ 5. Are you replying to another comment?
588
+ → Add parent_comment_id
589
+ ```
590
+
591
+ **Common Pitfalls to Avoid:**
592
+ - Don't use both `line_number` and `code_snippet` - pick one
593
+ - Suggestions always need `file_path` and `line_number`
594
+ - Code snippets must match exactly (including whitespace)
595
+ - REMOVED lines reference the source file, ADDED/CONTEXT reference the destination
596
+
597
+ ### Merge Pull Request
598
+
599
+ ```typescript
600
+ {
601
+ "tool": "merge_pull_request",
602
+ "arguments": {
603
+ "workspace": "PROJ",
604
+ "repository": "my-repo",
605
+ "pull_request_id": 123,
606
+ "merge_strategy": "squash", // Optional: merge-commit, squash, fast-forward
607
+ "close_source_branch": true, // Optional
608
+ "commit_message": "Custom merge message" // Optional
609
+ }
610
+ }
611
+ ```
612
+
613
+ ### List Branches
614
+
615
+ ```typescript
616
+ {
617
+ "tool": "list_branches",
618
+ "arguments": {
619
+ "workspace": "PROJ",
620
+ "repository": "my-repo",
621
+ "filter": "feature", // Optional: filter by name pattern
622
+ "limit": 25, // Optional (default: 25)
623
+ "start": 0 // Optional: for pagination (default: 0)
624
+ }
625
+ }
626
+ ```
627
+
628
+ Returns a paginated list of branches with:
629
+ - Branch name and ID
630
+ - Latest commit hash
631
+ - Default branch indicator
632
+ - Pagination info
633
+
634
+ ### Delete Branch
635
+
636
+ ```typescript
637
+ {
638
+ "tool": "delete_branch",
639
+ "arguments": {
640
+ "workspace": "PROJ",
641
+ "repository": "my-repo",
642
+ "branch_name": "feature/old-feature",
643
+ "force": false // Optional (default: false)
644
+ }
645
+ }
646
+ ```
647
+
648
+ **Note**: Branch deletion requires appropriate permissions. The branch will be permanently deleted.
649
+
650
+ ### Get Branch
651
+
652
+ ```typescript
653
+ {
654
+ "tool": "get_branch",
655
+ "arguments": {
656
+ "workspace": "PROJ",
657
+ "repository": "my-repo",
658
+ "branch_name": "feature/new-feature",
659
+ "include_merged_prs": false // Optional (default: false)
660
+ }
661
+ }
662
+ ```
663
+
664
+ Returns comprehensive branch information including:
665
+ - Branch details:
666
+ - Name and ID
667
+ - Latest commit (hash, message, author, date)
668
+ - Default branch indicator
669
+ - Open pull requests from this branch:
670
+ - PR title and ID
671
+ - Destination branch
672
+ - Author and reviewers
673
+ - Approval status (approved by, changes requested by, pending)
674
+ - PR URL
675
+ - Merged pull requests (if `include_merged_prs` is true):
676
+ - PR title and ID
677
+ - Merge date and who merged it
678
+ - Statistics:
679
+ - Total open PRs count
680
+ - Total merged PRs count
681
+ - Days since last commit
682
+
683
+ This tool is particularly useful for:
684
+ - Checking if a branch has open PRs before deletion
685
+ - Getting an overview of branch activity
686
+ - Understanding PR review status
687
+ - Identifying stale branches
688
+
689
+ ### List Branch Commits
690
+
691
+ Get all commits in a specific branch with advanced filtering options:
692
+
693
+ ```typescript
694
+ // Basic usage - get recent commits
695
+ {
696
+ "tool": "list_branch_commits",
697
+ "arguments": {
698
+ "workspace": "PROJ",
699
+ "repository": "my-repo",
700
+ "branch_name": "feature/new-feature",
701
+ "limit": 50 // Optional (default: 25)
702
+ }
703
+ }
704
+
705
+ // Filter by date range
706
+ {
707
+ "tool": "list_branch_commits",
708
+ "arguments": {
709
+ "workspace": "PROJ",
710
+ "repository": "my-repo",
711
+ "branch_name": "main",
712
+ "since": "2025-01-01T00:00:00Z", // ISO date string
713
+ "until": "2025-01-15T23:59:59Z" // ISO date string
714
+ }
715
+ }
716
+
717
+ // Filter by author
718
+ {
719
+ "tool": "list_branch_commits",
720
+ "arguments": {
721
+ "workspace": "PROJ",
722
+ "repository": "my-repo",
723
+ "branch_name": "develop",
724
+ "author": "john.doe@company.com", // Email or username
725
+ "limit": 100
726
+ }
727
+ }
728
+
729
+ // Exclude merge commits
730
+ {
731
+ "tool": "list_branch_commits",
732
+ "arguments": {
733
+ "workspace": "PROJ",
734
+ "repository": "my-repo",
735
+ "branch_name": "release/v2.0",
736
+ "include_merge_commits": false
737
+ }
738
+ }
739
+
740
+ // Search in commit messages
741
+ {
742
+ "tool": "list_branch_commits",
743
+ "arguments": {
744
+ "workspace": "PROJ",
745
+ "repository": "my-repo",
746
+ "branch_name": "main",
747
+ "search": "bugfix", // Search in commit messages
748
+ "limit": 50
749
+ }
750
+ }
751
+
752
+ // Combine multiple filters
753
+ {
754
+ "tool": "list_branch_commits",
755
+ "arguments": {
756
+ "workspace": "PROJ",
757
+ "repository": "my-repo",
758
+ "branch_name": "develop",
759
+ "author": "jane.smith@company.com",
760
+ "since": "2025-01-01T00:00:00Z",
761
+ "include_merge_commits": false,
762
+ "search": "feature",
763
+ "limit": 100,
764
+ "start": 0 // For pagination
765
+ }
766
+ }
767
+ ```
768
+
769
+ **Filter Parameters:**
770
+ - `since`: ISO date string - only show commits after this date
771
+ - `until`: ISO date string - only show commits before this date
772
+ - `author`: Filter by author email/username
773
+ - `include_merge_commits`: Boolean to include/exclude merge commits (default: true)
774
+ - `search`: Search for text in commit messages
775
+
776
+ Returns detailed commit information:
777
+ ```json
778
+ {
779
+ "branch_name": "feature/new-feature",
780
+ "branch_head": "abc123def456", // Latest commit hash
781
+ "commits": [
782
+ {
783
+ "hash": "abc123def456",
784
+ "abbreviated_hash": "abc123d",
785
+ "message": "Add new feature implementation",
786
+ "author": {
787
+ "name": "John Doe",
788
+ "email": "john.doe@example.com"
789
+ },
790
+ "date": "2025-01-03T10:30:00Z",
791
+ "parents": ["parent1hash", "parent2hash"],
792
+ "is_merge_commit": false
793
+ }
794
+ // ... more commits
795
+ ],
796
+ "total_count": 150,
797
+ "start": 0,
798
+ "limit": 25,
799
+ "has_more": true,
800
+ "next_start": 25,
801
+ "filters_applied": {
802
+ "author": "john.doe@example.com",
803
+ "since": "2025-01-01",
804
+ "include_merge_commits": false
805
+ }
806
+ }
807
+ ```
808
+
809
+ This tool is particularly useful for:
810
+ - Reviewing commit history before releases
811
+ - Finding commits by specific authors
812
+ - Tracking changes within date ranges
813
+ - Searching for specific features or fixes
814
+ - Analyzing branch activity patterns
815
+
816
+ ### List PR Commits
817
+
818
+ Get all commits that are part of a pull request:
819
+
820
+ ```typescript
821
+ {
822
+ "tool": "list_pr_commits",
823
+ "arguments": {
824
+ "workspace": "PROJ",
825
+ "repository": "my-repo",
826
+ "pull_request_id": 123,
827
+ "limit": 50, // Optional (default: 25)
828
+ "start": 0 // Optional: for pagination
829
+ }
830
+ }
831
+ ```
832
+
833
+ Returns commit information for the PR:
834
+ ```json
835
+ {
836
+ "pull_request_id": 123,
837
+ "pull_request_title": "Add awesome feature",
838
+ "commits": [
839
+ {
840
+ "hash": "def456ghi789",
841
+ "abbreviated_hash": "def456g",
842
+ "message": "Initial implementation",
843
+ "author": {
844
+ "name": "Jane Smith",
845
+ "email": "jane.smith@example.com"
846
+ },
847
+ "date": "2025-01-02T14:20:00Z",
848
+ "parents": ["parent1hash"],
849
+ "is_merge_commit": false
850
+ }
851
+ // ... more commits
852
+ ],
853
+ "total_count": 5,
854
+ "start": 0,
855
+ "limit": 25,
856
+ "has_more": false
857
+ }
858
+ ```
859
+
860
+ This tool is particularly useful for:
861
+ - Reviewing all changes in a PR before merging
862
+ - Understanding the development history of a PR
863
+ - Checking commit messages for quality
864
+ - Verifying authorship of changes
865
+ - Analyzing PR complexity by commit count
866
+
867
+ ### Get Pull Request Diff
868
+
869
+ Get the diff/changes for a pull request with optional filtering capabilities:
870
+
871
+ ```typescript
872
+ // Get full diff (default behavior)
873
+ {
874
+ "tool": "get_pull_request_diff",
875
+ "arguments": {
876
+ "workspace": "PROJ",
877
+ "repository": "my-repo",
878
+ "pull_request_id": 123,
879
+ "context_lines": 5 // Optional (default: 3)
880
+ }
881
+ }
882
+
883
+ // Exclude specific file types
884
+ {
885
+ "tool": "get_pull_request_diff",
886
+ "arguments": {
887
+ "workspace": "PROJ",
888
+ "repository": "my-repo",
889
+ "pull_request_id": 123,
890
+ "exclude_patterns": ["*.lock", "*.svg", "node_modules/**", "*.min.js"]
891
+ }
892
+ }
893
+
894
+ // Include only specific file types
895
+ {
896
+ "tool": "get_pull_request_diff",
897
+ "arguments": {
898
+ "workspace": "PROJ",
899
+ "repository": "my-repo",
900
+ "pull_request_id": 123,
901
+ "include_patterns": ["*.res", "*.resi", "src/**/*.js"]
902
+ }
903
+ }
904
+
905
+ // Get diff for a specific file only
906
+ {
907
+ "tool": "get_pull_request_diff",
908
+ "arguments": {
909
+ "workspace": "PROJ",
910
+ "repository": "my-repo",
911
+ "pull_request_id": 123,
912
+ "file_path": "src/components/Button.res"
913
+ }
914
+ }
915
+
916
+ // Combine filters
917
+ {
918
+ "tool": "get_pull_request_diff",
919
+ "arguments": {
920
+ "workspace": "PROJ",
921
+ "repository": "my-repo",
922
+ "pull_request_id": 123,
923
+ "include_patterns": ["src/**/*"],
924
+ "exclude_patterns": ["*.test.js", "*.spec.js"]
925
+ }
926
+ }
927
+ ```
928
+
929
+ **Filtering Options:**
930
+ - `include_patterns`: Array of glob patterns to include (whitelist)
931
+ - `exclude_patterns`: Array of glob patterns to exclude (blacklist)
932
+ - `file_path`: Get diff for a specific file only
933
+ - Patterns support standard glob syntax (e.g., `*.js`, `src/**/*.res`, `!test/**`)
934
+
935
+ **Response includes filtering metadata:**
936
+ ```json
937
+ {
938
+ "message": "Pull request diff retrieved successfully",
939
+ "pull_request_id": 123,
940
+ "diff": "..filtered diff content..",
941
+ "filter_metadata": {
942
+ "total_files": 15,
943
+ "included_files": 12,
944
+ "excluded_files": 3,
945
+ "excluded_file_list": ["package-lock.json", "logo.svg", "yarn.lock"],
946
+ "filters_applied": {
947
+ "exclude_patterns": ["*.lock", "*.svg"]
948
+ }
949
+ }
950
+ }
951
+ ```
952
+
953
+ ### Approve Pull Request
954
+
955
+ ```typescript
956
+ {
957
+ "tool": "approve_pull_request",
958
+ "arguments": {
959
+ "workspace": "PROJ",
960
+ "repository": "my-repo",
961
+ "pull_request_id": 123
962
+ }
963
+ }
964
+ ```
965
+
966
+ ### Request Changes
967
+
968
+ ```typescript
969
+ {
970
+ "tool": "request_changes",
971
+ "arguments": {
972
+ "workspace": "PROJ",
973
+ "repository": "my-repo",
974
+ "pull_request_id": 123,
975
+ "comment": "Please address the following issues..." // Optional
976
+ }
977
+ }
978
+ ```
979
+
980
+ ### List Directory Content
981
+
982
+ ```typescript
983
+ {
984
+ "tool": "list_directory_content",
985
+ "arguments": {
986
+ "workspace": "PROJ",
987
+ "repository": "my-repo",
988
+ "path": "src/components", // Optional (defaults to root)
989
+ "branch": "main" // Optional (defaults to default branch)
990
+ }
991
+ }
992
+ ```
993
+
994
+ Returns directory listing with:
995
+ - Path and branch information
996
+ - Array of contents with:
997
+ - Name
998
+ - Type (file or directory)
999
+ - Size (for files)
1000
+ - Full path
1001
+ - Total items count
1002
+
1003
+ ### Get File Content
1004
+
1005
+ ```typescript
1006
+ {
1007
+ "tool": "get_file_content",
1008
+ "arguments": {
1009
+ "workspace": "PROJ",
1010
+ "repository": "my-repo",
1011
+ "file_path": "src/index.ts",
1012
+ "branch": "main", // Optional (defaults to default branch)
1013
+ "start_line": 1, // Optional: starting line (1-based, use negative for from end)
1014
+ "line_count": 100, // Optional: number of lines to return
1015
+ "full_content": false // Optional: force full content (default: false)
1016
+ }
1017
+ }
1018
+ ```
1019
+
1020
+ **Smart Truncation Features:**
1021
+ - Automatically truncates large files (>50KB) to prevent token overload
1022
+ - Default line counts based on file type:
1023
+ - Config files (.yml, .json): 200 lines
1024
+ - Documentation (.md, .txt): 300 lines
1025
+ - Code files (.ts, .js, .py): 500 lines
1026
+ - Log files: Last 100 lines
1027
+ - Use `start_line: -50` to get last 50 lines (tail functionality)
1028
+ - Files larger than 1MB require explicit `full_content: true` or line parameters
1029
+
1030
+ Returns file content with:
1031
+ - File path and branch
1032
+ - File size and encoding
1033
+ - Content (full or truncated based on parameters)
1034
+ - Line information (if truncated):
1035
+ - Total lines in file
1036
+ - Range of returned lines
1037
+ - Truncation indicator
1038
+ - Last modified information (commit, author, date)
1039
+
1040
+ Example responses:
1041
+
1042
+ ```json
1043
+ // Small file - returns full content
1044
+ {
1045
+ "file_path": "package.json",
1046
+ "branch": "main",
1047
+ "size": 1234,
1048
+ "encoding": "utf-8",
1049
+ "content": "{\n \"name\": \"my-project\",\n ...",
1050
+ "last_modified": {
1051
+ "commit_id": "abc123",
1052
+ "author": "John Doe",
1053
+ "date": "2025-01-21T10:00:00Z"
1054
+ }
1055
+ }
1056
+
1057
+ // Large file - automatically truncated
1058
+ {
1059
+ "file_path": "src/components/LargeComponent.tsx",
1060
+ "branch": "main",
1061
+ "size": 125000,
1062
+ "encoding": "utf-8",
1063
+ "content": "... first 500 lines ...",
1064
+ "line_info": {
1065
+ "total_lines": 3500,
1066
+ "returned_lines": {
1067
+ "start": 1,
1068
+ "end": 500
1069
+ },
1070
+ "truncated": true,
1071
+ "message": "Showing lines 1-500 of 3500. File size: 122.1KB"
1072
+ }
1073
+ }
1074
+ ```
1075
+
1076
+ ## Development
1077
+
1078
+ - `npm run dev` - Watch mode for development
1079
+ - `npm run build` - Build the TypeScript code
1080
+ - `npm start` - Run the built server
1081
+
1082
+ ## Troubleshooting
1083
+
1084
+ 1. **Authentication errors**: Double-check your username and app password
1085
+ 2. **404 errors**: Verify the workspace, repository slug, and PR ID
1086
+ 3. **Permission errors**: Ensure your app password has the required permissions
1087
+
1088
+ ## License
1089
+
1090
+ MIT