diff --git a/PostFundManagement.Application/Mcp/Records.cs b/PostFundManagement.Application/Mcp/Records.cs index dbf2d66..4da83eb 100644 --- a/PostFundManagement.Application/Mcp/Records.cs +++ b/PostFundManagement.Application/Mcp/Records.cs @@ -3,7 +3,7 @@ namespace PostFundManagement.Application.Mcp; /// /// Token-optimized standardized tool response wrapper for MCP tool execution. /// -public record Records(bool Success, T? Data = default, string? Message = null, IReadOnlyList? Errors = null) +public record Records(bool Success, T? Data, string? Message = null, IReadOnlyList? Errors = null) { public static Records Ok(T data, string? message = null) => new(true, data, message, null); diff --git a/PostFundManagement.Tests/McpToolingTests.cs b/PostFundManagement.Tests/McpToolingTests.cs index 0e887fb..7231929 100644 --- a/PostFundManagement.Tests/McpToolingTests.cs +++ b/PostFundManagement.Tests/McpToolingTests.cs @@ -35,6 +35,63 @@ public class McpToolingTests _serviceProvider = services.BuildServiceProvider(); } + [Fact] + public void McpServer_WithApplicationMcpTools_SchemaGeneration_Succeeds() + { + var services = new ServiceCollection(); + services.AddLogging(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddApplicationMcpTools(); + + var mcpBuilder = services.AddMcpServer(); + mcpBuilder.WithApplicationMcpTools(); + + var sp = services.BuildServiceProvider(); + var tools = sp.GetServices().ToList(); + Assert.NotEmpty(tools); + Assert.True(tools.Count >= 40, $"Expected at least 40 MCP server tools, but found {tools.Count}"); + } + + [Theory] + [InlineData(typeof(GrantsMcpTools))] + [InlineData(typeof(ProjectsMcpTools))] + [InlineData(typeof(ExecutionMcpTools))] + [InlineData(typeof(GovernanceMcpTools))] + [InlineData(typeof(EvidenceMcpTools))] + [InlineData(typeof(CommunicationsMcpTools))] + [InlineData(typeof(UsersMcpTools))] + public void McpServer_ToolsSchemaGeneration_Succeeds(Type toolType) + { + var services = new ServiceCollection(); + services.AddLogging(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddApplicationMcpTools(); + + var mcpBuilder = services.AddMcpServer(); + // Register just the one tool type using reflection + var withToolsMethod = typeof(Microsoft.Extensions.DependencyInjection.McpServerBuilderExtensions) + .GetMethods() + .First(m => m.Name == "WithTools" && m.IsGenericMethodDefinition && m.GetParameters().Length == 2) + .MakeGenericMethod(toolType); + withToolsMethod.Invoke(null, new object?[] { mcpBuilder, null }); + + var sp = services.BuildServiceProvider(); + var tools = sp.GetServices().ToList(); + Assert.NotEmpty(tools); + } + [Fact] public void AddApplicationMcpTools_RegistersAllToolTypesAndInAppClient() {