Files
pfm/PostFundManagement.Application/Mcp/GovernanceMcpTools.cs
T
2026-10-30 10:16:27 +02:00

99 lines
9.0 KiB
C#

using PostFundManagement.Application.Abstractions.Services;
using PostFundManagement.Application.Extensions;
using PostFundManagement.Application.Services.Governance;
using PostFundManagement.Domain;
using PostFundManagement.Domain.Models;
namespace PostFundManagement.Application.Mcp;
/// <summary>
/// MCP tools proxying Governance Services (Portfolios, Organisations, Multi-Tenancy, Funding Instruments, Executive Dashboards).
/// </summary>
[McpServerToolType]
public class GovernanceMcpTools(IGovernanceService service)
{
[McpServerTool(Name = "governance_get_dashboard", Title = "Get Portfolio Executive Dashboard", ReadOnly = true)]
[Description("Retrieves aggregated executive portfolio statistics, project counts, financial totals, and risk overviews (Modules M20 & M22).")]
public async Task<Records<Dashboard>> GetDashboardAsync(CancellationToken cancellationToken = default) =>
(await service.GetDashboardAsync(cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_get_organisations", Title = "Get Master Organisations", ReadOnly = true)]
[Description("Retrieves a paginated list of recipient, partner, and donor organisations (BR-005 Single Source of Truth).")]
public async Task<Records<Organisation[]>> GetOrganisationsAsync([Description("Page index (1-based)")] int page = 1, [Description("Page size (1-100)")] int pageSize = 50, CancellationToken cancellationToken = default) =>
(await service.GetOrganisationsAsync(new Pagination(page, pageSize), cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_get_organisation", Title = "Get Organisation by ID", ReadOnly = true)]
[Description("Retrieves full master data and KYC details for an organisation by hash identifier.")]
public async Task<Records<Organisation>> GetOrganisationAsync([Description("Organisation hash identifier")] string organisationIdHash, CancellationToken cancellationToken = default) =>
(await service.GetOrganisationAsync(organisationIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_create_organisation", Title = "Register Organisation", Destructive = false)]
[Description("Registers a new recipient organisation, donor, or implementation partner (Module M03).")]
public async Task<McpToolResult> CreateOrganisationAsync([Description("Organisation creation details")] CreateOrganisationRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreateOrganisationAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Organisation successfully registered.");
[McpServerTool(Name = "governance_update_organisation", Title = "Update Organisation", Destructive = false)]
[Description("Updates organisation profile, contact details, registration, or tax status.")]
public async Task<Records<Organisation>> UpdateOrganisationAsync([Description("Organisation update request")] UpdateOrganisationRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default)
{
var result = await service.UpdateOrganisationAsync(request, userId ?? SystemUser, cancellationToken);
return result.ToMcpResult();
}
[McpServerTool(Name = "governance_get_portfolios", Title = "Get Portfolios", ReadOnly = true)]
[Description("Retrieves a paginated list of top-level investment and grant portfolios.")]
public async Task<Records<Portfolio[]>> GetPortfoliosAsync([Description("Page index (1-based)")] int page = 1, [Description("Page size (1-100)")] int pageSize = 50, CancellationToken cancellationToken = default) =>
(await service.GetPorfoliosAsync(new Pagination(page, pageSize), cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_get_portfolio", Title = "Get Portfolio by ID", ReadOnly = true)]
[Description("Retrieves details of a portfolio by hash identifier.")]
public async Task<Records<Portfolio>> GetPortfolioAsync([Description("Portfolio hash identifier")] string portfolioIdHash, CancellationToken cancellationToken = default) =>
(await service.GetPortfolioAsync(portfolioIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_create_portfolio", Title = "Create Portfolio", Destructive = false)]
[Description("Creates an overarching investment or grant portfolio governing programmes.")]
public async Task<McpToolResult> CreatePortfolioAsync([Description("Portfolio creation parameters")] CreatePortfolioRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreatePortfolioAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Portfolio successfully created.");
[McpServerTool(Name = "governance_update_portfolio", Title = "Update Portfolio", Destructive = false)]
[Description("Updates portfolio objectives, dates, or metadata.")]
public async Task<McpToolResult> UpdatePortfolioAsync([Description("Portfolio update request")] UpdatePortfolioRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.UpdatePortfolioAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Portfolio successfully updated.");
[McpServerTool(Name = "governance_get_instruments", Title = "Get Funding Instruments", ReadOnly = true)]
[Description("Retrieves configured funding instruments (Grant, Debt, Impact, Blended Finance, etc.) under a programme (BR-006).")]
public async Task<Records<Instrument[]>> GetInstrumentsAsync([Description("Programme hash identifier")] string programmeIdHash, CancellationToken cancellationToken = default) =>
(await service.GetInstrumentsAsync(programmeIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_create_instrument", Title = "Define Funding Instrument", Destructive = false)]
[Description("Configures a funding instrument with custom milestone rules, KPIs, and disbursement criteria (BR-006).")]
public async Task<McpToolResult> CreateInstrumentAsync([Description("Instrument creation request")] CreateInstrumentRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreateInstrumentAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Funding instrument successfully defined.");
[McpServerTool(Name = "governance_get_tenants", Title = "Get Tenants", ReadOnly = true)]
[Description("Retrieves registered tenant partitions in the multi-tenant architecture.")]
public async Task<Records<Tenant[]>> GetTenantsAsync(CancellationToken cancellationToken = default) =>
(await service.GetTenantsAsync(cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_get_tenant", Title = "Get Tenant by ID", ReadOnly = true)]
[Description("Retrieves tenant profile and isolation partition details.")]
public async Task<Records<Tenant>> GetTenantAsync([Description("Tenant hash identifier")] string tenantIdHash, CancellationToken cancellationToken = default) =>
(await service.GetTenantAsync(tenantIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_create_tenant", Title = "Create Tenant", Destructive = false)]
[Description("Provisions a new tenant boundary in the platform.")]
public async Task<McpToolResult> CreateTenantAsync([Description("Tenant creation parameters")] CreateTenantRequest request, [Description("Optional acting user ID; defaults to System user if omitted")] Guid? userId = null, CancellationToken cancellationToken = default) =>
(await service.CreateTenantAsync(request, userId ?? SystemUser, cancellationToken)).ToMcpResult("Tenant successfully created.");
[McpServerTool(Name = "governance_get_portfolio_value", Title = "Calculate Portfolio Monetary Value", ReadOnly = true)]
[Description("Computes aggregated total commitment and monetary allocation across all projects in a portfolio (BR-010).")]
public async Task<Records<decimal>> GetPortfolioValueAsync([Description("Portfolio hash identifier")] string portfolioIdHash, CancellationToken cancellationToken = default) =>
(await service.GetPorfolioValueAsync(portfolioIdHash, cancellationToken)).ToMcpResult();
[McpServerTool(Name = "governance_get_programme_value", Title = "Calculate Programme Monetary Value", ReadOnly = true)]
[Description("Computes aggregated total commitment across all projects in a programme (BR-010).")]
public async Task<Records<decimal>> GetProgrammeValueAsync([Description("Programme hash identifier")] string programmeIdHash, CancellationToken cancellationToken = default) =>
(await service.GetProgrammeValueAsync(programmeIdHash, cancellationToken)).ToMcpResult();
}