@aashari/mcp-server-atlassian-bitbucket
Version:
Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MC
48 lines (47 loc) • 1.83 kB
JavaScript
;
/**
* Utilities for formatting and handling query parameters for the Bitbucket API.
* These functions help convert user-friendly query strings into the format expected by Bitbucket's REST API.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatBitbucketQuery = formatBitbucketQuery;
/**
* Format a simple text query into Bitbucket's query syntax
* Bitbucket API expects query parameters in a specific format for the 'q' parameter
*
* @param query - The search query string
* @param field - Optional field to search in, defaults to 'name'
* @returns Formatted query string for Bitbucket API
*
* @example
* // Simple text search (returns: name ~ "vue3")
* formatBitbucketQuery("vue3")
*
* @example
* // Already formatted query (returns unchanged: name = "repository")
* formatBitbucketQuery("name = \"repository\"")
*
* @example
* // With specific field (returns: description ~ "API")
* formatBitbucketQuery("API", "description")
*/
function formatBitbucketQuery(query, field = 'name') {
// If the query is empty, return it as is
if (!query || query.trim() === '') {
return query;
}
// Regular expression to check if the query already contains operators
// like ~, =, !=, >, <, etc., which would indicate it's already formatted
const operatorPattern = /[~=!<>]/;
// If the query already contains operators, assume it's properly formatted
if (operatorPattern.test(query)) {
return query;
}
// If query is quoted, assume it's an exact match
if (query.startsWith('"') && query.endsWith('"')) {
return `${field} ~ ${query}`;
}
// Format simple text as a field search with fuzzy match
// Wrap in double quotes to handle spaces and special characters
return `${field} ~ "${query}"`;
}