using PostFundManagement.Application.Abstractions.Services;
using PostFundManagement.Application.Extensions;
using PostFundManagement.Application.Services.Grants;
using PostFundManagement.Domain;
using PostFundManagement.Domain.Models;
namespace PostFundManagement.Application.Mcp;
///
/// MCP tools proxying Grants & Award Services (M01 Award Intake, M02 Contract Management, M05 Budgeting).
///
[McpServerToolType]
public class GrantsMcpTools(IGrantsService service)
{
[McpServerTool(Name = "grants_get_awards", Title = "Get Approved Funding Awards", ReadOnly = true)]
[Description("Retrieves a paginated list of approved funding awards (Module M01).")]
public async Task> GetAwardsAsync([Description("Page index (1-based)")] int page = 1, [Description("Page size (1-100)")] int pageSize = 50, CancellationToken cancellationToken = default) =>
(await service.GetAwardsAsync(new Pagination(page, pageSize), cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_get_award", Title = "Get Award by ID", ReadOnly = true)]
[Description("Retrieves details of an approved funding award by its hash identifier.")]
public async Task> GetAwardAsync([Description("Award hash identifier")] string awardIdHash, CancellationToken cancellationToken = default) =>
(await service.GetAwardAsync(awardIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_create_award", Title = "Register Approved Award", Destructive = false)]
[Description("Registers an approved funding award from upstream committee sanction (BR-001/BR-002, M01). Automatically transitions into contract generation.")]
public async Task CreateAwardAsync([Description("Award creation details")] CreateAwardRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreateAwardAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Award record successfully created and transitioned to contract generation.");
[McpServerTool(Name = "grants_update_award", Title = "Update Award Record", Destructive = false)]
[Description("Updates an existing funding award's metadata and parameters.")]
public async Task UpdateAwardAsync([Description("Award update parameters")] UpdateAwardRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.UpdateAwardAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Award record successfully updated.");
[McpServerTool(Name = "grants_get_contracts", Title = "Get Contracts", ReadOnly = true)]
[Description("Retrieves a paginated list of legal grant contracts and agreements (Module M02).")]
public async Task> GetContractsAsync([Description("Page index (1-based)")] int page = 1, [Description("Page size (1-100)")] int pageSize = 50, CancellationToken cancellationToken = default) =>
(await service.GetContractsAsync(new Pagination(page, pageSize), cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_get_contract", Title = "Get Contract by ID", ReadOnly = true)]
[Description("Retrieves details of a contract agreement by its hash identifier.")]
public async Task> GetContractAsync([Description("Contract hash identifier")] string contractIdHash, CancellationToken cancellationToken = default) =>
(await service.GetContractAsync(contractIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_create_contract", Title = "Create Draft Contract", Destructive = false)]
[Description("Creates a new draft contract or agreement associated with an approved award (Module M02).")]
public async Task CreateContractAsync([Description("Contract creation request")] CreateContractRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreateContractAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Draft contract agreement successfully created.");
[McpServerTool(Name = "grants_update_contract", Title = "Update Contract Agreement", Destructive = false)]
[Description("Updates terms and metadata of a contract in DRAFT or UNDER_REVIEW state.")]
public async Task UpdateContractAsync([Description("Contract update request")] UpdateContractRequest request, CancellationToken cancellationToken = default) =>
(await service.UpdateContractAsync(request, cancellationToken)).ToMcpResult("Contract agreement successfully updated.");
[McpServerTool(Name = "grants_execute_contract", Title = "Formally Execute Contract", Destructive = false)]
[Description("Formally executes and locks a contract agreement once all parties have signed and effective date is established (FR-M02-020).")]
public async Task ExecuteContractAsync([Description("Contract execution request")] ExecuteContractRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.ExecuteContractAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Contract agreement successfully executed and locked.");
[McpServerTool(Name = "grants_get_contract_url", Title = "Get Contract Download URL", ReadOnly = true)]
[Description("Retrieves a presigned download URL for the authoritative executed contract document.")]
public async Task> GetContractUrlAsync([Description("Contract hash identifier")] string contractIdHash, CancellationToken cancellationToken = default) =>
(await service.GetContractUrlAsync(contractIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_get_budgets", Title = "Get Budgets", ReadOnly = true)]
[Description("Retrieves a paginated list of project budgets and allocations (Module M05).")]
public async Task> GetBudgetsAsync([Description("Page index (1-based)")] int page = 1, [Description("Page size (1-100)")] int pageSize = 50, CancellationToken cancellationToken = default) =>
(await service.GetBudgetsAsync(new Pagination(page, pageSize), cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_get_budget", Title = "Get Budget by ID", ReadOnly = true)]
[Description("Retrieves details of a project budget allocation by hash identifier.")]
public async Task> GetBudgetAsync([Description("Budget hash identifier")] string budgetIdHash, CancellationToken cancellationToken = default) =>
(await service.GetBudgetAsync(budgetIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "grants_create_budget", Title = "Create Budget Allocation", Destructive = false)]
[Description("Creates a new project budget line and category allocation (Module M05).")]
public async Task CreateBudgetAsync([Description("Budget creation request")] CreateBudgetRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreateBudgetAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Budget allocation successfully created.");
[McpServerTool(Name = "grants_update_budget", Title = "Update Budget Allocation", Destructive = false)]
[Description("Updates an existing project budget allocation with audit tracking.")]
public async Task UpdateBudgetAsync([Description("Budget update request")] UpdateBudgetRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.UpdateBudgetAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Budget allocation successfully updated.");
}