sozsoft-platform/api/modules/Sozsoft.Mcp/Sozsoft.Mcp.HttpApi/Tools/McpDataTools.cs

60 lines
2.6 KiB
C#
Raw Permalink Normal View History

2026-09-17 09:01:14 +00:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
2026-10-10 22:03:36 +00:00
using ModelContextProtocol.Protocol;
2026-09-17 09:01:14 +00:00
using ModelContextProtocol.Server;
using Sozsoft.Mcp.Dtos;
namespace Sozsoft.Mcp.Tools;
/// <summary>
/// Veri yazma araclari. Yazma bir ListForm ekraninin sozlesmesinden gecer; ekran yetkisi ve
2026-09-18 13:47:23 +00:00
/// tenant filtresi aynen uygulanir. Sunucu kaydinda <c>AllowedTools</c> dolu ve bu araclar
/// secili degilse arac listesinde hic gorunmez.
2026-09-17 09:01:14 +00:00
/// </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.")]
2026-10-10 22:03:36 +00:00
public async Task<CallToolResult> InsertRowAsync(
2026-09-17 09:01:14 +00:00
[Description("Kaydin eklenecegi listenin kodu.")]
string listFormCode,
[Description("Alan adi -> deger eslemesi.")]
Dictionary<string, object?> values)
2026-10-10 22:03:36 +00:00
=> McpToolResult.From(await dataAppService.InsertRowAsync(new McpRowRequestDto
2026-09-17 09:01:14 +00:00
{
ListFormCode = listFormCode,
Values = values ?? []
2026-10-10 22:03:36 +00:00
}));
2026-09-17 09:01:14 +00:00
[McpServerTool(Name = McpToolNames.UpdateRow, Destructive = true, Idempotent = true)]
[Description("Bir listedeki kaydi anahtar degerine gore gunceller. Yalnizca verilen alanlar yazilir.")]
2026-10-10 22:03:36 +00:00
public async Task<CallToolResult> UpdateRowAsync(
2026-09-17 09:01:14 +00:00
[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)
2026-10-10 22:03:36 +00:00
=> McpToolResult.From(await dataAppService.UpdateRowAsync(new McpRowRequestDto
2026-09-17 09:01:14 +00:00
{
ListFormCode = listFormCode,
Keys = keys ?? [],
Values = values ?? []
2026-10-10 22:03:36 +00:00
}));
2026-09-17 09:01:14 +00:00
[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.")]
2026-10-10 22:03:36 +00:00
public async Task<CallToolResult> DeleteRowAsync(
2026-09-17 09:01:14 +00:00
[Description("Kaydin bulundugu listenin kodu.")]
string listFormCode,
[Description("Silinecek kaydin anahtar alan degeri.")]
List<object?> keys)
2026-10-10 22:03:36 +00:00
=> McpToolResult.From(await dataAppService.DeleteRowAsync(new McpRowRequestDto
2026-09-17 09:01:14 +00:00
{
ListFormCode = listFormCode,
Keys = keys ?? []
2026-10-10 22:03:36 +00:00
}));
2026-09-17 09:01:14 +00:00
}