forked from CodeGraphContext/CodeGraphContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_definitions.py
More file actions
279 lines (278 loc) · 16.5 KB
/
Copy pathtool_definitions.py
File metadata and controls
279 lines (278 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
TOOLS = {
"add_code_to_graph": {
"name": "add_code_to_graph",
"description": "Performs a one-time scan of a local folder to add its code to the graph. Ideal for indexing libraries, dependencies, or projects not being actively modified. Returns a job ID for background processing.",
"inputSchema": {
"type": "object",
"properties": {
"path": {"type": "string", "description": "Path to the directory or file to add."},
"is_dependency": {"type": "boolean", "description": "Whether this code is a dependency.", "default": False}
},
"required": ["path"]
}
},
"check_job_status": {
"name": "check_job_status",
"description": "Check the status and progress of a background job.",
"inputSchema": {
"type": "object",
"properties": { "job_id": {"type": "string", "description": "Job ID from a previous tool call"} },
"required": ["job_id"]
}
},
"list_jobs": {
"name": "list_jobs",
"description": "List all background jobs and their current status.",
"inputSchema": {"type": "object", "properties": {}}
},
"find_code": {
"name": "find_code",
"description": "Find relevant code snippets related to a keyword (e.g., function name, class name, or content).",
"inputSchema": {
"type": "object",
"properties": { "query": {"type": "string", "description": "Keyword or phrase to search for"}, "fuzzy_search": {"type": "boolean", "description": "Whether to use fuzzy search", "default": False}, "edit_distance": {"type": "number", "description": "Edit distance for fuzzy search (between 0-2)", "default": 2}, "repo_path": {"type": "string", "description": "Optional: Path to the repository to restrict the search to."}},
"required": ["query"]
}
},
"analyze_code_relationships": {
"name": "analyze_code_relationships",
"description": "Analyze code relationships like 'who calls this function' or 'class hierarchy'. Supported query types include: find_callers, find_callees, find_all_callers, find_all_callees, find_importers, who_modifies, class_hierarchy, overrides, dead_code, call_chain, module_deps, variable_scope, find_complexity, find_functions_by_argument, find_functions_by_decorator.",
"inputSchema": {
"type": "object",
"properties": {
"query_type": {"type": "string", "description": "Type of relationship query to run.", "enum": ["find_callers", "find_callees", "find_all_callers", "find_all_callees", "find_importers", "who_modifies", "class_hierarchy", "overrides", "dead_code", "call_chain", "module_deps", "variable_scope", "find_complexity", "find_functions_by_argument", "find_functions_by_decorator"]},
"target": {"type": "string", "description": "The function, class, or module to analyze."},
"context": {"type": "string", "description": "Optional: specific file path for precise results."},
"repo_path": {"type": "string", "description": "Optional: Path to the repository to restrict the search to."}
},
"required": ["query_type", "target"]
}
},
"watch_directory": {
"name": "watch_directory",
"description": "Performs an initial scan of a directory and then continuously monitors it for changes, automatically keeping the graph up-to-date. Ideal for projects under active development. Returns a job ID for the initial scan.",
"inputSchema": {
"type": "object",
"properties": { "path": {"type": "string", "description": "Path to directory to watch"} },
"required": ["path"]
}
},
"execute_cypher_query": {
"name": "execute_cypher_query",
"description": "Fallback tool to run a direct, read-only Cypher query against the code graph. Use this for complex questions not covered by other tools. The graph contains nodes representing code structures and relationships between them. **Schema Overview:**\n- **Nodes:** `Repository`, `File`, `Module`, `Class`, `Function`.\n- **Properties:** Nodes have properties like `name`, `path`, `cyclomatic_complexity` (on Function nodes), and `source`.\n- **Relationships:** `CONTAINS` (e.g., File-[:CONTAINS]->Function), `CALLS` (Function-[:CALLS]->Function or File-[:CALLS]->Function), `IMPORTS` (File-[:IMPORTS]->Module), `INHERITS` (Class-[:INHERITS]->Class).",
"inputSchema": {
"type": "object",
"properties": { "cypher_query": {"type": "string", "description": "The read-only Cypher query to execute."} },
"required": ["cypher_query"]
}
},
"add_package_to_graph": {
"name": "add_package_to_graph",
"description": "Add a package to the graph by discovering its location. Supports multiple languages. Returns immediately with a job ID.",
"inputSchema": {
"type": "object",
"properties": {
"package_name": {"type": "string", "description": "Name of the package to add (e.g., 'requests', 'express', 'moment', 'lodash')."},
"language": {"type": "string", "description": "The programming language of the package.", "enum": ["python", "javascript", "typescript", "java", "c", "go", "ruby", "php","cpp"]},
"is_dependency": {"type": "boolean", "description": "Mark as a dependency.", "default": True}
},
"required": ["package_name", "language"]
}
},
"find_dead_code": {
"name": "find_dead_code",
"description": "Find potentially unused functions (dead code) across the entire indexed codebase, optionally excluding functions with specific decorators.",
"inputSchema": {
"type": "object",
"properties": {
"exclude_decorated_with": {"type": "array", "items": {"type": "string"}, "description": "Optional: A list of decorator names (e.g., '@app.route') to exclude from dead code detection.", "default": []},
"repo_path": {"type": "string", "description": "Optional: Path to the repository to restrict the search to."}
}
}
},
"calculate_cyclomatic_complexity": {
"name": "calculate_cyclomatic_complexity",
"description": "Calculate the cyclomatic complexity of a specific function to measure its complexity.",
"inputSchema": {
"type": "object",
"properties": {
"function_name": {"type": "string", "description": "The name of the function to analyze."},
"path": {"type": "string", "description": "Optional: The full path to the file containing the function for a more specific query."},
"repo_path": {"type": "string", "description": "Optional: Path to the repository to restrict the search to."}
},
"required": ["function_name"]
}
},
"find_most_complex_functions": {
"name": "find_most_complex_functions",
"description": "Find the most complex functions in the codebase based on cyclomatic complexity.",
"inputSchema": {
"type": "object",
"properties": {
"limit": {"type": "integer", "description": "The maximum number of complex functions to return.", "default": 10},
"repo_path": {"type": "string", "description": "Optional: Path to the repository to restrict the search to."}
}
}
},
"list_indexed_repositories": {
"name": "list_indexed_repositories",
"description": "List all indexed repositories.",
"inputSchema": {
"type": "object",
"properties": {}
}
},
"delete_repository": {
"name": "delete_repository",
"description": "Delete an indexed repository from the graph.",
"inputSchema": {
"type": "object",
"properties": {
"repo_path": {"type": "string", "description": "The path of the repository to delete."}
},
"required": ["repo_path"]
}
},
"visualize_graph_query": {
"name": "visualize_graph_query",
"description": "Generates a URL to visualize the results of a Cypher query in the Neo4j Browser. The user can open this URL in their web browser to see the graph visualization.",
"inputSchema": {
"type": "object",
"properties": {
"cypher_query": {"type": "string", "description": "The Cypher query to visualize."}
},
"required": ["cypher_query"]
}
},
"list_watched_paths": {
"name": "list_watched_paths",
"description": "Lists all directories currently being watched for live file changes.",
"inputSchema": {"type": "object", "properties": {}}
},
"unwatch_directory": {
"name": "unwatch_directory",
"description": "Stops watching a directory for live file changes.",
"inputSchema": {
"type": "object",
"properties": {
"path": {"type": "string", "description": "The absolute path of the directory to stop watching."}
},
"required": ["path"]
}
},
"load_bundle": {
"name": "load_bundle",
"description": "Load a pre-indexed .cgc bundle into the database. Can load from local file or automatically download from registry if not found locally. Bundles are portable snapshots of indexed code that load instantly without re-indexing.",
"inputSchema": {
"type": "object",
"properties": {
"bundle_name": {"type": "string", "description": "Name of the bundle to load (e.g., 'flask', 'pandas', 'flask-main-2579ce9.cgc'). Can be a full filename or just the package name."},
"clear_existing": {"type": "boolean", "description": "Whether to clear existing data before loading. Use with caution.", "default": False}
},
"required": ["bundle_name"]
}
},
"search_registry_bundles": {
"name": "search_registry_bundles",
"description": "Search for available pre-indexed bundles in the registry. Returns bundles matching the search query with details like repository, version, size, and download information.",
"inputSchema": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query to find bundles (searches in name, repository, and description). Leave empty to list all bundles."},
"unique_only": {"type": "boolean", "description": "If true, show only the most recent version of each package. If false, show all versions.", "default": False}
}
}
},
"get_repository_stats": {
"name": "get_repository_stats",
"description": "Get statistics about indexed repositories, including counts of files, functions, classes, and modules. Can show overall database statistics or stats for a specific repository.",
"inputSchema": {
"type": "object",
"properties": {
"repo_path": {"type": "string", "description": "Optional: Path to a specific repository. If not provided, returns overall database statistics."}
}
}
},
"discover_codegraph_contexts": {
"name": "discover_codegraph_contexts",
"description": "Scan child directories of the current workspace (or a given path) for .codegraphcontext folders that contain indexed code graph databases. Useful when the IDE is opened on a parent folder that itself has no database, but its sub-projects do.",
"inputSchema": {
"type": "object",
"properties": {
"path": {"type": "string", "description": "Optional: Root directory to scan. Defaults to the server's current working directory."},
"max_depth": {"type": "integer", "description": "How many levels of child directories to scan. Defaults to 1 (immediate children only).", "default": 1}
}
}
},
"switch_context": {
"name": "switch_context",
"description": "Switch the current MCP session to use a different .codegraphcontext database. Provide the path to the repo directory (or its .codegraphcontext/ folder). The server will reconnect to that database so subsequent queries use it. By default the mapping is saved globally for persistence across restarts.",
"inputSchema": {
"type": "object",
"properties": {
"context_path": {"type": "string", "description": "Path to the repository root that contains a .codegraphcontext/ folder, or directly to the .codegraphcontext/ folder itself."},
"save": {"type": "boolean", "description": "Whether to persist this mapping so the server reconnects automatically next time. Defaults to true.", "default": True}
},
"required": ["context_path"]
}
},
"generate_report": {
"name": "generate_report",
"description": "Generate a CGC_REPORT.md summarising god nodes (highest fan-in), most complex functions, cross-module coupling, potential dead code, and suggested Cypher queries. Use include_java=true to also include Spring endpoint tables, bean stereotype counts, and Maven module dependency summaries.",
"inputSchema": {
"type": "object",
"properties": {
"output_path": {"type": "string", "description": "Where to write the report. Defaults to CGC_REPORT.md in the server working directory."},
"include_java": {"type": "boolean", "description": "Include Spring/Maven Java-specific sections.", "default": False},
"god_node_limit": {"type": "integer", "description": "Max rows for god-nodes section.", "default": 15},
"complexity_limit": {"type": "integer", "description": "Max rows for complexity section.", "default": 15},
"cross_module_limit": {"type": "integer", "description": "Max rows for cross-module connections section.", "default": 20}
}
}
},
"find_java_spring_endpoints": {
"name": "find_java_spring_endpoints",
"description": "Find all Spring HTTP endpoint handler functions in the indexed Java codebase. Optionally filter by HTTP method (GET, POST, PUT, DELETE, PATCH) or URL path pattern.",
"inputSchema": {
"type": "object",
"properties": {
"http_method": {"type": "string", "description": "Optional: HTTP method to filter by (GET, POST, PUT, DELETE, PATCH).", "enum": ["GET", "POST", "PUT", "DELETE", "PATCH"]},
"path_pattern": {"type": "string", "description": "Optional: URL path substring to filter by (e.g. '/api/users')."},
"repo_path": {"type": "string", "description": "Optional: Restrict search to a specific repository path."}
}
}
},
"find_java_spring_beans": {
"name": "find_java_spring_beans",
"description": "Find Spring bean classes by stereotype (CONTROLLER, REST_CONTROLLER, SERVICE, REPOSITORY, COMPONENT, CONFIGURATION). Returns class names, file paths, and injection counts.",
"inputSchema": {
"type": "object",
"properties": {
"stereotype": {"type": "string", "description": "Optional: Filter by Spring stereotype.", "enum": ["CONTROLLER", "REST_CONTROLLER", "SERVICE", "REPOSITORY", "COMPONENT", "CONFIGURATION"]},
"repo_path": {"type": "string", "description": "Optional: Restrict search to a specific repository path."}
}
}
},
"find_datasource_nodes": {
"name": "find_datasource_nodes",
"description": "Query Datasource, DbTable, DbColumn, and RedisKeyPattern nodes in the code graph. Returns datasources and their tables/key-patterns, optionally filtered by kind or name.",
"inputSchema": {
"type": "object",
"properties": {
"kind": {
"type": "string",
"description": "Optional: Filter by datasource kind.",
"enum": ["mysql", "cassandra", "redis"]
},
"name": {
"type": "string",
"description": "Optional: Filter by datasource name (substring match)."
},
"include_columns": {
"type": "boolean",
"description": "If true, include DbColumn / RedisKeyPattern details in the response. Default false."
}
}
}
}
}