feat(backend): Implement Story 5.6 - Resource Registration & Discovery
Implemented pluggable resource registration and auto-discovery mechanism for MCP Resources. Changes: - Enhanced McpResourceDescriptor with metadata (Category, Version, Parameters, Examples, Tags, IsEnabled) - Created ResourceDiscoveryService for Assembly scanning and auto-discovery - Updated McpResourceRegistry with category support and grouping methods - Enhanced ResourcesListMethodHandler to return categorized resources with full metadata - Created ResourceHealthCheckHandler for resource availability verification - Updated all existing Resources (Projects, Issues, Sprints, Users) with Categories and Versions - Updated McpServiceExtensions to use auto-discovery at startup - Added comprehensive unit tests for discovery and health check Features: ✅ New Resources automatically discovered via Assembly scanning ✅ Resources organized by category (Projects, Issues, Sprints, Users) ✅ Rich metadata for documentation (parameters, examples, tags) ✅ Health check endpoint (resources/health) for monitoring ✅ Thread-safe registry operations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,16 +10,18 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ColaFlow.Modules.Mcp.Infrastructure.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for registering MCP services
|
||||
/// Enhanced with auto-discovery and dynamic registration
|
||||
/// </summary>
|
||||
public static class McpServiceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers MCP module services
|
||||
/// Registers MCP module services with auto-discovery
|
||||
/// </summary>
|
||||
public static IServiceCollection AddMcpModule(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
@@ -39,7 +41,10 @@ public static class McpServiceExtensions
|
||||
// Register resource registry (Singleton - shared across all requests)
|
||||
services.AddSingleton<IMcpResourceRegistry, McpResourceRegistry>();
|
||||
|
||||
// Register MCP Resources
|
||||
// Register Resource Discovery Service (Singleton - used at startup)
|
||||
services.AddSingleton<IResourceDiscoveryService, ResourceDiscoveryService>();
|
||||
|
||||
// Register MCP Resources (Scoped - manual registration for now, auto-discovery at startup)
|
||||
services.AddScoped<IMcpResource, ProjectsListResource>();
|
||||
services.AddScoped<IMcpResource, ProjectsGetResource>();
|
||||
services.AddScoped<IMcpResource, IssuesSearchResource>();
|
||||
@@ -54,6 +59,7 @@ public static class McpServiceExtensions
|
||||
services.AddScoped<IMcpMethodHandler, InitializeMethodHandler>();
|
||||
services.AddScoped<IMcpMethodHandler, ResourcesListMethodHandler>();
|
||||
services.AddScoped<IMcpMethodHandler, ResourcesReadMethodHandler>();
|
||||
services.AddScoped<IMcpMethodHandler, ResourceHealthCheckHandler>(); // NEW: Health check handler
|
||||
services.AddScoped<IMcpMethodHandler, ToolsListMethodHandler>();
|
||||
services.AddScoped<IMcpMethodHandler, ToolsCallMethodHandler>();
|
||||
|
||||
@@ -71,7 +77,7 @@ public static class McpServiceExtensions
|
||||
/// </summary>
|
||||
public static IApplicationBuilder UseMcpMiddleware(this IApplicationBuilder app)
|
||||
{
|
||||
// Initialize resource registry (register all resources)
|
||||
// Initialize resource registry (register all resources with auto-discovery)
|
||||
InitializeResourceRegistry(app);
|
||||
|
||||
// 1. Correlation ID middleware (FIRST - needed for all subsequent logging)
|
||||
@@ -94,17 +100,30 @@ public static class McpServiceExtensions
|
||||
|
||||
/// <summary>
|
||||
/// Initialize resource registry by registering all resources
|
||||
/// Enhanced with auto-discovery using Assembly scanning
|
||||
/// This is called once at startup
|
||||
/// </summary>
|
||||
private static void InitializeResourceRegistry(IApplicationBuilder app)
|
||||
{
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var registry = scope.ServiceProvider.GetRequiredService<IMcpResourceRegistry>();
|
||||
var resources = scope.ServiceProvider.GetServices<IMcpResource>();
|
||||
var discoveryService = scope.ServiceProvider.GetRequiredService<IResourceDiscoveryService>();
|
||||
var loggerFactory = scope.ServiceProvider.GetRequiredService<ILoggerFactory>();
|
||||
var logger = loggerFactory.CreateLogger("McpResourceRegistry");
|
||||
|
||||
logger.LogInformation("Initializing MCP Resource Registry with auto-discovery...");
|
||||
|
||||
// Auto-discover and instantiate all resources
|
||||
var resources = discoveryService.DiscoverAndInstantiateResources(scope.ServiceProvider);
|
||||
|
||||
// Register all discovered resources
|
||||
foreach (var resource in resources)
|
||||
{
|
||||
registry.RegisterResource(resource);
|
||||
}
|
||||
|
||||
var categories = registry.GetCategories();
|
||||
logger.LogInformation("MCP Resource Registry initialized: {ResourceCount} resources in {CategoryCount} categories: {Categories}",
|
||||
resources.Count, categories.Count, string.Join(", ", categories));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user