Add project filter, route group prefixes, decorator entry points, and remove limit caps

- search_graph: add `project` parameter to scope searches to a single project
- httplink: resolve Go gin router Group() prefixes into Route node paths
- pipeline: recognize @app.middleware, @app.exception_handler, @app.on_event as entry points
- search_graph/search_code: make `limit` optional (no default cap, no max 200)
- Fix cypher test assertions after previous SubmitOrder rename
This commit is contained in:
Martin Vogel
2026-02-25 00:39:25 +01:00
parent 8ea3f2ee21
commit 0fa3eb7c8c
7 changed files with 75 additions and 25 deletions
+6 -6
View File
@@ -403,9 +403,9 @@ func TestExecuteWhereRegex(t *testing.T) {
if err != nil {
t.Fatalf("execute: %v", err)
}
// HandleOrder, ValidateOrder
if len(result.Rows) != 2 {
t.Errorf("expected 2 rows, got %d", len(result.Rows))
// HandleOrder, ValidateOrder, SubmitOrder
if len(result.Rows) != 3 {
t.Errorf("expected 3 rows, got %d", len(result.Rows))
}
}
@@ -414,7 +414,7 @@ func TestExecuteWhereStartsWith(t *testing.T) {
defer s.Close()
exec := &Executor{Store: s}
result, err := exec.Execute(`MATCH (f:Function) WHERE f.name STARTS WITH "Send" RETURN f.name`)
result, err := exec.Execute(`MATCH (f:Function) WHERE f.name STARTS WITH "Submit" RETURN f.name`)
if err != nil {
t.Fatalf("execute: %v", err)
}
@@ -435,8 +435,8 @@ func TestExecuteWhereContains(t *testing.T) {
if err != nil {
t.Fatalf("execute: %v", err)
}
if len(result.Rows) != 2 {
t.Errorf("expected 2 rows (HandleOrder, ValidateOrder), got %d", len(result.Rows))
if len(result.Rows) != 3 {
t.Errorf("expected 3 rows (HandleOrder, ValidateOrder, SubmitOrder), got %d", len(result.Rows))
}
}
+44 -4
View File
@@ -57,6 +57,9 @@ var (
// Go gin routes: .POST("/path", .GET("/path"
goRouteRe = regexp.MustCompile(`\.(GET|POST|PUT|DELETE|PATCH)\(\s*["']([^"']+)["']`)
// Go gin group: .Group("/prefix")
goGroupRe = regexp.MustCompile(`(\w+)\s*(?::=|=)\s*\w+\.Group\(\s*["']([^"']+)["']`)
// Express.js routes: app.get("/path", router.post("/path"
expressRouteRe = regexp.MustCompile(`\w+\.(get|post|put|delete|patch)\(\s*["'` + "`" + `]([^"'` + "`" + `]+)["'` + "`" + `]`)
@@ -230,14 +233,51 @@ func extractPythonRoutes(f *store.Node) []RouteHandler {
}
// extractGoRoutes extracts route registrations from Go source code (gin patterns).
// Resolves router group prefixes by matching variable names in Group() calls
// to the receiver of .GET/.POST calls (e.g., contracts.POST("", ...) where
// contracts := rg.Group("/contracts")).
func extractGoRoutes(f *store.Node, source string) []RouteHandler {
var routes []RouteHandler
matches := goRouteRe.FindAllStringSubmatch(source, -1)
for _, m := range matches {
// Build a map of variable name → group prefix from Group() calls
groupPrefixes := map[string]string{}
for _, gm := range goGroupRe.FindAllStringSubmatch(source, -1) {
varName := gm[1]
prefix := gm[2]
groupPrefixes[varName] = prefix
}
// Match route registrations and try to prepend group prefix
lines := strings.Split(source, "\n")
for _, line := range lines {
rm := goRouteRe.FindStringSubmatch(line)
if rm == nil {
continue
}
method := strings.ToUpper(rm[1])
path := rm[2]
// Try to find the receiver variable (e.g., "contracts" in "contracts.POST")
// by looking at what's before the .METHOD( call
idx := strings.Index(line, "."+rm[1]+"(")
if idx > 0 {
prefix := strings.TrimSpace(line[:idx])
// Take the last word (variable name)
parts := strings.Fields(prefix)
if len(parts) > 0 {
receiver := parts[len(parts)-1]
if gp, ok := groupPrefixes[receiver]; ok {
path = strings.TrimRight(gp, "/") + "/" + strings.TrimLeft(path, "/")
if path == "/" {
path = gp
}
}
}
}
routes = append(routes, RouteHandler{
Path: m[2],
Method: strings.ToUpper(m[1]),
Path: path,
Method: method,
FunctionName: f.Name,
QualifiedName: f.QualifiedName,
})
+2
View File
@@ -796,6 +796,8 @@ var frameworkDecoratorPrefixes = []string{
"@router.get", "@router.post", "@router.put", "@router.delete", "@router.patch",
"@router.route", "@router.websocket",
"@blueprint.", "@api.", "@ns.",
// Python middleware and exception handlers (framework-registered)
"@app.middleware", "@app.exception_handler", "@app.on_event",
// Testing frameworks
"@pytest.fixture", "@pytest.mark",
// CLI frameworks
+4 -5
View File
@@ -30,11 +30,10 @@ type SearchResult struct {
// Search executes a parameterized search query.
func (s *Store) Search(params SearchParams) ([]*SearchResult, error) {
if params.Limit <= 0 {
params.Limit = 50
}
if params.Limit > 200 {
params.Limit = 200
// Limit=0 means no limit; use a high ceiling for SQL
unlimited := params.Limit <= 0
if unlimited {
params.Limit = 100000
}
// Build the query dynamically with parameterized values
+3 -3
View File
@@ -30,9 +30,9 @@ func (s *Server) handleSearchCode(_ context.Context, req *mcp.CallToolRequest) (
}
fileGlob := getStringArg(args, "file_pattern")
maxResults := getIntArg(args, "max_results", 50)
if maxResults > 200 {
maxResults = 200
maxResults := getIntArg(args, "max_results", 0)
if maxResults <= 0 {
maxResults = 100000 // no limit
}
isRegex := false
+7 -2
View File
@@ -22,10 +22,12 @@ func (s *Server) handleSearchGraph(_ context.Context, req *mcp.CallToolRequest)
Direction: getStringArg(args, "direction"),
MinDegree: getIntArg(args, "min_degree", -1),
MaxDegree: getIntArg(args, "max_degree", -1),
Limit: getIntArg(args, "limit", 50),
Limit: getIntArg(args, "limit", 0), // 0 = no limit
ExcludeEntryPoints: getBoolArg(args, "exclude_entry_points"),
}
projectFilter := getStringArg(args, "project")
projects, err := s.store.ListProjects()
if err != nil {
return errResult(fmt.Sprintf("list projects: %v", err)), nil
@@ -38,7 +40,7 @@ func (s *Server) handleSearchGraph(_ context.Context, req *mcp.CallToolRequest)
}), nil
}
// Search across all projects, collect results
// Search across matching projects, collect results
type resultEntry struct {
Project string `json:"project"`
Name string `json:"name"`
@@ -54,6 +56,9 @@ func (s *Server) handleSearchGraph(_ context.Context, req *mcp.CallToolRequest)
var allResults []resultEntry
for _, p := range projects {
if projectFilter != "" && p.Name != projectFilter {
continue
}
params.Project = p.Name
results, searchErr := s.store.Search(params)
if searchErr != nil {
+9 -5
View File
@@ -102,13 +102,17 @@ func (s *Server) registerTools() {
// 5. search_graph
s.mcp.AddTool(&mcp.Tool{
Name: "search_graph",
Description: "Search the code graph with structured filters. Replaces raw Cypher queries with safe, parameterized search. Supports filtering by node label, name pattern (regex), file pattern (glob), relationship type, direction, and degree (fan-in/fan-out). Returns matching nodes with properties and edge counts.",
Description: "Search the code graph with structured filters. Replaces raw Cypher queries with safe, parameterized search. Supports filtering by project, node label, name pattern (regex), file pattern (glob), relationship type, direction, and degree (fan-in/fan-out). Returns matching nodes with properties and edge counts.",
InputSchema: json.RawMessage(`{
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "Filter by project name. If omitted, searches all indexed projects."
},
"label": {
"type": "string",
"description": "Node label filter: Function, Class, Module, Method, Interface, Enum, Type, File, Package, Folder"
"description": "Node label filter: Function, Class, Module, Method, Interface, Enum, Type, File, Package, Folder, Route"
},
"name_pattern": {
"type": "string",
@@ -116,7 +120,7 @@ func (s *Server) registerTools() {
},
"file_pattern": {
"type": "string",
"description": "Glob pattern for file path (e.g. '**/order-service/**')"
"description": "Glob pattern for file path within the project (e.g. '**/services/**', '*.py')"
},
"relationship": {
"type": "string",
@@ -141,7 +145,7 @@ func (s *Server) registerTools() {
},
"limit": {
"type": "integer",
"description": "Max results (default 50, max 200)"
"description": "Max results to return. If omitted, returns all matching results."
}
}
}`),
@@ -234,7 +238,7 @@ func (s *Server) registerTools() {
},
"max_results": {
"type": "integer",
"description": "Maximum number of matches to return (default 50, max 200)"
"description": "Maximum number of matches to return. If omitted, returns all matches."
}
},
"required": ["pattern"]