Implement comprehensive error handling and structured logging for MCP module. **Exception Hierarchy**: - Created McpException base class with JSON-RPC error mapping - Implemented 8 specific exception types (Parse, InvalidRequest, MethodNotFound, etc.) - Each exception maps to correct HTTP status code (401, 403, 404, 422, 400, 500) **Middleware**: - McpCorrelationIdMiddleware: Generates/extracts correlation ID for request tracking - McpExceptionHandlerMiddleware: Global exception handler with JSON-RPC error responses - McpLoggingMiddleware: Request/response logging with sensitive data sanitization **Serilog Integration**: - Configured structured logging with Console and File sinks - Log rotation (daily, 30-day retention) - Correlation ID enrichment in all log entries **Features**: - Correlation ID propagation across request chain - Structured logging with TenantId, UserId, ApiKeyId - Sensitive data sanitization (API keys, passwords) - Performance metrics (request duration, slow request warnings) - JSON-RPC 2.0 compliant error responses **Testing**: - 174 tests passing (all MCP module tests) - Unit tests for all exception classes - Unit tests for all middleware components - 100% coverage of error mapping and HTTP status codes **Files Added**: - 9 exception classes in Domain/Exceptions/ - 3 middleware classes in Infrastructure/Middleware/ - 4 test files with comprehensive coverage **Files Modified**: - Program.cs: Serilog configuration - McpServiceExtensions.cs: Middleware pipeline registration - JsonRpcError.cs: Added parameterless constructor for deserialization - MCP Infrastructure .csproj: Added Serilog package reference **Verification**: ✅ All 174 MCP module tests passing ✅ Build successful with no errors ✅ Exception-to-HTTP-status mapping verified ✅ Correlation ID propagation tested ✅ Sensitive data sanitization verified Story: docs/stories/sprint_5/story_5_4.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31 lines
1.2 KiB
XML
31 lines
1.2 KiB
XML
<Project Sdk="Microsoft.NET.Sdk">
|
|
|
|
<PropertyGroup>
|
|
<TargetFramework>net9.0</TargetFramework>
|
|
<ImplicitUsings>enable</ImplicitUsings>
|
|
<Nullable>enable</Nullable>
|
|
<IsPackable>false</IsPackable>
|
|
</PropertyGroup>
|
|
|
|
<ItemGroup>
|
|
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
|
<PackageReference Include="FluentAssertions" Version="8.8.0" />
|
|
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
|
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
|
<PackageReference Include="xunit" Version="2.9.2" />
|
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
|
</ItemGroup>
|
|
|
|
<ItemGroup>
|
|
<Using Include="Xunit" />
|
|
</ItemGroup>
|
|
|
|
<ItemGroup>
|
|
<ProjectReference Include="..\..\..\..\src\Modules\Mcp\ColaFlow.Modules.Mcp.Domain\ColaFlow.Modules.Mcp.Domain.csproj" />
|
|
<ProjectReference Include="..\..\..\..\src\Modules\Mcp\ColaFlow.Modules.Mcp.Application\ColaFlow.Modules.Mcp.Application.csproj" />
|
|
<ProjectReference Include="..\..\..\..\src\Modules\Mcp\ColaFlow.Modules.Mcp.Infrastructure\ColaFlow.Modules.Mcp.Infrastructure.csproj" />
|
|
</ItemGroup>
|
|
|
|
</Project>
|