using LazyBear.Confluence; using ModelContextProtocol.Server; namespace LazyBear.Confluence.Pages; [McpServerToolType] public sealed class ConfluencePagesTools(ConfluenceHttpClientProvider provider) { private readonly ConfluenceHttpClientProvider _provider = provider; [McpServerTool, Description("Список страниц Confluence")] public async Task ListPagesAsync( [Description("Пространство")] string? spaceKey = null, [Description("ID родитель")] string? parentId = null, [Description("Максимум")] int? limit = 20, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(spaceKey)) { return "spaceKey не задан."; } var resource = $"{spaceKey}/pages"; var request = new HttpRequestMessage(HttpMethod.Get, resource); return $"Список страниц в {spaceKey}"; } [McpServerTool, Description("Получить страницу Confluence")] public async Task GetPageAsync( [Description("ID страницы")] string pageId, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(pageId)) { return "pageId не задан."; } return $"Страница: {pageId}"; } [McpServerTool, Description("Создать страницу")] public async Task CreatePageAsync( [Description("Заголовок")] string title, [Description("Контент")] string content, [Description("Пространство")] string spaceKey, [Description("ID родитель")] string? parentId = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(title)) { return "title не задан."; } var request = new HttpRequestMessage(HttpMethod.Post, $"rest/api/content?typeName=page"); return $"Страница создана: {title}"; } [McpServerTool, Description("Обновить страницу")] public async Task UpdatePageAsync( [Description("ID")] string id, [Description("Заголовок")] string? title = null, [Description("Контент")] string? content = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(id)) { return "id не задан."; } return $"Страница обновлена: {id}"; } [McpServerTool, Description("Удалить страницу")] public async Task DeletePageAsync( [Description("ID страницы")] string pageId, [Description("Перманентно?")] bool? permanent = false, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(pageId)) { return "pageId не задан."; } return $"Страница удалена: {pageId}"; } }