概述
安裝
工具列表
內容詳情
替代品
什麼是Bitbucket MCP服務器?
Bitbucket MCP服務器是一個模型上下文協議(MCP)服務器,它為開發人員提供了與Bitbucket API交互的工具。通過這個服務器,您可以輕鬆地管理代碼審查、分支操作、文件瀏覽等任務。如何使用Bitbucket MCP服務器?
使用Bitbucket MCP服務器需要安裝並配置相關工具。您可以通過npm直接運行服務器,或者從源代碼構建。一旦配置完成,您就可以通過簡單的命令與Bitbucket進行交互。適用場景
Bitbucket MCP服務器適用於團隊協作開發、自動化代碼審查、持續集成和部署等場景。它特別適合需要頻繁與Bitbucket交互的開發人員和項目經理。主要功能
優勢與侷限性
如何使用
使用案例
常見問題
相關資源
安裝
{
"mcpServers": {
"bitbucket": {
"command": "npx",
"args": [
"-y",
"@nexus2520/bitbucket-mcp-server"
],
"env": {
"BITBUCKET_USERNAME": "your-username",
"BITBUCKET_APP_PASSWORD": "your-app-password"
}
}
}
}
{
"mcpServers": {
"bitbucket": {
"command": "npx",
"args": [
"-y",
"@nexus2520/bitbucket-mcp-server"
],
"env": {
"BITBUCKET_USERNAME": "your.email@company.com",
"BITBUCKET_TOKEN": "your-http-access-token",
"BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
}
}
}
}
{
"mcpServers": {
"bitbucket": {
"command": "node",
"args": ["/absolute/path/to/bitbucket-mcp-server/build/index.js"],
"env": {
"BITBUCKET_USERNAME": "your-username",
"BITBUCKET_APP_PASSWORD": "your-app-password"
}
}
}
}
{
"mcpServers": {
"bitbucket": {
"command": "node",
"args": ["/absolute/path/to/bitbucket-mcp-server/build/index.js"],
"env": {
"BITBUCKET_USERNAME": "your.email@company.com",
"BITBUCKET_TOKEN": "your-http-access-token",
"BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
}
}
}
}
🚀 Bitbucket MCP Server
Bitbucket MCP Server 是一個基於模型上下文協議(MCP)的服務器,它提供了與 Bitbucket API 交互的工具,同時支持 Bitbucket Cloud 和 Bitbucket Server。
🚀 快速開始
本 MCP 服務器提供了豐富的工具,用於與 Bitbucket API 進行交互。你可以按照以下步驟進行安裝和配置,從而使用這些工具。
✨ 主要特性
當前已實現的工具
核心 PR 生命週期工具
get_pull_request
- 獲取拉取請求的詳細信息list_pull_requests
- 按篩選條件(狀態、作者、分頁)列出拉取請求create_pull_request
- 創建新的拉取請求update_pull_request
- 更新拉取請求的詳細信息(標題、描述、審核人、目標分支)add_comment
- 為拉取請求添加評論(支持回覆)merge_pull_request
- 以各種策略合併拉取請求list_pr_commits
- 列出屬於拉取請求的所有提交delete_branch
- 合併後刪除分支
分支管理工具
list_branches
- 按篩選條件和分頁列出分支delete_branch
- 刪除分支(進行保護檢查)get_branch
- 獲取詳細的分支信息,包括關聯的 PRlist_branch_commits
- 按高級篩選條件列出分支中的提交
文件和目錄工具
list_directory_content
- 列出存儲庫路徑中的文件和目錄get_file_content
- 獲取文件內容,對大文件進行智能截斷
代碼審查工具
get_pull_request_diff
- 獲取拉取請求的差異/更改approve_pull_request
- 批准拉取請求unapprove_pull_request
- 撤銷對拉取請求的批准request_changes
- 請求對拉取請求進行更改remove_requested_changes
- 撤銷對拉取請求的更改請求
📦 安裝指南
使用 npx(推薦)
使用 npx 直接使用此 MCP 服務器是最簡單的方法:
{
"mcpServers": {
"bitbucket": {
"command": "npx",
"args": [
"-y",
"@nexus2520/bitbucket-mcp-server"
],
"env": {
"BITBUCKET_USERNAME": "your-username",
"BITBUCKET_APP_PASSWORD": "your-app-password"
}
}
}
}
對於 Bitbucket Server:
{
"mcpServers": {
"bitbucket": {
"command": "npx",
"args": [
"-y",
"@nexus2520/bitbucket-mcp-server"
],
"env": {
"BITBUCKET_USERNAME": "your.email@company.com",
"BITBUCKET_TOKEN": "your-http-access-token",
"BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
}
}
}
}
從源代碼安裝
- 克隆或下載此存儲庫
- 安裝依賴項:
npm install
- 構建 TypeScript 代碼:
npm run build
📚 詳細文檔
身份驗證設置
此服務器使用 Bitbucket 應用密碼進行身份驗證。
創建應用密碼
- 登錄到你的 Bitbucket 賬戶
- 導航到:https://bitbucket.org/account/settings/app-passwords/
- 點擊“創建應用密碼”
- 給它一個描述性標籤(例如,“MCP Server”)
- 選擇以下權限:
- 賬戶:讀取
- 存儲庫:讀取、寫入
- 拉取請求:讀取、寫入
- 點擊“創建”
- 重要提示:立即複製生成的密碼(你將無法再次看到它!)
運行設置腳本
node scripts/setup-auth.js
這將引導你完成身份驗證設置過程。
配置
將服務器添加到你的 MCP 設置文件中(通常位於 ~/.vscode-server/data/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
):
{
"mcpServers": {
"bitbucket": {
"command": "node",
"args": ["/absolute/path/to/bitbucket-mcp-server/build/index.js"],
"env": {
"BITBUCKET_USERNAME": "your-username",
"BITBUCKET_APP_PASSWORD": "your-app-password"
}
}
}
}
替換:
/absolute/path/to/bitbucket-mcp-server
為該目錄的實際路徑your-username
為你的 Bitbucket 用戶名(不是電子郵件)your-app-password
為你創建的應用密碼
對於 Bitbucket Server,使用:
{
"mcpServers": {
"bitbucket": {
"command": "node",
"args": ["/absolute/path/to/bitbucket-mcp-server/build/index.js"],
"env": {
"BITBUCKET_USERNAME": "your.email@company.com",
"BITBUCKET_TOKEN": "your-http-access-token",
"BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
}
}
}
}
Bitbucket Server 用戶注意事項:
- 使用你的完整電子郵件地址作為用戶名(例如,“john.doe@company.com”)
- 這是確保批准/審核操作正確工作所必需的
💻 使用示例
基礎用法
獲取拉取請求
{
"tool": "get_pull_request",
"arguments": {
"workspace": "PROJ", // 必需 - 你的項目密鑰
"repository": "my-repo",
"pull_request_id": 123
}
}
返回拉取請求的詳細信息,包括:
- 標題和描述
- 作者和審核人
- 源分支和目標分支
- 批准狀態
- 指向 Web UI 和差異的鏈接
- 合併提交詳情(當 PR 合併時):
merge_commit_hash
:合併提交的哈希值merged_by
:執行合併的人merged_at
:合併發生的時間merge_commit_message
:合併提交消息
- 帶有嵌套回覆的活動評論(需要關注的未解決評論):
active_comments
:活動評論數組(最多 20 條最近的頂級評論)- 評論文本和作者
- 創建日期
- 是否為內聯評論(帶有文件路徑和行號)
- 嵌套回覆(適用於 Bitbucket Server):
replies
:具有相同結構的回覆評論數組- 回覆可以嵌套多層
- 父引用(適用於 Bitbucket Cloud):
parent_id
:回覆評論的父評論 ID
active_comment_count
:未解決評論的總數(包括嵌套回覆)total_comment_count
:所有評論的總數(包括已解決和回覆)
- 文件更改:
file_changes
:PR 中修改的所有文件的數組- 文件路徑
- 狀態(添加、修改、刪除或重命名)
- 舊路徑(對於重命名的文件)
file_changes_summary
:摘要統計信息- 更改的文件總數
- 以及更多...
列出拉取請求
{
"tool": "list_pull_requests",
"arguments": {
"workspace": "PROJ", // 必需 - 你的項目密鑰
"repository": "my-repo",
"state": "OPEN", // 可選: OPEN, MERGED, DECLINED, ALL (默認: OPEN)
"author": "username", // 可選: 按作者篩選 (見下面的註釋)
"limit": 25, // 可選: 每頁的最大結果數 (默認: 25)
"start": 0 // 可選: 分頁起始索引 (默認: 0)
}
}
返回分頁的拉取請求列表,包含:
- 與
get_pull_request
相同詳細信息的拉取請求數組 - 匹配的 PR 總數
- 分頁信息(has_more, next_start)
作者篩選注意事項:
- 對於 Bitbucket Cloud:使用用戶名(例如,“johndoe”)
- 對於 Bitbucket Server:使用完整的電子郵件地址(例如,“john.doe@company.com”)
創建拉取請求
{
"tool": "create_pull_request",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"title": "Add new feature",
"source_branch": "feature/new-feature",
"destination_branch": "main",
"description": "This PR adds a new feature...", // 可選
"reviewers": ["john.doe", "jane.smith"], // 可選
"close_source_branch": true // 可選 (默認: false)
}
}
更新拉取請求
{
"tool": "update_pull_request",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"title": "Updated title", // 可選
"description": "Updated description", // 可選
"destination_branch": "develop", // 可選
"reviewers": ["new.reviewer"] // 可選 - 見下面的註釋
}
}
審核人重要說明:
- 當更新 PR 時未指定
reviewers
參數,現有審核人和他們的批准狀態將被保留 - 當提供
reviewers
參數時:- 審核人列表將被新列表替換
- 對於已經在 PR 上的審核人,他們的批准狀態將被保留
- 新審核人將以未批准狀態添加
- 這可以防止在僅想更新 PR 描述或標題時意外刪除審核人
添加評論
為拉取請求添加評論,可以是一般評論或特定代碼行的內聯評論:
// 一般評論
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "Great work on this PR!"
}
}
// 特定行的內聯評論
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "Consider extracting this into a separate function",
"file_path": "src/utils/helpers.js",
"line_number": 42,
"line_type": "CONTEXT" // ADDED, REMOVED, or CONTEXT
}
}
// 回覆現有評論
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "I agree with this suggestion",
"parent_comment_id": 456
}
}
// 添加帶有代碼建議的評論(單行)
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "This variable name could be more descriptive.",
"file_path": "src/utils/helpers.js",
"line_number": 42,
"line_type": "CONTEXT",
"suggestion": "const userAuthenticationToken = token;"
}
}
// 添加帶有多行代碼建議的評論
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "This function could be simplified using array methods.",
"file_path": "src/utils/calculations.js",
"line_number": 50,
"suggestion_end_line": 55,
"line_type": "CONTEXT",
"suggestion": "function calculateTotal(items) {\n return items.reduce((sum, item) => sum + item.price, 0);\n}"
}
}
建議功能使用 GitHub 風格的 markdown 建議塊格式化評論,Bitbucket 可以渲染。添加建議時:
suggestion
是必需的,包含替換代碼- 使用建議時,
file_path
和line_number
是必需的 suggestion_end_line
是可選的,用於多行建議(默認為line_number
)- 評論將使用 ````suggestion` markdown 塊格式化,可能適用於 Bitbucket UI
使用代碼片段代替行號
add_comment
工具現在支持使用代碼片段自動查找行號。這在 AI 工具分析差異時特別有用,因為它們可能難以確定確切的行號:
// 使用代碼片段添加評論
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "This variable name could be more descriptive",
"file_path": "src/components/Button.res",
"code_snippet": "let isDisabled = false",
"search_context": {
"before": ["let onClick = () => {"],
"after": ["setLoading(true)"]
}
}
}
// 使用策略處理多個匹配項
{
"tool": "add_comment",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment_text": "Consider extracting this",
"file_path": "src/utils/helpers.js",
"code_snippet": "return result;",
"search_context": {
"before": ["const result = calculate();"],
"after": ["}"]
},
"match_strategy": "best" // 自動選擇最高置信度匹配
}
}
代碼片段參數:
code_snippet
:要查找的精確代碼行(替代line_number
)search_context
:可選上下文,用於消除多個匹配項的歧義before
:應出現在目標之前的行數組after
:應出現在目標之後的行數組
match_strategy
:如何處理多個匹配項"strict"
(默認):失敗並顯示所有匹配項的錯誤"best"
:自動選擇最高置信度匹配
多個匹配項的錯誤響應(嚴格模式):
{
"error": {
"code": "MULTIPLE_MATCHES_FOUND",
"message": "Code snippet 'return result;' found in 3 locations",
"occurrences": [
{
"line_number": 42,
"file_path": "src/utils/helpers.js",
"preview": " const result = calculate();\n> return result;\n}",
"confidence": 0.9,
"line_type": "ADDED"
},
// ... 更多匹配項
],
"suggestion": "To resolve, either:\n1. Add more context...\n2. Use match_strategy: 'best'...\n3. Use line_number directly"
}
}
此功能對於以下情況特別有用:
- 分析差異的 AI 驅動的代碼審查工具
- 根據代碼模式自動添加評論的腳本
- 避免大差異中的行號混淆
評論回覆注意事項:
- 使用
parent_comment_id
回覆任何評論(一般或內聯) - 在
get_pull_request
響應中:- Bitbucket Server 在
replies
數組中顯示嵌套回覆 - Bitbucket Cloud 為回覆評論顯示
parent_id
字段
- Bitbucket Server 在
- 你可以回覆回覆,創建嵌套對話
內聯評論注意事項:
file_path
:差異中顯示的文件路徑line_number
:差異中顯示的行號line_type
:ADDED
- 對於新添加的行(差異中為綠色)REMOVED
- 對於刪除的行(差異中為紅色)CONTEXT
- 對於未更改的上下文行
添加評論 - 完整使用指南
add_comment
工具支持多種場景。以下是何時以及如何使用每種方法:
1. 一般 PR 評論(無文件/行)
- 使用場景:對 PR 進行總體反饋
- 必需參數:僅
comment_text
- 示例:“LGTM!”,“請更新文檔”
2. 回覆現有評論
- 使用場景:繼續對話線程
- 必需參數:
comment_text
,parent_comment_id
- 適用於一般和內聯評論回覆
3. 帶行號的內聯評論
- 使用場景:你知道差異中的確切行號
- 必需參數:
comment_text
,file_path
,line_number
- 可選:
line_type
(默認為 CONTEXT)
4. 帶代碼片段的內聯評論
- 使用場景:你有代碼但不知道行號(AI 工具常見)
- 必需參數:
comment_text
,file_path
,code_snippet
- 工具將自動查找行號
- 如果代碼多次出現,添加
search_context
- 當存在多個匹配項時,使用
match_strategy: "best"
自動選擇
5. 代碼建議
- 使用場景:提出特定的代碼更改建議
- 必需參數:
comment_text
,file_path
,line_number
,suggestion
- 對於多行:還需添加
suggestion_end_line
- 在 Bitbucket UI 中創建適用的建議塊
AI/自動化工具的決策流程:
1. 你是否想建議代碼更改?
→ 使用帶行號的建議
2. 你是否有確切的行號?
→ 直接使用行號
3. 你有代碼片段但沒有行號嗎?
→ 使用代碼片段(如有需要添加搜索上下文)
4. 這是關於 PR 的一般評論嗎?
→ 僅使用 comment_text
5. 你是否在回覆另一條評論?
→ 添加 parent_comment_id
避免常見陷阱:
- 不要同時使用
line_number
和code_snippet
- 選擇其一 - 建議始終需要
file_path
和line_number
- 代碼片段必須完全匹配(包括空白)
- REMOVED 行引用源文件,ADDED/CONTEXT 引用目標文件
合併拉取請求
{
"tool": "merge_pull_request",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"merge_strategy": "squash", // 可選: merge-commit, squash, fast-forward
"close_source_branch": true, // 可選
"commit_message": "Custom merge message" // 可選
}
}
列出分支
{
"tool": "list_branches",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"filter": "feature", // 可選: 按名稱模式篩選
"limit": 25, // 可選 (默認: 25)
"start": 0 // 可選: 用於分頁 (默認: 0)
}
}
返回分頁的分支列表,包含:
- 分支名稱和 ID
- 最新提交哈希
- 默認分支指示符
- 分頁信息
刪除分支
{
"tool": "delete_branch",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "feature/old-feature",
"force": false // 可選 (默認: false)
}
}
注意:刪除分支需要適當的權限。分支將被永久刪除。
獲取分支
{
"tool": "get_branch",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "feature/new-feature",
"include_merged_prs": false // 可選 (默認: false)
}
}
返回全面的分支信息,包括:
- 分支詳情:
- 名稱和 ID
- 最新提交(哈希、消息、作者、日期)
- 默認分支指示符
- 從此分支發出的開放拉取請求:
- PR 標題和 ID
- 目標分支
- 作者和審核人
- 批准狀態(批准人、請求更改人、待處理)
- PR URL
- 合併的拉取請求(如果
include_merged_prs
為 true):- PR 標題和 ID
- 合併日期和合並人
- 統計信息:
- 開放 PR 總數
- 合併 PR 總數
- 自上次提交以來的天數
此工具對於以下情況特別有用:
- 在刪除分支之前檢查是否有開放 PR
- 獲取分支活動概述
- 瞭解 PR 審核狀態
- 識別陳舊分支
列出分支提交
獲取特定分支中的所有提交,並具有高級篩選選項:
// 基本用法 - 獲取最近的提交
{
"tool": "list_branch_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "feature/new-feature",
"limit": 50 // 可選 (默認: 25)
}
}
// 按日期範圍篩選
{
"tool": "list_branch_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "main",
"since": "2025-01-01T00:00:00Z", // ISO 日期字符串
"until": "2025-01-15T23:59:59Z" // ISO 日期字符串
}
}
// 按作者篩選
{
"tool": "list_branch_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "develop",
"author": "john.doe@company.com", // 電子郵件或用戶名
"limit": 100
}
}
// 排除合併提交
{
"tool": "list_branch_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "release/v2.0",
"include_merge_commits": false
}
}
// 在提交消息中搜索
{
"tool": "list_branch_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "main",
"search": "bugfix", // 在提交消息中搜索
"limit": 50
}
}
// 組合多個篩選器
{
"tool": "list_branch_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"branch_name": "develop",
"author": "jane.smith@company.com",
"since": "2025-01-01T00:00:00Z",
"include_merge_commits": false,
"search": "feature",
"limit": 100,
"start": 0 // 用於分頁
}
}
篩選參數:
since
:ISO 日期字符串 - 僅顯示此日期之後的提交until
:ISO 日期字符串 - 僅顯示此日期之前的提交author
:按作者電子郵件/用戶名篩選include_merge_commits
:布爾值,是否包含合併提交(默認:true)search
:在提交消息中搜索文本
返回詳細的提交信息:
{
"branch_name": "feature/new-feature",
"branch_head": "abc123def456", // 最新提交哈希
"commits": [
{
"hash": "abc123def456",
"abbreviated_hash": "abc123d",
"message": "Add new feature implementation",
"author": {
"name": "John Doe",
"email": "john.doe@example.com"
},
"date": "2025-01-03T10:30:00Z",
"parents": ["parent1hash", "parent2hash"],
"is_merge_commit": false
}
// ... 更多提交
],
"total_count": 150,
"start": 0,
"limit": 25,
"has_more": true,
"next_start": 25,
"filters_applied": {
"author": "john.doe@example.com",
"since": "2025-01-01",
"include_merge_commits": false
}
}
此工具對於以下情況特別有用:
- 在發佈前審查提交歷史
- 查找特定作者的提交
- 跟蹤日期範圍內的更改
- 搜索特定功能或修復
- 分析分支活動模式
獲取拉取請求中的提交
獲取屬於拉取請求的所有提交:
{
"tool": "list_pr_commits",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"limit": 50, // 可選 (默認: 25)
"start": 0 // 可選: 用於分頁
}
}
返回 PR 的提交信息:
{
"pull_request_id": 123,
"pull_request_title": "Add awesome feature",
"commits": [
{
"hash": "def456ghi789",
"abbreviated_hash": "def456g",
"message": "Initial implementation",
"author": {
"name": "Jane Smith",
"email": "jane.smith@example.com"
},
"date": "2025-01-02T14:20:00Z",
"parents": ["parent1hash"],
"is_merge_commit": false
}
// ... 更多提交
],
"total_count": 5,
"start": 0,
"limit": 25,
"has_more": false
}
此工具對於以下情況特別有用:
- 在合併前審查 PR 中的所有更改
- 瞭解 PR 的開發歷史
- 檢查提交消息的質量
- 驗證更改的作者身份
- 通過提交計數分析 PR 的複雜性
獲取拉取請求差異
獲取拉取請求的差異/更改,並具有可選的篩選功能:
// 獲取完整差異(默認行為)
{
"tool": "get_pull_request_diff",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"context_lines": 5 // 可選 (默認: 3)
}
}
// 排除特定文件類型
{
"tool": "get_pull_request_diff",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"exclude_patterns": ["*.lock", "*.svg", "node_modules/**", "*.min.js"]
}
}
// 僅包含特定文件類型
{
"tool": "get_pull_request_diff",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"include_patterns": ["*.res", "*.resi", "src/**/*.js"]
}
}
// 僅獲取特定文件的差異
{
"tool": "get_pull_request_diff",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"file_path": "src/components/Button.res"
}
}
// 組合篩選器
{
"tool": "get_pull_request_diff",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"include_patterns": ["src/**/*"],
"exclude_patterns": ["*.test.js", "*.spec.js"]
}
}
篩選選項:
include_patterns
:要包含的 glob 模式數組(白名單)exclude_patterns
:要排除的 glob 模式數組(黑名單)file_path
:僅獲取特定文件的差異- 模式支持標準 glob 語法(例如,
*.js
,src/**/*.res
,!test/**
)
響應包含篩選元數據:
{
"message": "Pull request diff retrieved successfully",
"pull_request_id": 123,
"diff": "..filtered diff content..",
"filter_metadata": {
"total_files": 15,
"included_files": 12,
"excluded_files": 3,
"excluded_file_list": ["package-lock.json", "logo.svg", "yarn.lock"],
"filters_applied": {
"exclude_patterns": ["*.lock", "*.svg"]
}
}
}
批准拉取請求
{
"tool": "approve_pull_request",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123
}
}
請求更改
{
"tool": "request_changes",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"pull_request_id": 123,
"comment": "Please address the following issues..." // 可選
}
}
列出目錄內容
{
"tool": "list_directory_content",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"path": "src/components", // 可選 (默認為根目錄)
"branch": "main" // 可選 (默認為默認分支)
}
}
返回目錄列表,包含:
- 路徑和分支信息
- 內容數組,包含:
- 名稱
- 類型(文件或目錄)
- 大小(對於文件)
- 完整路徑
- 總項目數
獲取文件內容
{
"tool": "get_file_content",
"arguments": {
"workspace": "PROJ",
"repository": "my-repo",
"file_path": "src/index.ts",
"branch": "main", // 可選 (默認為默認分支)
"start_line": 1, // 可選: 起始行 (基於 1,負數表示從末尾開始)
"line_count": 100, // 可選: 返回的行數
"full_content": false // 可選: 強制獲取完整內容 (默認: false)
}
}
智能截斷功能:
- 自動截斷大文件(>50KB)以防止令牌過載
- 根據文件類型的默認行數:
- 配置文件(.yml,.json):200 行
- 文檔文件(.md,.txt):300 行
- 代碼文件(.ts,.js,.py):500 行
- 日誌文件:最後 100 行
- 使用
start_line: -50
獲取最後 50 行(尾部功能) - 大於 1MB 的文件需要顯式
full_content: true
或行參數
返回文件內容,包含:
- 文件路徑和分支
- 文件大小和編碼
- 內容(根據參數為完整或截斷)
- 行信息(如果截斷):
- 文件中的總行數
- 返回的行範圍
- 截斷指示符
- 最後修改信息(提交、作者、日期)
示例響應:
// 小文件 - 返回完整內容
{
"file_path": "package.json",
"branch": "main",
"size": 1234,
"encoding": "utf-8",
"content": "{\n \"name\": \"my-project\",\n ...",
"last_modified": {
"commit_id": "abc123",
"author": "John Doe",
"date": "2025-01-21T10:00:00Z"
}
}
// 大文件 - 自動截斷
{
"file_path": "src/components/LargeComponent.tsx",
"branch": "main",
"size": 125000,
"encoding": "utf-8",
"content": "... first 500 lines ...",
"line_info": {
"total_lines": 3500,
"returned_lines": {
"start": 1,
"end": 500
},
"truncated": true,
"message": "Showing lines 1-500 of 3500. File size: 122.1KB"
}
}
高級用法
在實際開發中,你可以根據具體需求組合使用這些工具,以實現更復雜的功能。例如,結合 list_pull_requests
和 get_pull_request_diff
工具,先列出符合條件的拉取請求,再獲取特定拉取請求的差異信息,從而進行更細緻的代碼審查。
🔧 技術細節
本項目使用 Node.js 構建,並使用 TypeScript 進行類型檢查,以確保代碼的健壯性和可維護性。通過與 Bitbucket API 交互,實現了各種工具的功能。在處理大文件時,採用了智能截斷的策略,避免因文件過大導致的性能問題。同時,在身份驗證方面,使用 Bitbucket 應用密碼,提供了安全可靠的認證方式。
📄 許可證
本項目採用 MIT 許可證。






精選MCP服務推薦







