78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
using LazyBear.Confluence;
|
||
using ModelContextProtocol.Server;
|
||
|
||
namespace LazyBear.Confluence.Search;
|
||
|
||
[McpServerToolType]
|
||
public sealed class ConfluenceSearchTools(ConfluenceHttpClientProvider provider)
|
||
{
|
||
private readonly ConfluenceHttpClientProvider _provider = provider;
|
||
|
||
[McpServerTool, Description("Поиск страниц Confluence")]
|
||
public async Task<string> SearchPagesAsync(
|
||
[Description("Запрос")] string query,
|
||
[Description("Пространство")] string? spaceKey = null,
|
||
[Description("Типы")] string[]? types = null,
|
||
[Description("Максимум")] int? limit = 20,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(query))
|
||
{
|
||
return "query не задан.";
|
||
}
|
||
|
||
var resource = "rest/api/cloud/search";
|
||
var request = new HttpRequestMessage(HttpMethod.Get, resource);
|
||
request.AddQueryParameter("cql", query);
|
||
request.AddQueryParameter("limit", limit?.ToString() ?? "20");
|
||
request.AddQueryParameter("spaceKeys", spaceKey ?? "ALL");
|
||
if (types != null)
|
||
{
|
||
foreach (var type in types)
|
||
{
|
||
request.AddQueryParameter("type", type);
|
||
}
|
||
}
|
||
|
||
return $"Поиск: {query} (spaces={spaceKey}, types={string.Join(",", types)})";
|
||
}
|
||
|
||
[McpServerTool, Description("Краулинг пространства Confluence")]
|
||
public async Task<string> CrawlSpaceAsync(
|
||
[Description("Пространство")] string spaceKey,
|
||
[Description("Максимум страниц")] int? limit = 100,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(spaceKey))
|
||
{
|
||
return "spaceKey не задан.";
|
||
}
|
||
|
||
string CrawlPagesList(string spaceKey, int? limit)
|
||
{
|
||
return $"Краулинг пространства {spaceKey} с лимитом {limit?.ToString() ?? "100"}";
|
||
}
|
||
|
||
string CrawlResult(string crawlResult)
|
||
{
|
||
return $"Краулинг завершён. Результат: {crawlResult}";
|
||
}
|
||
|
||
var crawlResult = CrawlPagesList(spaceKey, limit);
|
||
return CrawlResult(crawlResult);
|
||
}
|
||
|
||
[McpServerTool, Description("Искать битые ссылки Confluence")]
|
||
public async Task<string> FindBrokenLinksAsync(
|
||
[Description("Пространство")] string spaceKey,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(spaceKey))
|
||
{
|
||
return "spaceKey не задан.";
|
||
}
|
||
|
||
return $"Поиск битых ссылок в {spaceKey}";
|
||
}
|
||
}
|