Fixed crash loop
This commit is contained in:
@@ -3,7 +3,7 @@ namespace PostFundManagement.Application.Mcp;
|
||||
/// <summary>
|
||||
/// Token-optimized standardized tool response wrapper for MCP tool execution.
|
||||
/// </summary>
|
||||
public record Records<T>(bool Success, T? Data = default, string? Message = null, IReadOnlyList<string>? Errors = null)
|
||||
public record Records<T>(bool Success, T? Data, string? Message = null, IReadOnlyList<string>? Errors = null)
|
||||
{
|
||||
public static Records<T> Ok(T data, string? message = null) => new(true, data, message, null);
|
||||
|
||||
|
||||
@@ -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<IGrantsService, TestGrantsService>();
|
||||
services.AddSingleton<IProjectService, TestProjectService>();
|
||||
services.AddSingleton<IExecutionService, TestExecutionService>();
|
||||
services.AddSingleton<IGovernanceService, TestGovernanceService>();
|
||||
services.AddSingleton<IEvidenceService, TestEvidenceService>();
|
||||
services.AddSingleton<ICommunicationsService, TestCommunicationsService>();
|
||||
services.AddSingleton<IUserService, TestUserService>();
|
||||
services.AddApplicationMcpTools();
|
||||
|
||||
var mcpBuilder = services.AddMcpServer();
|
||||
mcpBuilder.WithApplicationMcpTools();
|
||||
|
||||
var sp = services.BuildServiceProvider();
|
||||
var tools = sp.GetServices<ModelContextProtocol.Server.McpServerTool>().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<IGrantsService, TestGrantsService>();
|
||||
services.AddSingleton<IProjectService, TestProjectService>();
|
||||
services.AddSingleton<IExecutionService, TestExecutionService>();
|
||||
services.AddSingleton<IGovernanceService, TestGovernanceService>();
|
||||
services.AddSingleton<IEvidenceService, TestEvidenceService>();
|
||||
services.AddSingleton<ICommunicationsService, TestCommunicationsService>();
|
||||
services.AddSingleton<IUserService, TestUserService>();
|
||||
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<ModelContextProtocol.Server.McpServerTool>().ToList();
|
||||
Assert.NotEmpty(tools);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddApplicationMcpTools_RegistersAllToolTypesAndInAppClient()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user