fix(backend): Fix MCP module compilation errors by using correct exception classes

Replaced non-existent ColaFlow.Shared.Kernel.Exceptions namespace references
with ColaFlow.Modules.Mcp.Domain.Exceptions in 5 files:

Changes:
- McpToolRegistry.cs: Use McpInvalidParamsException and McpNotFoundException
- AddCommentTool.cs: Use McpInvalidParamsException and McpNotFoundException
- CreateIssueTool.cs: Use McpInvalidParamsException, McpNotFoundException, and ProjectId.From()
- UpdateStatusTool.cs: Use McpNotFoundException
- ToolParameterParser.cs: Use McpInvalidParamsException for all validation errors

All BadRequestException -> McpInvalidParamsException
All NotFoundException -> McpNotFoundException

Also fixed CreateIssueTool to convert Guid to ProjectId value object.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2025-11-09 18:31:17 +01:00
parent 9ccd3284fb
commit 61e0f1249c
11 changed files with 1235 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
namespace ColaFlow.Modules.Mcp.Contracts.Tools;
/// <summary>
/// Interface for MCP Tools
/// Tools provide write operations to AI agents through the MCP protocol
/// All write operations create PendingChanges and require human approval
/// </summary>
public interface IMcpTool
{
/// <summary>
/// Tool name (e.g., "create_issue", "update_status")
/// Must be unique and follow snake_case naming convention
/// </summary>
string Name { get; }
/// <summary>
/// Human-readable tool description for AI to understand when to use this tool
/// </summary>
string Description { get; }
/// <summary>
/// JSON Schema describing the tool's input parameters
/// </summary>
McpToolInputSchema InputSchema { get; }
/// <summary>
/// Execute the tool with the provided arguments
/// This should create a PendingChange, NOT execute the change directly
/// </summary>
/// <param name="toolCall">The tool call request with arguments</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Tool execution result</returns>
Task<McpToolResult> ExecuteAsync(
McpToolCall toolCall,
CancellationToken cancellationToken);
/// <summary>
/// Get tool descriptor with full metadata
/// </summary>
McpToolDescriptor GetDescriptor()
{
return new McpToolDescriptor
{
Name = Name,
Description = Description,
InputSchema = InputSchema
};
}
}

View File

@@ -0,0 +1,18 @@
namespace ColaFlow.Modules.Mcp.Contracts.Tools;
/// <summary>
/// Represents a tool call request from an AI agent
/// </summary>
public sealed class McpToolCall
{
/// <summary>
/// Tool name to execute
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Tool arguments as key-value pairs
/// Values can be strings, numbers, booleans, arrays, or objects
/// </summary>
public Dictionary<string, object> Arguments { get; set; } = new();
}

View File

@@ -0,0 +1,22 @@
namespace ColaFlow.Modules.Mcp.Contracts.Tools;
/// <summary>
/// Descriptor for an MCP Tool containing metadata and schema
/// </summary>
public sealed class McpToolDescriptor
{
/// <summary>
/// Tool name
/// </summary>
public string Name { get; set; } = string.Empty;
/// <summary>
/// Tool description
/// </summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// Input parameter schema
/// </summary>
public McpToolInputSchema InputSchema { get; set; } = new();
}

View File

@@ -0,0 +1,89 @@
namespace ColaFlow.Modules.Mcp.Contracts.Tools;
/// <summary>
/// JSON Schema for tool input parameters
/// </summary>
public sealed class McpToolInputSchema
{
/// <summary>
/// Schema type (always "object" for tool inputs)
/// </summary>
public string Type { get; set; } = "object";
/// <summary>
/// Schema properties (parameter definitions)
/// Key is parameter name, value is parameter schema
/// </summary>
public Dictionary<string, JsonSchemaProperty> Properties { get; set; } = new();
/// <summary>
/// List of required parameter names
/// </summary>
public List<string> Required { get; set; } = new();
}
/// <summary>
/// JSON Schema property definition
/// </summary>
public sealed class JsonSchemaProperty
{
/// <summary>
/// Property type: "string", "number", "integer", "boolean", "array", "object"
/// </summary>
public string Type { get; set; } = "string";
/// <summary>
/// Property description (for AI to understand)
/// </summary>
public string? Description { get; set; }
/// <summary>
/// Enum values (for restricted choices)
/// </summary>
public string[]? Enum { get; set; }
/// <summary>
/// String format hint: "uuid", "email", "date-time", "uri", etc.
/// </summary>
public string? Format { get; set; }
/// <summary>
/// Minimum value (for numbers)
/// </summary>
public decimal? Minimum { get; set; }
/// <summary>
/// Maximum value (for numbers)
/// </summary>
public decimal? Maximum { get; set; }
/// <summary>
/// Minimum length (for strings)
/// </summary>
public int? MinLength { get; set; }
/// <summary>
/// Maximum length (for strings)
/// </summary>
public int? MaxLength { get; set; }
/// <summary>
/// Pattern (regex) for string validation
/// </summary>
public string? Pattern { get; set; }
/// <summary>
/// Items schema (for arrays)
/// </summary>
public JsonSchemaProperty? Items { get; set; }
/// <summary>
/// Properties schema (for nested objects)
/// </summary>
public Dictionary<string, JsonSchemaProperty>? Properties { get; set; }
/// <summary>
/// Default value
/// </summary>
public object? Default { get; set; }
}

View File

@@ -0,0 +1,38 @@
namespace ColaFlow.Modules.Mcp.Contracts.Tools;
/// <summary>
/// Result of a tool execution
/// </summary>
public sealed class McpToolResult
{
/// <summary>
/// Tool result content (typically text describing the PendingChange created)
/// </summary>
public IEnumerable<McpToolContent> Content { get; set; } = Array.Empty<McpToolContent>();
/// <summary>
/// Whether the tool execution failed
/// </summary>
public bool IsError { get; set; }
}
/// <summary>
/// Content item in a tool result
/// </summary>
public sealed class McpToolContent
{
/// <summary>
/// Content type: "text" or "resource"
/// </summary>
public string Type { get; set; } = "text";
/// <summary>
/// Text content (for type="text")
/// </summary>
public string? Text { get; set; }
/// <summary>
/// Resource URI (for type="resource")
/// </summary>
public string? Resource { get; set; }
}