list_workspaces
Retrieve all Bitbucket workspaces accessible to your user account to manage repositories and collaboration projects.
Instructions
List all workspaces accessible by the current user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main handler function that fetches the list of workspaces from the Bitbucket API using axios, formats them into a markdown list, and returns a structured content response. Handles errors gracefully.export async function listWorkspaces( axiosInstance: AxiosInstance, config: Config, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { try { const response = await axiosInstance.get< BitbucketPaginatedResponse<BitbucketWorkspace> >(`/workspaces`); const workspaces = response.data.values; const summary = `Found ${workspaces.length} workspaces.`; const workspaceList = workspaces .map( workspace => `**${workspace.name}** - Slug: ${workspace.slug} - Private: ${workspace.is_private}` ) .join('\n\n'); return { content: [ { type: 'text', text: `${summary}\n\n${workspaceList}`, }, ], }; } catch (error) { console.error('Error fetching workspaces:', error); return { content: [ { type: 'text', text: `Error fetching workspaces: ${ error instanceof Error ? error.message : 'Unknown error' }`, }, ], }; } }
- The tool's metadata definition, including the exact name 'list_workspaces', description, and input schema (no parameters required).export const listWorkspacesTool = { name: 'list_workspaces', description: 'List all workspaces accessible by the current user.', inputSchema: { type: 'object', properties: {}, }, };
- src/index.ts:111-136 (registration)Registration of listWorkspacesTool in the tools array returned by the ListToolsRequest handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ // Repositories listRepositoriesTool, getRepositoryDetailsTool, // Commits listCommitsTool, getCommitTool, // Branching Model updateRepositoryBranchingModelSettingsTool, updateProjectBranchingModelSettingsTool, listBranchRestrictionsTool, getBranchRestrictionTool, // Projects getProjectTool, listDefaultReviewersTool, // Pull Requests listPullRequestsTool, getPullRequestTool, createPullRequestTool, updatePullRequestTool, // Workspaces listWorkspacesTool, ], }));
- src/index.ts:143-173 (registration)Registration of the 'list_workspaces' tool name mapped to the listWorkspaces handler function in the CallToolRequest handler's dispatch map.string, ( axiosInstance: AxiosInstance, config: Config, args: any ) => Promise<{ content: Array<{ type: string; text: string }> }> > = { // Repositories list_repositories: listRepositories, get_repository_details: getRepositoryDetails, // Commits list_commits: listCommits, get_commit: getCommit, // Branching Model update_repository_branching_model_settings: updateRepositoryBranchingModelSettings, update_project_branching_model_settings: updateProjectBranchingModelSettings, list_branch_restrictions: listBranchRestrictions, get_branch_restriction: getBranchRestriction, // Projects get_project: getProject, list_default_reviewers: listDefaultReviewers, // Pull Requests list_pull_requests: listPullRequests, get_pull_request: getPullRequest, create_pull_request: createPullRequest, update_pull_request: updatePullRequest, // Workspaces list_workspaces: listWorkspaces, };
- src/index.ts:71-74 (registration)Import statement that brings in the handler function and tool schema from the implementation file.import { listWorkspaces, listWorkspacesTool, } from './tools/workspaces/listWorkspaces.js';