sozsoft-platform/api/modules/Sozsoft.Mcp/Sozsoft.Mcp.HttpApi/Tools/McpDataTools.cs
2026-09-10 17:40:43 +03:00

58 lines
2.5 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using ModelContextProtocol.Server;
using Sozsoft.Mcp.Dtos;
namespace Sozsoft.Mcp.Tools;
/// <summary>
/// Veri yazma araclari. Yazma bir ListForm ekraninin sozlesmesinden gecer; ekran yetkisi ve
/// tenant filtresi aynen uygulanir. Sunucu kaydinda <c>AllowWrite</c> kapaliysa bu araclar
/// arac listesinde hic gorunmez.
/// </summary>
[McpServerToolType]
public sealed class McpDataTools(IMcpDataAppService dataAppService)
{
[McpServerTool(Name = McpToolNames.InsertRow, Destructive = false, Idempotent = false)]
[Description("Bir listeye yeni kayit ekler. Alan adlari describe_list cikisindaki field degerleridir.")]
public async Task<McpWriteResultDto> InsertRowAsync(
[Description("Kaydin eklenecegi listenin kodu.")]
string listFormCode,
[Description("Alan adi -> deger eslemesi.")]
Dictionary<string, object?> values)
=> await dataAppService.InsertRowAsync(new McpRowRequestDto
{
ListFormCode = listFormCode,
Values = values ?? []
});
[McpServerTool(Name = McpToolNames.UpdateRow, Destructive = true, Idempotent = true)]
[Description("Bir listedeki kaydi anahtar degerine gore gunceller. Yalnizca verilen alanlar yazilir.")]
public async Task<McpWriteResultDto> UpdateRowAsync(
[Description("Kaydin bulundugu listenin kodu.")]
string listFormCode,
[Description("Guncellenecek kaydin anahtar alan degeri; describe_list cikisindaki keyFieldName alanina karsilik gelir.")]
List<object?> keys,
[Description("Alan adi -> yeni deger eslemesi.")]
Dictionary<string, object?> values)
=> await dataAppService.UpdateRowAsync(new McpRowRequestDto
{
ListFormCode = listFormCode,
Keys = keys ?? [],
Values = values ?? []
});
[McpServerTool(Name = McpToolNames.DeleteRow, Destructive = true, Idempotent = true)]
[Description("Bir listedeki kaydi anahtar degerine gore siler. Ekranin kendi silme komutu kullanilir; soft delete tasiyan tablolarda kayit pasife cekilir.")]
public async Task<McpWriteResultDto> DeleteRowAsync(
[Description("Kaydin bulundugu listenin kodu.")]
string listFormCode,
[Description("Silinecek kaydin anahtar alan degeri.")]
List<object?> keys)
=> await dataAppService.DeleteRowAsync(new McpRowRequestDto
{
ListFormCode = listFormCode,
Keys = keys ?? []
});
}