cli / mcp for bitbucket
1import {
2 getPipeline,
3 getPipelineStepLog,
4 listPipelines,
5 triggerPipeline,
6} from '@bitbucket-tool/core';
7import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
8import {
9 getPipelineSchema,
10 getPipelineStepLogSchema,
11 listPipelinesSchema,
12 triggerPipelineSchema,
13} from '../schemas/pipeline.schemas';
14import { resolveWorkspace, resultToResponse } from './helpers';
15
16export const registerPipelineTools = (server: McpServer): void => {
17 server.tool(
18 'list_pipelines',
19 'List recent pipelines for a repository. Returns pipeline UUIDs, status, and trigger info.',
20 listPipelinesSchema,
21 { readOnlyHint: true },
22 async ({ workspace, repo_slug, page, pagelen }) => {
23 const w = resolveWorkspace(workspace);
24 return resultToResponse(
25 await listPipelines({ workspace: w, repoSlug: repo_slug, page, pagelen })
26 );
27 }
28 );
29
30 server.tool(
31 'get_pipeline',
32 'Get details of a specific pipeline including steps, status, and duration. Use list_pipelines to find pipeline UUIDs.',
33 getPipelineSchema,
34 { readOnlyHint: true },
35 async ({ workspace, repo_slug, pipeline_uuid }) => {
36 const w = resolveWorkspace(workspace);
37 return resultToResponse(
38 await getPipeline({ workspace: w, repoSlug: repo_slug, pipelineUuid: pipeline_uuid })
39 );
40 }
41 );
42
43 server.tool(
44 'get_pipeline_step_log',
45 'Get the log output of a specific pipeline step. Returns raw text. Use get_pipeline to find step UUIDs.',
46 getPipelineStepLogSchema,
47 { readOnlyHint: true },
48 async ({ workspace, repo_slug, pipeline_uuid, step_uuid }) => {
49 const w = resolveWorkspace(workspace);
50 const result = await getPipelineStepLog({
51 workspace: w,
52 repoSlug: repo_slug,
53 pipelineUuid: pipeline_uuid,
54 stepUuid: step_uuid,
55 });
56
57 return resultToResponse(result, (log) => log);
58 }
59 );
60
61 // @ts-expect-error TS2589: MCP SDK overload resolution + transitive generated types exceed TypeScript recursion limit
62 server.tool(
63 'trigger_pipeline',
64 'Trigger a new pipeline run on a branch or tag. Optionally specify a custom pipeline pattern.',
65 triggerPipelineSchema,
66 { readOnlyHint: false },
67 async ({ workspace, repo_slug, ref_name, ref_type, pattern }) => {
68 const w = resolveWorkspace(workspace);
69 return resultToResponse(
70 await triggerPipeline({
71 workspace: w,
72 repoSlug: repo_slug,
73 target: {
74 type: 'pipeline_ref_target',
75 ref_type: ref_type ?? 'branch',
76 ref_name,
77 ...(pattern ? { selector: { type: 'custom' as const, pattern } } : {}),
78 },
79 })
80 );
81 }
82 );
83};