get_confluence_labels
Retrieve labels assigned to a Confluence page to understand its categorization and discover related content through shared labels.
Instructions
Get labels for a page. Use this to understand page categorization and find related content through common labels.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | ID of the page |
Implementation Reference
- The main handler function `handleGetConfluenceLabels` that executes the tool logic. It takes a ConfluenceClient and { pageId } args, calls client.getConfluenceLabels(pageId), and returns simplified label data (id, name) with pagination info.
export async function handleGetConfluenceLabels( client: ConfluenceClient, args: { pageId: string } ): Promise<{ content: Array<{ type: "text"; text: string }>; }> { try { if (!args.pageId) { throw new McpError(ErrorCode.InvalidParams, "pageId is required"); } const labels = await client.getConfluenceLabels(args.pageId); const simplified = { labels: labels.results.map((label: Label) => ({ id: label.id, name: label.name })), next: labels._links.next ? true : false }; return { content: [ { type: "text", text: JSON.stringify(simplified), }, ], }; } catch (error) { console.error("Error getting labels:", error instanceof Error ? error.message : String(error)); throw new McpError( ErrorCode.InternalError, `Failed to get labels: ${error instanceof Error ? error.message : String(error)}` ); } } - src/schemas/tool-schemas.ts:161-173 (schema)Input schema definition for the 'get_confluence_labels' tool. Describes the tool purpose (get labels for a page) and input schema requiring a 'pageId' string property.
get_confluence_labels: { description: "Get labels for a page. Use this to understand page categorization and find related content through common labels.", inputSchema: { type: "object", properties: { pageId: { type: "string", description: "ID of the page", }, }, required: ["pageId"], }, }, - src/index.ts:261-265 (registration)Registration of the tool in the main server's CallToolRequestSchema handler. Case 'get_confluence_labels' extracts pageId from args, validates it, and calls handleGetConfluenceLabels.
case "get_confluence_labels": { const { pageId } = (args || {}) as { pageId: string }; if (!pageId) throw new McpError(ErrorCode.InvalidParams, "pageId is required"); return await handleGetConfluenceLabels(this.confluenceClient, { pageId }); } - The ConfluenceClient helper method `getConfluenceLabels` that makes the actual HTTP GET request to /pages/{pageId}/labels using the Confluence v2 API client.
async getConfluenceLabels(pageId: string): Promise<PaginatedResponse<Label>> { const response = await this.v2Client.get(`/pages/${pageId}/labels`); return response.data; }