mcp-server-bitbucket 0.11.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.
package/src/types.ts ADDED
@@ -0,0 +1,369 @@
1
+ /**
2
+ * Type definitions for Bitbucket MCP Server
3
+ */
4
+
5
+ // ==================== CONFIGURATION ====================
6
+
7
+ export interface BitbucketConfig {
8
+ workspace: string;
9
+ email: string;
10
+ apiToken: string;
11
+ timeout?: number;
12
+ maxRetries?: number;
13
+ }
14
+
15
+ // ==================== API RESPONSE TYPES ====================
16
+
17
+ export interface BitbucketUser {
18
+ display_name: string;
19
+ uuid: string;
20
+ account_id?: string;
21
+ links?: {
22
+ avatar?: { href: string };
23
+ html?: { href: string };
24
+ };
25
+ }
26
+
27
+ export interface BitbucketProject {
28
+ key: string;
29
+ name: string;
30
+ description?: string;
31
+ uuid?: string;
32
+ links?: {
33
+ html?: { href: string };
34
+ };
35
+ }
36
+
37
+ export interface CloneLink {
38
+ name: string;
39
+ href: string;
40
+ }
41
+
42
+ export interface BitbucketRepository {
43
+ uuid: string;
44
+ name: string;
45
+ full_name: string;
46
+ description?: string;
47
+ is_private: boolean;
48
+ project?: BitbucketProject;
49
+ mainbranch?: { name: string };
50
+ links?: {
51
+ clone?: CloneLink[];
52
+ html?: { href: string };
53
+ };
54
+ created_on?: string;
55
+ updated_on?: string;
56
+ }
57
+
58
+ export interface BitbucketBranch {
59
+ name: string;
60
+ target?: {
61
+ hash: string;
62
+ message?: string;
63
+ author?: {
64
+ raw?: string;
65
+ user?: BitbucketUser;
66
+ };
67
+ date?: string;
68
+ };
69
+ }
70
+
71
+ export interface BitbucketCommit {
72
+ hash: string;
73
+ message?: string;
74
+ author?: {
75
+ raw?: string;
76
+ user?: BitbucketUser;
77
+ };
78
+ date?: string;
79
+ parents?: { hash: string }[];
80
+ }
81
+
82
+ export interface BitbucketPullRequest {
83
+ id: number;
84
+ title: string;
85
+ description?: string;
86
+ state: 'OPEN' | 'MERGED' | 'DECLINED' | 'SUPERSEDED';
87
+ author?: BitbucketUser;
88
+ source?: {
89
+ branch?: { name: string };
90
+ commit?: { hash: string };
91
+ };
92
+ destination?: {
93
+ branch?: { name: string };
94
+ commit?: { hash: string };
95
+ };
96
+ reviewers?: BitbucketUser[];
97
+ participants?: {
98
+ user: BitbucketUser;
99
+ approved: boolean;
100
+ role: string;
101
+ }[];
102
+ close_source_branch?: boolean;
103
+ merge_commit?: { hash: string };
104
+ created_on?: string;
105
+ updated_on?: string;
106
+ links?: {
107
+ html?: { href: string };
108
+ diff?: { href: string };
109
+ };
110
+ }
111
+
112
+ export interface BitbucketPipeline {
113
+ uuid: string;
114
+ build_number?: number;
115
+ state?: {
116
+ name: string;
117
+ result?: { name: string };
118
+ };
119
+ target?: {
120
+ ref_name?: string;
121
+ ref_type?: string;
122
+ };
123
+ created_on?: string;
124
+ completed_on?: string;
125
+ duration_in_seconds?: number;
126
+ }
127
+
128
+ export interface BitbucketPipelineStep {
129
+ uuid: string;
130
+ name?: string;
131
+ state?: {
132
+ name: string;
133
+ result?: { name: string };
134
+ };
135
+ started_on?: string;
136
+ completed_on?: string;
137
+ duration_in_seconds?: number;
138
+ }
139
+
140
+ export interface BitbucketPipelineVariable {
141
+ uuid: string;
142
+ key: string;
143
+ value?: string;
144
+ secured: boolean;
145
+ }
146
+
147
+ // ==================== PIPELINE TRIGGER OPTIONS ====================
148
+
149
+ export interface PipelineTriggerVariable {
150
+ key: string;
151
+ value: string;
152
+ secured?: boolean;
153
+ }
154
+
155
+ export interface TriggerPipelineOptions {
156
+ branch?: string;
157
+ commit?: string;
158
+ customPipeline?: string;
159
+ variables?: PipelineTriggerVariable[] | Record<string, string>;
160
+ }
161
+
162
+ export interface BitbucketEnvironment {
163
+ uuid: string;
164
+ name: string;
165
+ environment_type?: { name: string };
166
+ rank?: number;
167
+ restrictions?: unknown;
168
+ lock?: unknown;
169
+ }
170
+
171
+ export interface BitbucketDeployment {
172
+ uuid: string;
173
+ environment?: BitbucketEnvironment;
174
+ state?: {
175
+ name: string;
176
+ started_on?: string;
177
+ completed_on?: string;
178
+ };
179
+ release?: {
180
+ commit?: { hash: string };
181
+ pipeline?: { uuid: string };
182
+ };
183
+ }
184
+
185
+ export interface BitbucketWebhook {
186
+ uuid: string;
187
+ url: string;
188
+ description?: string;
189
+ events: string[];
190
+ active: boolean;
191
+ created_at?: string;
192
+ }
193
+
194
+ export interface BitbucketTag {
195
+ name: string;
196
+ message?: string;
197
+ target?: {
198
+ hash: string;
199
+ date?: string;
200
+ };
201
+ tagger?: {
202
+ raw?: string;
203
+ date?: string;
204
+ };
205
+ }
206
+
207
+ export interface BitbucketBranchRestriction {
208
+ id: number;
209
+ kind: string;
210
+ pattern?: string;
211
+ branch_match_kind?: string;
212
+ branch_type?: string;
213
+ value?: number;
214
+ users?: BitbucketUser[];
215
+ groups?: BitbucketGroup[];
216
+ }
217
+
218
+ export interface BitbucketGroup {
219
+ slug: string;
220
+ name: string;
221
+ }
222
+
223
+ export interface BitbucketComment {
224
+ id: number;
225
+ content?: {
226
+ raw?: string;
227
+ markup?: string;
228
+ html?: string;
229
+ };
230
+ user?: BitbucketUser;
231
+ created_on?: string;
232
+ updated_on?: string;
233
+ inline?: {
234
+ path?: string;
235
+ from?: number;
236
+ to?: number;
237
+ };
238
+ }
239
+
240
+ export interface BitbucketCommitStatus {
241
+ key: string;
242
+ state: 'SUCCESSFUL' | 'FAILED' | 'INPROGRESS' | 'STOPPED';
243
+ name?: string;
244
+ description?: string;
245
+ url?: string;
246
+ created_on?: string;
247
+ updated_on?: string;
248
+ }
249
+
250
+ export interface DirectoryEntry {
251
+ path: string;
252
+ type: 'commit_file' | 'commit_directory';
253
+ size?: number;
254
+ }
255
+
256
+ export interface UserPermission {
257
+ user: BitbucketUser;
258
+ permission: 'read' | 'write' | 'admin';
259
+ }
260
+
261
+ export interface GroupPermission {
262
+ group: BitbucketGroup;
263
+ permission: 'read' | 'write' | 'admin';
264
+ }
265
+
266
+ // ==================== PAGINATED RESPONSE ====================
267
+
268
+ export interface PaginatedResponse<T> {
269
+ values: T[];
270
+ page?: number;
271
+ pagelen?: number;
272
+ size?: number;
273
+ next?: string;
274
+ previous?: string;
275
+ }
276
+
277
+ // ==================== TOOL RESPONSE TYPES ====================
278
+
279
+ export interface RepositorySummary {
280
+ name: string;
281
+ full_name: string;
282
+ private: boolean;
283
+ project?: string;
284
+ description?: string;
285
+ }
286
+
287
+ export interface RepositoryDetail extends RepositorySummary {
288
+ clone_urls: {
289
+ https?: string;
290
+ ssh?: string;
291
+ html?: string;
292
+ };
293
+ main_branch?: string;
294
+ created?: string;
295
+ updated?: string;
296
+ }
297
+
298
+ export interface PullRequestSummary {
299
+ id: number;
300
+ title: string;
301
+ state: string;
302
+ author?: string;
303
+ source_branch?: string;
304
+ destination_branch?: string;
305
+ url?: string;
306
+ }
307
+
308
+ export interface PullRequestDetail extends PullRequestSummary {
309
+ description?: string;
310
+ reviewers?: string[];
311
+ approvals?: number;
312
+ created?: string;
313
+ updated?: string;
314
+ }
315
+
316
+ export interface PipelineSummary {
317
+ uuid: string;
318
+ build_number?: number;
319
+ state?: string;
320
+ result?: string;
321
+ branch?: string;
322
+ created?: string;
323
+ }
324
+
325
+ export interface PipelineDetail extends PipelineSummary {
326
+ duration?: number;
327
+ completed?: string;
328
+ }
329
+
330
+ export interface BranchSummary {
331
+ name: string;
332
+ commit?: string;
333
+ message?: string;
334
+ date?: string;
335
+ }
336
+
337
+ export interface CommitSummary {
338
+ hash: string;
339
+ message?: string;
340
+ author?: string;
341
+ date?: string;
342
+ }
343
+
344
+ export interface CommitDetail extends CommitSummary {
345
+ parents?: string[];
346
+ }
347
+
348
+ // ==================== ENUMS ====================
349
+
350
+ export enum PRState {
351
+ OPEN = 'OPEN',
352
+ MERGED = 'MERGED',
353
+ DECLINED = 'DECLINED',
354
+ SUPERSEDED = 'SUPERSEDED',
355
+ }
356
+
357
+ export enum MergeStrategy {
358
+ MERGE_COMMIT = 'merge_commit',
359
+ SQUASH = 'squash',
360
+ FAST_FORWARD = 'fast_forward',
361
+ }
362
+
363
+ export enum CommitStatusState {
364
+ SUCCESSFUL = 'SUCCESSFUL',
365
+ FAILED = 'FAILED',
366
+ INPROGRESS = 'INPROGRESS',
367
+ STOPPED = 'STOPPED',
368
+ }
369
+
package/src/utils.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Utility functions for Bitbucket MCP Server
3
+ */
4
+
5
+ /**
6
+ * Ensure a UUID has braces around it (Bitbucket API requirement)
7
+ */
8
+ export function ensureUuidBraces(uuid: string): string {
9
+ if (!uuid) return uuid;
10
+ if (uuid.startsWith('{') && uuid.endsWith('}')) {
11
+ return uuid;
12
+ }
13
+ return `{${uuid}}`;
14
+ }
15
+
16
+ /**
17
+ * Remove braces from a UUID
18
+ */
19
+ export function removeUuidBraces(uuid: string): string {
20
+ if (!uuid) return uuid;
21
+ return uuid.replace(/^{|}$/g, '');
22
+ }
23
+
24
+ /**
25
+ * Truncate a hash to short form (7 characters)
26
+ */
27
+ export function truncateHash(hash: string | undefined | null): string {
28
+ if (!hash) return '';
29
+ return hash.substring(0, 7);
30
+ }
31
+
32
+ /**
33
+ * Sanitize a search term to prevent BQL injection
34
+ */
35
+ export function sanitizeSearchTerm(term: string): string {
36
+ // Remove or escape special characters that could be used for BQL injection
37
+ return term.replace(/["\\]/g, '').trim();
38
+ }
39
+
40
+ /**
41
+ * Validate and clamp a limit parameter
42
+ */
43
+ export function validateLimit(limit: number, maxLimit: number = 100): number {
44
+ if (limit < 1) return 1;
45
+ if (limit > maxLimit) return maxLimit;
46
+ return limit;
47
+ }
48
+
49
+ /**
50
+ * Create a "not found" response object
51
+ */
52
+ export function notFoundResponse(type: string, identifier: string): Record<string, unknown> {
53
+ return {
54
+ error: `${type} '${identifier}' not found`,
55
+ found: false,
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Format a timestamp string, truncating to date only if needed
61
+ */
62
+ export function formatTimestamp(timestamp: string | undefined | null): string | null {
63
+ if (!timestamp) return null;
64
+ // Return ISO format truncated to seconds
65
+ return timestamp.split('.')[0];
66
+ }
67
+
68
+ /**
69
+ * Extract a URL from Bitbucket links structure
70
+ */
71
+ export function extractUrl(links: Record<string, unknown> | undefined, key: string = 'html'): string {
72
+ if (!links) return '';
73
+ const link = links[key] as { href?: string } | undefined;
74
+ return link?.href || '';
75
+ }
76
+
77
+ /**
78
+ * Sleep for a specified duration (for rate limiting retries)
79
+ */
80
+ export function sleep(ms: number): Promise<void> {
81
+ return new Promise(resolve => setTimeout(resolve, ms));
82
+ }
83
+
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noImplicitReturns": true,
20
+ "noFallthroughCasesInSwitch": true
21
+ },
22
+ "include": ["src/**/*"],
23
+ "exclude": ["node_modules", "dist", "tests"]
24
+ }
25
+