diff --git a/CLAUDE.md b/CLAUDE.md new file mode 120000 index 0000000..fa62d27 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +CONTEXT.md \ No newline at end of file diff --git a/main.go b/main.go index f9054a6..4c10cbf 100644 --- a/main.go +++ b/main.go @@ -159,12 +159,15 @@ func main() { // Define the find_comments tool findCommentsTool := mcp.NewTool("find_comments", - mcp.WithDescription("Find undocumented exports, TODOs, and analyze comments"), + mcp.WithDescription("Find all comments in Go files, with optional filtering for TODOs or undocumented exports"), mcp.WithString("dir", mcp.Description("Directory to search (default: current directory)"), ), mcp.WithString("type", - mcp.Description("Comment type to find: 'todo', 'undocumented', or 'all' (default: 'all')"), + mcp.Description("Comment type: 'todo' (filters by TODO keywords), 'undocumented' (finds undocumented exports), or 'all' (returns all comments, default)"), + ), + mcp.WithString("filter", + mcp.Description("Optional regex to filter comments (applies to 'todo' and 'all' types)"), ), ) mcpServer.AddTool(findCommentsTool, findCommentsHandler) @@ -678,8 +681,9 @@ func analyzeTestsHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp func findCommentsHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { dir := request.GetString("dir", "./") commentType := request.GetString("type", "all") + filter := request.GetString("filter", "") - comments, err := findComments(dir, commentType) + comments, err := findComments(dir, commentType, filter) if err != nil { return mcp.NewToolResultError(fmt.Sprintf("failed to find comments: %v", err)), nil } diff --git a/tool_find_comments.go b/tool_find_comments.go index 4b4418c..112429f 100644 --- a/tool_find_comments.go +++ b/tool_find_comments.go @@ -20,7 +20,7 @@ type CommentItem struct { Position Position `json:"position"` } -func findComments(dir string, commentType string) ([]CommentInfo, error) { +func findComments(dir string, commentType string, filter string) ([]CommentInfo, error) { var comments []CommentInfo err := walkGoFiles(dir, func(path string, src []byte, file *ast.File, fset *token.FileSet) error { @@ -28,16 +28,28 @@ func findComments(dir string, commentType string) ([]CommentInfo, error) { File: path, } - // Find TODOs in comments + // Find comments based on type if commentType == "todo" || commentType == "all" { - todoRegex := regexp.MustCompile(`(?i)\b(todo|fixme|hack|bug|xxx)\b`) + var filterRegex *regexp.Regexp + if filter != "" { + var err error + filterRegex, err = regexp.Compile(filter) + if err != nil { + return err + } + } else if commentType == "todo" { + // Default TODO regex if no filter provided and type is "todo" + filterRegex = regexp.MustCompile(`(?i)\b(todo|fixme|hack|bug|xxx)\b`) + } + for _, cg := range file.Comments { for _, c := range cg.List { - if todoRegex.MatchString(c.Text) { + // If no filter or filter matches, include the comment + if filterRegex == nil || filterRegex.MatchString(c.Text) { pos := fset.Position(c.Pos()) info.TODOs = append(info.TODOs, CommentItem{ Comment: c.Text, - Type: "todo", + Type: "comment", Position: newPosition(pos), }) }