Skip to main content
Glama
Lexmata

Bitbucket Cloud MCP Server

by Lexmata

search_code

Search for code across all repositories in a Bitbucket Cloud workspace to find specific code snippets, functions, or patterns.

Instructions

Search for code across all repositories in a workspace.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspaceYesThe workspace slug
search_queryYesSearch query string
pageNoPage number
pagelenNoResults per page

Implementation Reference

  • The core handler function that performs the Bitbucket API call to search for code in a workspace.
    async searchCode(params: SearchCodeParams): Promise<PaginatedResponse<BitbucketSearchResult>> {
      const { workspace, search_query, ...queryParams } = params;
      return this.client.get<PaginatedResponse<BitbucketSearchResult>>(
        `/workspaces/${workspace}/search/code`,
        {
          search_query,
          ...queryParams,
        } as Record<string, string | number | undefined>
      );
    }
  • Registration of the 'search_code' tool in the toolDefinitions array for MCP, including name, description, and inputSchema.
    {
      name: 'search_code',
      description: 'Search for code across all repositories in a workspace.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          workspace: { type: 'string', description: 'The workspace slug' },
          search_query: { type: 'string', description: 'Search query string' },
          page: { type: 'number', description: 'Page number' },
          pagelen: { type: 'number', description: 'Results per page' },
        },
        required: ['workspace', 'search_query'],
      },
    },
  • Zod schema used for input validation and parsing in the tool handler.
    search_code: z.object({
      workspace: z.string().describe('The workspace slug'),
      search_query: z.string().describe('Search query string'),
      page: z.number().optional().describe('Page number'),
      pagelen: z.number().optional().describe('Results per page'),
    }),
  • Dispatcher logic in ToolHandler.handleTool that parses arguments and delegates to the SearchAPI.searchCode method.
    case 'search_code': {
      const params = toolSchemas.search_code.parse(args);
      return this.search.searchCode(params);
    }
  • TypeScript interface defining the parameters for the search_code tool.
    export interface SearchCodeParams {
      workspace: string;
      search_query: string;
      page?: number;
      pagelen?: number;
    }

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/Lexmata/bitbucket-mcp'

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