get_confluence_labels
Retrieve labels from a Confluence page to understand its categorization and identify 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
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pageId | Yes | ID of the page |
Implementation Reference
- Handler function for get_confluence_labels tool that validates pageId, fetches labels using ConfluenceClient, simplifies the response, and returns JSON-formatted content.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 and description definition for the get_confluence_labels tool.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-264 (registration)Tool registration and dispatch logic in the main CallToolRequestSchema switch statement.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 });
- ConfluenceClient helper method that makes the actual API call to retrieve paginated labels for a page.async getConfluenceLabels(pageId: string): Promise<PaginatedResponse<Label>> { const response = await this.v2Client.get(`/pages/${pageId}/labels`); return response.data; }