Skip to main content
Glama
aashari

Atlassian Bitbucket MCP Server

by aashari

Bitbucket POST Request

bb_post

Create 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 jq param 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:

  1. Create PR: /repositories/{workspace}/{repo}/pullrequests body: {"title": "...", "source": {"branch": {"name": "feature"}}, "destination": {"branch": {"name": "main"}}}

  2. Add PR comment: /repositories/{workspace}/{repo}/pullrequests/{id}/comments body: {"content": {"raw": "Comment text"}}

  3. Approve PR: /repositories/{workspace}/{repo}/pullrequests/{id}/approve body: {}

  4. Request changes: /repositories/{workspace}/{repo}/pullrequests/{id}/request-changes body: {}

  5. Merge PR: /repositories/{workspace}/{repo}/pullrequests/{id}/merge body: {"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

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe Bitbucket API endpoint path (without base URL). Must start with "/". Examples: "/workspaces", "/repositories/{workspace}/{repo_slug}", "/repositories/{workspace}/{repo_slug}/pullrequests/{id}"
queryParamsNoOptional query parameters as key-value pairs. Examples: {"pagelen": "25", "page": "2", "q": "state=\"OPEN\"", "fields": "values.title,values.state"}
jqNoJMESPath 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
outputFormatNoOutput format: "toon" (default, 30-60% fewer tokens) or "json". TOON is optimized for LLMs with tabular arrays and minimal syntax.
bodyYesRequest 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 },
    		});
    	}
    }
  • 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);
    		}
    	};
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description fully discloses behavioral traits: default TOON format, cost optimization via jq, auto-added /2.0 prefix, and output format options. It aligns with annotations (not read-only, not destructive, not idempotent, open-world hint) and adds significant context beyond structured data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement, important cost optimization note, and a list of common operations. It is slightly verbose but front-loaded with key information, making it efficient for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 5 parameters, nested objects, and no output schema, the description is remarkably complete: it covers output formats, cost optimization, common endpoint patterns, and links to the full API reference. No gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite 100% schema description coverage, the description adds substantial meaning: detailed path examples, jq usage with examples, outputFormat benefits, body structure examples for common endpoints. This greatly aids parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Create Bitbucket resources' and provides multiple specific endpoint examples (create PR, add comment, approve, etc.), distinguishing it from sibling tools that handle other HTTP methods.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains when to use the tool (creating resources) and provides common operations with endpoint and body examples. It lacks explicit when-not-to-use or alternative tool references, but the context signals and sibling tool list imply the usage boundaries.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aashari/mcp-server-atlassian-bitbucket'

If you have feedback or need assistance with the MCP directory API, please join our Discord server