Implemented JSON-RPC 2.0 protocol handler for MCP communication, enabling AI agents to communicate with ColaFlow using the Model Context Protocol. **Implementation:** - JSON-RPC 2.0 data models (Request, Response, Error, ErrorCode) - MCP protocol models (Initialize, Capabilities, ClientInfo, ServerInfo) - McpProtocolHandler with method routing and error handling - Method handlers: initialize, resources/list, tools/list, tools/call - ASP.NET Core middleware for /mcp endpoint - Service registration and dependency injection setup **Testing:** - 28 unit tests covering protocol parsing, validation, and error handling - Integration tests for initialize handshake and error responses - All tests passing with >80% coverage **Changes:** - Created ColaFlow.Modules.Mcp.Contracts project - Created ColaFlow.Modules.Mcp.Domain project - Created ColaFlow.Modules.Mcp.Application project - Created ColaFlow.Modules.Mcp.Infrastructure project - Created ColaFlow.Modules.Mcp.Tests project - Registered MCP module in ColaFlow.API Program.cs - Added /mcp endpoint via middleware **Acceptance Criteria Met:** ✅ JSON-RPC 2.0 messages correctly parsed ✅ Request validation (jsonrpc: "2.0", method, params, id) ✅ Error responses conform to JSON-RPC 2.0 spec ✅ Invalid requests return proper error codes (-32700, -32600, -32601, -32602) ✅ MCP initialize method implemented ✅ Server capabilities returned (resources, tools, prompts) ✅ Protocol version negotiation works (1.0) ✅ Request routing to method handlers ✅ Unit test coverage > 80% ✅ All tests passing **Story**: docs/stories/sprint_5/story_5_1.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
3.2 KiB
3.2 KiB
story_id, sprint_id, phase, status, priority, story_points, assignee, estimated_days, created_date, dependencies
| story_id | sprint_id | phase | status | priority | story_points | assignee | estimated_days | created_date | dependencies | |
|---|---|---|---|---|---|---|---|---|---|---|
| story_5_6 | sprint_5 | Phase 2 - Resources | not_started | P0 | 3 | backend | 1 | 2025-11-06 |
|
Story 5.6: Resource Registration & Discovery
Phase: Phase 2 - Resources (Week 3-4) Priority: P0 CRITICAL Estimated Effort: 3 Story Points (1 day)
User Story
As an AI Agent I want to discover available MCP Resources dynamically So that I know what data I can access from ColaFlow
Business Value
Dynamic Resource discovery enables:
- AI agents to explore available capabilities
- Easy addition of new Resources without code changes
- Version compatibility checking
- Documentation generation
Acceptance Criteria
AC1: Auto-Discovery
- All
IMcpResourceimplementations auto-registered at startup - Use Assembly scanning (Reflection)
- Singleton registration in DI container
AC2: Resource Catalog
resources/listmethod returns all Resources- Each Resource includes: URI, name, description, MIME type
- Response conforms to MCP specification
AC3: Resource Versioning
- Support for Resource versioning (future-proof)
- Optional
versionfield in Resource metadata
AC4: Configuration
- Enable/disable Resources via
appsettings.json - Filter Resources by tenant (optional)
AC5: Testing
- Unit tests for registry logic
- Integration test for
resources/list
Technical Design
public interface IMcpRegistry
{
void RegisterResource(IMcpResource resource);
IMcpResource? GetResource(string uri);
IReadOnlyList<IMcpResource> GetAllResources();
}
public class McpRegistry : IMcpRegistry
{
private readonly Dictionary<string, IMcpResource> _resources = new();
public void RegisterResource(IMcpResource resource)
{
_resources[resource.Uri] = resource;
}
public IMcpResource? GetResource(string uri)
{
return _resources.TryGetValue(uri, out var resource) ? resource : null;
}
public IReadOnlyList<IMcpResource> GetAllResources()
{
return _resources.Values.ToList().AsReadOnly();
}
}
// Auto-registration
public static class McpServiceExtensions
{
public static IServiceCollection AddMcpResources(
this IServiceCollection services)
{
var assembly = typeof(IMcpResource).Assembly;
var resourceTypes = assembly.GetTypes()
.Where(t => typeof(IMcpResource).IsAssignableFrom(t)
&& !t.IsInterface && !t.IsAbstract);
foreach (var type in resourceTypes)
{
services.AddSingleton(typeof(IMcpResource), type);
}
services.AddSingleton<IMcpRegistry, McpRegistry>();
return services;
}
}
Tasks
- Create
IMcpRegistryinterface (1 hour) - Implement
McpRegistryclass (2 hours) - Implement auto-discovery via Reflection (2 hours)
- Implement
resources/listhandler (1 hour) - Add configuration support (1 hour)
- Unit tests (2 hours)
Definition of Done
- All Resources auto-registered
resources/listreturns complete catalog- Unit tests passing
- Code reviewed