Bitbucket POST Request
bb_postCreate Bitbucket pull requests, comments, approvals, and merges via REST API calls. Reduce token costs by filtering response fields with JMESPath expressions for efficient data extraction.
Instructions
Create Bitbucket resources. Returns TOON format by default (token-efficient).
IMPORTANT - Cost Optimization:
Use
jqparam to extract only needed fields from response (e.g.,jq: "{id: id, title: title}")Unfiltered responses include all metadata and are expensive!
Output format: TOON (default) or JSON (outputFormat: "json")
Common operations:
Create PR:
/repositories/{workspace}/{repo}/pullrequestsbody:{"title": "...", "source": {"branch": {"name": "feature"}}, "destination": {"branch": {"name": "main"}}}Add PR comment:
/repositories/{workspace}/{repo}/pullrequests/{id}/commentsbody:{"content": {"raw": "Comment text"}}Approve PR:
/repositories/{workspace}/{repo}/pullrequests/{id}/approvebody:{}Request changes:
/repositories/{workspace}/{repo}/pullrequests/{id}/request-changesbody:{}Merge PR:
/repositories/{workspace}/{repo}/pullrequests/{id}/mergebody:{"merge_strategy": "squash"}(strategies: merge_commit, squash, fast_forward)
The /2.0 prefix is added automatically. API reference: https://developer.atlassian.com/cloud/bitbucket/rest/
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The Bitbucket API endpoint path (without base URL). Must start with "/". Examples: "/workspaces", "/repositories/{workspace}/{repo_slug}", "/repositories/{workspace}/{repo_slug}/pullrequests/{id}" | |
| queryParams | No | Optional query parameters as key-value pairs. Examples: {"pagelen": "25", "page": "2", "q": "state=\"OPEN\"", "fields": "values.title,values.state"} | |
| jq | No | JMESPath expression to filter/transform the response. IMPORTANT: Always use this to extract only needed fields and reduce token costs. Examples: "values[*].{name: name, slug: slug}" (extract specific fields), "values[0]" (first result), "values[*].name" (names only). See https://jmespath.org | |
| outputFormat | No | Output format: "toon" (default, 30-60% fewer tokens) or "json". TOON is optimized for LLMs with tabular arrays and minimal syntax. | |
| body | Yes | Request body as a JSON object. Structure depends on the endpoint. Example for PR: {"title": "My PR", "source": {"branch": {"name": "feature"}}} |
Implementation Reference
- Core handler for bb_post - delegates to handleRequest with 'POST' method, executing the actual Bitbucket API POST request
export async function handlePost( options: RequestWithBodyArgsType, ): Promise<ControllerResponse> { return handleRequest('POST', options); } - Shared request handler that normalizes the path, fetches Atlassian API, applies JQ filtering, and formats output (TOON/JSON)
async function handleRequest( method: HttpMethod, options: RequestWithBodyOptions, ): Promise<ControllerResponse> { const methodLogger = logger.forMethod(`handle${method}`); try { methodLogger.debug(`Making ${method} request`, { path: options.path, ...(options.body && { bodyKeys: Object.keys(options.body) }), }); // Get credentials const credentials = getAtlassianCredentials(); if (!credentials) { throw createAuthMissingError(); } // Normalize path and append query params let path = normalizePath(options.path); path = appendQueryParams(path, options.queryParams); methodLogger.debug(`${method}ing: ${path}`); const fetchOptions: { method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; body?: Record<string, unknown>; } = { method, }; // Add body for methods that support it if (options.body && ['POST', 'PUT', 'PATCH'].includes(method)) { fetchOptions.body = options.body; } const response = await fetchAtlassian<unknown>( credentials, path, fetchOptions, ); methodLogger.debug('Successfully received response'); // Apply JQ filter if provided, otherwise return raw data const result = applyJqFilter(response.data, options.jq); // Convert to output format (TOON by default, JSON if requested) const useToon = options.outputFormat !== 'json'; const content = await toOutputString(result, useToon); return { content, rawResponsePath: response.rawResponsePath, }; } catch (error) { throw handleControllerError(error, { entityType: 'API', operation: `${method} request`, source: `controllers/atlassian.api.controller.ts@handle${method}`, additionalInfo: { path: options.path }, }); } } - src/tools/atlassian.api.tool.ts:274-288 (registration)Registration of the 'bb_post' tool on the MCP server with title, description, input schema, annotations, and handler
server.registerTool( 'bb_post', { title: 'Bitbucket POST Request', description: BB_POST_DESCRIPTION, inputSchema: RequestWithBodyArgs, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, }, post, ); - Zod schema defining bb_post input arguments: path (required string), queryParams, jq filter, outputFormat, and body (record of unknown)
export const RequestWithBodyArgs = z.object({ ...BaseApiToolArgs, body: bodyField, }); export type RequestWithBodyArgsType = z.infer<typeof RequestWithBodyArgs>; /** * Schema for bb_post tool arguments (POST requests) */ export const PostApiToolArgs = RequestWithBodyArgs; export type PostApiToolArgsType = RequestWithBodyArgsType; - Factory function that creates the MCP tool handler wrapper for POST/PUT/PATCH, parsing args, calling the controller, truncating response, and formatting errors
function createWriteHandler( methodName: string, handler: ( options: RequestWithBodyArgsType, ) => Promise<{ content: string; rawResponsePath?: string | null }>, ) { return async (args: Record<string, unknown>) => { const methodLogger = Logger.forContext( 'tools/atlassian.api.tool.ts', methodName.toLowerCase(), ); methodLogger.debug(`Making ${methodName} request with args:`, { path: args.path, bodyKeys: args.body ? Object.keys(args.body as object) : [], }); try { const result = await handler(args as RequestWithBodyArgsType); methodLogger.debug( 'Successfully received response from controller', ); return { content: [ { type: 'text' as const, text: truncateForAI( result.content, result.rawResponsePath, ), }, ], }; } catch (error) { methodLogger.error(`Failed to make ${methodName} request`, error); return formatErrorForMcpTool(error); } }; }