deepcode-hku 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cli/__init__.py +18 -0
- cli/cli_app.py +296 -0
- cli/cli_interface.py +744 -0
- cli/cli_launcher.py +155 -0
- cli/main_cli.py +243 -0
- cli/workflows/__init__.py +11 -0
- cli/workflows/cli_workflow_adapter.py +336 -0
- deepcode.py +219 -0
- deepcode_hku-1.0.1.dist-info/METADATA +695 -0
- deepcode_hku-1.0.1.dist-info/RECORD +44 -0
- deepcode_hku-1.0.1.dist-info/WHEEL +5 -0
- deepcode_hku-1.0.1.dist-info/entry_points.txt +2 -0
- deepcode_hku-1.0.1.dist-info/licenses/LICENSE +21 -0
- deepcode_hku-1.0.1.dist-info/top_level.txt +6 -0
- tools/__init__.py +0 -0
- tools/code_implementation_server.py +1045 -0
- tools/code_indexer.py +1657 -0
- tools/code_reference_indexer.py +486 -0
- tools/command_executor.py +324 -0
- tools/git_command.py +356 -0
- tools/pdf_converter.py +640 -0
- tools/pdf_downloader.py +1370 -0
- tools/pdf_utils.py +52 -0
- ui/__init__.py +43 -0
- ui/app.py +13 -0
- ui/components.py +1450 -0
- ui/handlers.py +773 -0
- ui/layout.py +106 -0
- ui/streamlit_app.py +38 -0
- ui/styles.py +2116 -0
- utils/__init__.py +17 -0
- utils/cli_interface.py +459 -0
- utils/dialogue_logger.py +671 -0
- utils/file_processor.py +426 -0
- utils/simple_llm_logger.py +198 -0
- workflows/__init__.py +31 -0
- workflows/agent_orchestration_engine.py +1371 -0
- workflows/agents/__init__.py +13 -0
- workflows/agents/code_implementation_agent.py +1093 -0
- workflows/agents/memory_agent_concise.py +923 -0
- workflows/agents/memory_agent_concise_index.py +935 -0
- workflows/code_implementation_workflow.py +924 -0
- workflows/code_implementation_workflow_index.py +931 -0
- workflows/codebase_index_workflow.py +726 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Code Reference Indexer MCP Tool - Unified Version
|
|
4
|
+
|
|
5
|
+
Specialized MCP tool for searching relevant index content in indexes folder
|
|
6
|
+
and formatting it for LLM code implementation reference.
|
|
7
|
+
|
|
8
|
+
Core Features:
|
|
9
|
+
1. **UNIFIED TOOL**: Combined search_code_references that handles directory setup, loading, and searching in one call
|
|
10
|
+
2. Match relevant reference code based on target file path and functionality requirements
|
|
11
|
+
3. Format output of relevant code examples, functions and concepts
|
|
12
|
+
4. Provide structured reference information for LLM use
|
|
13
|
+
|
|
14
|
+
Key Improvement:
|
|
15
|
+
- Single tool call that handles all steps internally
|
|
16
|
+
- Agent only needs to provide indexes_path and target_file
|
|
17
|
+
- No dependency on calling order or global state management
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Dict, List, Tuple
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
import logging
|
|
25
|
+
|
|
26
|
+
# Import MCP modules
|
|
27
|
+
from mcp.server.fastmcp import FastMCP
|
|
28
|
+
|
|
29
|
+
# Setup logging
|
|
30
|
+
logging.basicConfig(level=logging.INFO)
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
# Create FastMCP server instance
|
|
34
|
+
mcp = FastMCP("code-reference-indexer")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class CodeReference:
|
|
39
|
+
"""Code reference information structure"""
|
|
40
|
+
|
|
41
|
+
file_path: str
|
|
42
|
+
file_type: str
|
|
43
|
+
main_functions: List[str]
|
|
44
|
+
key_concepts: List[str]
|
|
45
|
+
dependencies: List[str]
|
|
46
|
+
summary: str
|
|
47
|
+
lines_of_code: int
|
|
48
|
+
repo_name: str
|
|
49
|
+
confidence_score: float = 0.0
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class RelationshipInfo:
|
|
54
|
+
"""Relationship information structure"""
|
|
55
|
+
|
|
56
|
+
repo_file_path: str
|
|
57
|
+
target_file_path: str
|
|
58
|
+
relationship_type: str
|
|
59
|
+
confidence_score: float
|
|
60
|
+
helpful_aspects: List[str]
|
|
61
|
+
potential_contributions: List[str]
|
|
62
|
+
usage_suggestions: str
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def load_index_files_from_directory(indexes_directory: str) -> Dict[str, Dict]:
|
|
66
|
+
"""Load all index files from specified directory"""
|
|
67
|
+
indexes_path = Path(indexes_directory).resolve()
|
|
68
|
+
|
|
69
|
+
if not indexes_path.exists():
|
|
70
|
+
logger.warning(f"Indexes directory does not exist: {indexes_path}")
|
|
71
|
+
return {}
|
|
72
|
+
|
|
73
|
+
index_cache = {}
|
|
74
|
+
|
|
75
|
+
for index_file in indexes_path.glob("*.json"):
|
|
76
|
+
try:
|
|
77
|
+
with open(index_file, "r", encoding="utf-8") as f:
|
|
78
|
+
index_data = json.load(f)
|
|
79
|
+
index_cache[index_file.stem] = index_data
|
|
80
|
+
logger.info(f"Loaded index file: {index_file.name}")
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.error(f"Failed to load index file {index_file.name}: {e}")
|
|
83
|
+
|
|
84
|
+
logger.info(f"Loaded {len(index_cache)} index files from {indexes_path}")
|
|
85
|
+
return index_cache
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def extract_code_references(index_data: Dict) -> List[CodeReference]:
|
|
89
|
+
"""Extract code reference information from index data"""
|
|
90
|
+
references = []
|
|
91
|
+
|
|
92
|
+
repo_name = index_data.get("repo_name", "Unknown")
|
|
93
|
+
file_summaries = index_data.get("file_summaries", [])
|
|
94
|
+
|
|
95
|
+
for file_summary in file_summaries:
|
|
96
|
+
reference = CodeReference(
|
|
97
|
+
file_path=file_summary.get("file_path", ""),
|
|
98
|
+
file_type=file_summary.get("file_type", ""),
|
|
99
|
+
main_functions=file_summary.get("main_functions", []),
|
|
100
|
+
key_concepts=file_summary.get("key_concepts", []),
|
|
101
|
+
dependencies=file_summary.get("dependencies", []),
|
|
102
|
+
summary=file_summary.get("summary", ""),
|
|
103
|
+
lines_of_code=file_summary.get("lines_of_code", 0),
|
|
104
|
+
repo_name=repo_name,
|
|
105
|
+
)
|
|
106
|
+
references.append(reference)
|
|
107
|
+
|
|
108
|
+
return references
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def extract_relationships(index_data: Dict) -> List[RelationshipInfo]:
|
|
112
|
+
"""Extract relationship information from index data"""
|
|
113
|
+
relationships = []
|
|
114
|
+
|
|
115
|
+
relationship_list = index_data.get("relationships", [])
|
|
116
|
+
|
|
117
|
+
for rel in relationship_list:
|
|
118
|
+
relationship = RelationshipInfo(
|
|
119
|
+
repo_file_path=rel.get("repo_file_path", ""),
|
|
120
|
+
target_file_path=rel.get("target_file_path", ""),
|
|
121
|
+
relationship_type=rel.get("relationship_type", ""),
|
|
122
|
+
confidence_score=rel.get("confidence_score", 0.0),
|
|
123
|
+
helpful_aspects=rel.get("helpful_aspects", []),
|
|
124
|
+
potential_contributions=rel.get("potential_contributions", []),
|
|
125
|
+
usage_suggestions=rel.get("usage_suggestions", ""),
|
|
126
|
+
)
|
|
127
|
+
relationships.append(relationship)
|
|
128
|
+
|
|
129
|
+
return relationships
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def calculate_relevance_score(
|
|
133
|
+
target_file: str, reference: CodeReference, keywords: List[str] = None
|
|
134
|
+
) -> float:
|
|
135
|
+
"""Calculate relevance score between reference code and target file"""
|
|
136
|
+
score = 0.0
|
|
137
|
+
|
|
138
|
+
# File name similarity
|
|
139
|
+
target_name = Path(target_file).stem.lower()
|
|
140
|
+
ref_name = Path(reference.file_path).stem.lower()
|
|
141
|
+
|
|
142
|
+
if target_name in ref_name or ref_name in target_name:
|
|
143
|
+
score += 0.3
|
|
144
|
+
|
|
145
|
+
# File type matching
|
|
146
|
+
target_extension = Path(target_file).suffix
|
|
147
|
+
ref_extension = Path(reference.file_path).suffix
|
|
148
|
+
|
|
149
|
+
if target_extension == ref_extension:
|
|
150
|
+
score += 0.2
|
|
151
|
+
|
|
152
|
+
# Keyword matching
|
|
153
|
+
if keywords:
|
|
154
|
+
keyword_matches = 0
|
|
155
|
+
total_searchable_text = (
|
|
156
|
+
" ".join(reference.key_concepts)
|
|
157
|
+
+ " "
|
|
158
|
+
+ " ".join(reference.main_functions)
|
|
159
|
+
+ " "
|
|
160
|
+
+ reference.summary
|
|
161
|
+
+ " "
|
|
162
|
+
+ reference.file_type
|
|
163
|
+
).lower()
|
|
164
|
+
|
|
165
|
+
for keyword in keywords:
|
|
166
|
+
if keyword.lower() in total_searchable_text:
|
|
167
|
+
keyword_matches += 1
|
|
168
|
+
|
|
169
|
+
if keywords:
|
|
170
|
+
score += (keyword_matches / len(keywords)) * 0.5
|
|
171
|
+
|
|
172
|
+
return min(score, 1.0)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def find_relevant_references_in_cache(
|
|
176
|
+
target_file: str,
|
|
177
|
+
index_cache: Dict[str, Dict],
|
|
178
|
+
keywords: List[str] = None,
|
|
179
|
+
max_results: int = 10,
|
|
180
|
+
) -> List[Tuple[CodeReference, float]]:
|
|
181
|
+
"""Find reference code relevant to target file from provided cache"""
|
|
182
|
+
all_references = []
|
|
183
|
+
|
|
184
|
+
# Collect reference information from all index files
|
|
185
|
+
for repo_name, index_data in index_cache.items():
|
|
186
|
+
references = extract_code_references(index_data)
|
|
187
|
+
for ref in references:
|
|
188
|
+
relevance_score = calculate_relevance_score(target_file, ref, keywords)
|
|
189
|
+
if relevance_score > 0.1: # Only keep results with certain relevance
|
|
190
|
+
all_references.append((ref, relevance_score))
|
|
191
|
+
|
|
192
|
+
# Sort by relevance score
|
|
193
|
+
all_references.sort(key=lambda x: x[1], reverse=True)
|
|
194
|
+
|
|
195
|
+
return all_references[:max_results]
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def find_direct_relationships_in_cache(
|
|
199
|
+
target_file: str, index_cache: Dict[str, Dict]
|
|
200
|
+
) -> List[RelationshipInfo]:
|
|
201
|
+
"""Find direct relationships with target file from provided cache"""
|
|
202
|
+
relationships = []
|
|
203
|
+
|
|
204
|
+
# Normalize target file path (remove rice/ prefix if exists)
|
|
205
|
+
normalized_target = target_file.replace("rice/", "").strip("/")
|
|
206
|
+
|
|
207
|
+
# Collect relationship information from all index files
|
|
208
|
+
for repo_name, index_data in index_cache.items():
|
|
209
|
+
repo_relationships = extract_relationships(index_data)
|
|
210
|
+
for rel in repo_relationships:
|
|
211
|
+
# Normalize target file path in relationship
|
|
212
|
+
normalized_rel_target = rel.target_file_path.replace("rice/", "").strip("/")
|
|
213
|
+
|
|
214
|
+
# Check target file path matching (support multiple matching methods)
|
|
215
|
+
if (
|
|
216
|
+
normalized_target == normalized_rel_target
|
|
217
|
+
or normalized_target in normalized_rel_target
|
|
218
|
+
or normalized_rel_target in normalized_target
|
|
219
|
+
or target_file in rel.target_file_path
|
|
220
|
+
or rel.target_file_path in target_file
|
|
221
|
+
):
|
|
222
|
+
relationships.append(rel)
|
|
223
|
+
|
|
224
|
+
# Sort by confidence score
|
|
225
|
+
relationships.sort(key=lambda x: x.confidence_score, reverse=True)
|
|
226
|
+
|
|
227
|
+
return relationships
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def format_reference_output(
|
|
231
|
+
target_file: str,
|
|
232
|
+
relevant_refs: List[Tuple[CodeReference, float]],
|
|
233
|
+
relationships: List[RelationshipInfo],
|
|
234
|
+
) -> str:
|
|
235
|
+
"""Format reference information output"""
|
|
236
|
+
output_lines = []
|
|
237
|
+
|
|
238
|
+
output_lines.append(f"# Code Reference Information - {target_file}")
|
|
239
|
+
output_lines.append("=" * 80)
|
|
240
|
+
output_lines.append("")
|
|
241
|
+
|
|
242
|
+
# Direct relationship information
|
|
243
|
+
if relationships:
|
|
244
|
+
output_lines.append("## 🎯 Direct Relationships")
|
|
245
|
+
output_lines.append("")
|
|
246
|
+
|
|
247
|
+
for i, rel in enumerate(relationships[:5], 1):
|
|
248
|
+
output_lines.append(f"### {i}. {rel.repo_file_path}")
|
|
249
|
+
output_lines.append(f"**Relationship Type**: {rel.relationship_type}")
|
|
250
|
+
output_lines.append(f"**Confidence Score**: {rel.confidence_score:.2f}")
|
|
251
|
+
output_lines.append(
|
|
252
|
+
f"**Helpful Aspects**: {', '.join(rel.helpful_aspects)}"
|
|
253
|
+
)
|
|
254
|
+
output_lines.append(
|
|
255
|
+
f"**Potential Contributions**: {', '.join(rel.potential_contributions)}"
|
|
256
|
+
)
|
|
257
|
+
output_lines.append(f"**Usage Suggestions**: {rel.usage_suggestions}")
|
|
258
|
+
output_lines.append("")
|
|
259
|
+
|
|
260
|
+
# Relevant code references
|
|
261
|
+
if relevant_refs:
|
|
262
|
+
output_lines.append("## 📚 Relevant Code References")
|
|
263
|
+
output_lines.append("")
|
|
264
|
+
|
|
265
|
+
for i, (ref, score) in enumerate(relevant_refs[:8], 1):
|
|
266
|
+
output_lines.append(f"### {i}. {ref.file_path} (Relevance: {score:.2f})")
|
|
267
|
+
output_lines.append(f"**Repository**: {ref.repo_name}")
|
|
268
|
+
output_lines.append(f"**File Type**: {ref.file_type}")
|
|
269
|
+
output_lines.append(
|
|
270
|
+
f"**Main Functions**: {', '.join(ref.main_functions[:5])}"
|
|
271
|
+
)
|
|
272
|
+
output_lines.append(f"**Key Concepts**: {', '.join(ref.key_concepts[:8])}")
|
|
273
|
+
output_lines.append(f"**Dependencies**: {', '.join(ref.dependencies[:6])}")
|
|
274
|
+
output_lines.append(f"**Lines of Code**: {ref.lines_of_code}")
|
|
275
|
+
output_lines.append(f"**Summary**: {ref.summary[:300]}...")
|
|
276
|
+
output_lines.append("")
|
|
277
|
+
|
|
278
|
+
# Implementation suggestions
|
|
279
|
+
output_lines.append("## 💡 Implementation Suggestions")
|
|
280
|
+
output_lines.append("")
|
|
281
|
+
|
|
282
|
+
if relevant_refs:
|
|
283
|
+
# Collect all function names and concepts
|
|
284
|
+
all_functions = set()
|
|
285
|
+
all_concepts = set()
|
|
286
|
+
all_dependencies = set()
|
|
287
|
+
|
|
288
|
+
for ref, _ in relevant_refs[:5]:
|
|
289
|
+
all_functions.update(ref.main_functions)
|
|
290
|
+
all_concepts.update(ref.key_concepts)
|
|
291
|
+
all_dependencies.update(ref.dependencies)
|
|
292
|
+
|
|
293
|
+
output_lines.append("**Reference Function Name Patterns**:")
|
|
294
|
+
for func in sorted(list(all_functions))[:10]:
|
|
295
|
+
output_lines.append(f"- {func}")
|
|
296
|
+
output_lines.append("")
|
|
297
|
+
|
|
298
|
+
output_lines.append("**Important Concepts and Patterns**:")
|
|
299
|
+
for concept in sorted(list(all_concepts))[:15]:
|
|
300
|
+
output_lines.append(f"- {concept}")
|
|
301
|
+
output_lines.append("")
|
|
302
|
+
|
|
303
|
+
output_lines.append("**Potential Dependencies Needed**:")
|
|
304
|
+
for dep in sorted(list(all_dependencies))[:10]:
|
|
305
|
+
output_lines.append(f"- {dep}")
|
|
306
|
+
output_lines.append("")
|
|
307
|
+
|
|
308
|
+
output_lines.append("## 🚀 Next Actions")
|
|
309
|
+
output_lines.append(
|
|
310
|
+
"1. Analyze design patterns and architectural styles from the above reference code"
|
|
311
|
+
)
|
|
312
|
+
output_lines.append("2. Determine core functionalities and interfaces to implement")
|
|
313
|
+
output_lines.append("3. Choose appropriate dependency libraries and tools")
|
|
314
|
+
output_lines.append(
|
|
315
|
+
"4. Design implementation solution consistent with existing code style"
|
|
316
|
+
)
|
|
317
|
+
output_lines.append("5. Start writing specific code implementation")
|
|
318
|
+
|
|
319
|
+
return "\n".join(output_lines)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
# ==================== MCP Tool Definitions ====================
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
@mcp.tool()
|
|
326
|
+
async def search_code_references(
|
|
327
|
+
indexes_path: str, target_file: str, keywords: str = "", max_results: int = 10
|
|
328
|
+
) -> str:
|
|
329
|
+
"""
|
|
330
|
+
**UNIFIED TOOL**: Search relevant reference code from index files for target file implementation.
|
|
331
|
+
This tool combines directory setup, index loading, and searching in a single call.
|
|
332
|
+
|
|
333
|
+
Args:
|
|
334
|
+
indexes_path: Path to the indexes directory containing JSON index files
|
|
335
|
+
target_file: Target file path (file to be implemented)
|
|
336
|
+
keywords: Search keywords, comma-separated
|
|
337
|
+
max_results: Maximum number of results to return
|
|
338
|
+
|
|
339
|
+
Returns:
|
|
340
|
+
Formatted reference code information JSON string
|
|
341
|
+
"""
|
|
342
|
+
try:
|
|
343
|
+
# Step 1: Load index files from specified directory
|
|
344
|
+
logger.info(f"Loading index files from: {indexes_path}")
|
|
345
|
+
index_cache = load_index_files_from_directory(indexes_path)
|
|
346
|
+
|
|
347
|
+
if not index_cache:
|
|
348
|
+
result = {
|
|
349
|
+
"status": "error",
|
|
350
|
+
"message": f"No index files found or failed to load from: {indexes_path}",
|
|
351
|
+
"target_file": target_file,
|
|
352
|
+
"indexes_path": indexes_path,
|
|
353
|
+
}
|
|
354
|
+
return json.dumps(result, ensure_ascii=False, indent=2)
|
|
355
|
+
|
|
356
|
+
# Step 2: Parse keywords
|
|
357
|
+
keyword_list = (
|
|
358
|
+
[kw.strip() for kw in keywords.split(",") if kw.strip()] if keywords else []
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
# Step 3: Find relevant reference code
|
|
362
|
+
relevant_refs = find_relevant_references_in_cache(
|
|
363
|
+
target_file, index_cache, keyword_list, max_results
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
# Step 4: Find direct relationships
|
|
367
|
+
relationships = find_direct_relationships_in_cache(target_file, index_cache)
|
|
368
|
+
|
|
369
|
+
# Step 5: Format output
|
|
370
|
+
formatted_output = format_reference_output(
|
|
371
|
+
target_file, relevant_refs, relationships
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
result = {
|
|
375
|
+
"status": "success",
|
|
376
|
+
"target_file": target_file,
|
|
377
|
+
"indexes_path": indexes_path,
|
|
378
|
+
"keywords_used": keyword_list,
|
|
379
|
+
"total_references_found": len(relevant_refs),
|
|
380
|
+
"total_relationships_found": len(relationships),
|
|
381
|
+
"formatted_content": formatted_output,
|
|
382
|
+
"indexes_loaded": list(index_cache.keys()),
|
|
383
|
+
"total_indexes_loaded": len(index_cache),
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
logger.info(
|
|
387
|
+
f"Successfully found {len(relevant_refs)} references and {len(relationships)} relationships for {target_file}"
|
|
388
|
+
)
|
|
389
|
+
return json.dumps(result, ensure_ascii=False, indent=2)
|
|
390
|
+
|
|
391
|
+
except Exception as e:
|
|
392
|
+
logger.error(f"Error in search_code_references: {str(e)}")
|
|
393
|
+
result = {
|
|
394
|
+
"status": "error",
|
|
395
|
+
"message": f"Failed to search reference code: {str(e)}",
|
|
396
|
+
"target_file": target_file,
|
|
397
|
+
"indexes_path": indexes_path,
|
|
398
|
+
}
|
|
399
|
+
return json.dumps(result, ensure_ascii=False, indent=2)
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
@mcp.tool()
|
|
403
|
+
async def get_indexes_overview(indexes_path: str) -> str:
|
|
404
|
+
"""
|
|
405
|
+
Get overview of all available reference code index information from specified directory
|
|
406
|
+
|
|
407
|
+
Args:
|
|
408
|
+
indexes_path: Path to the indexes directory containing JSON index files
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
Overview information of all available reference code JSON string
|
|
412
|
+
"""
|
|
413
|
+
try:
|
|
414
|
+
# Load index files from specified directory
|
|
415
|
+
index_cache = load_index_files_from_directory(indexes_path)
|
|
416
|
+
|
|
417
|
+
if not index_cache:
|
|
418
|
+
result = {
|
|
419
|
+
"status": "error",
|
|
420
|
+
"message": f"No index files found in: {indexes_path}",
|
|
421
|
+
"indexes_path": indexes_path,
|
|
422
|
+
}
|
|
423
|
+
return json.dumps(result, ensure_ascii=False, indent=2)
|
|
424
|
+
|
|
425
|
+
overview = {"total_repos": len(index_cache), "repositories": {}}
|
|
426
|
+
|
|
427
|
+
for repo_name, index_data in index_cache.items():
|
|
428
|
+
repo_info = {
|
|
429
|
+
"repo_name": index_data.get("repo_name", repo_name),
|
|
430
|
+
"total_files": index_data.get("total_files", 0),
|
|
431
|
+
"file_types": [],
|
|
432
|
+
"main_concepts": [],
|
|
433
|
+
"total_relationships": len(index_data.get("relationships", [])),
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
# Collect file types and concepts
|
|
437
|
+
file_summaries = index_data.get("file_summaries", [])
|
|
438
|
+
file_types = set()
|
|
439
|
+
concepts = set()
|
|
440
|
+
|
|
441
|
+
for file_summary in file_summaries:
|
|
442
|
+
file_types.add(file_summary.get("file_type", "Unknown"))
|
|
443
|
+
concepts.update(file_summary.get("key_concepts", []))
|
|
444
|
+
|
|
445
|
+
repo_info["file_types"] = sorted(list(file_types))
|
|
446
|
+
repo_info["main_concepts"] = sorted(list(concepts))[
|
|
447
|
+
:20
|
|
448
|
+
] # Limit concept count
|
|
449
|
+
|
|
450
|
+
overview["repositories"][repo_name] = repo_info
|
|
451
|
+
|
|
452
|
+
result = {
|
|
453
|
+
"status": "success",
|
|
454
|
+
"overview": overview,
|
|
455
|
+
"indexes_directory": str(Path(indexes_path).resolve()),
|
|
456
|
+
"total_indexes_loaded": len(index_cache),
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return json.dumps(result, ensure_ascii=False, indent=2)
|
|
460
|
+
|
|
461
|
+
except Exception as e:
|
|
462
|
+
result = {
|
|
463
|
+
"status": "error",
|
|
464
|
+
"message": f"Failed to get indexes overview: {str(e)}",
|
|
465
|
+
"indexes_path": indexes_path,
|
|
466
|
+
}
|
|
467
|
+
return json.dumps(result, ensure_ascii=False, indent=2)
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def main():
|
|
471
|
+
"""Main function"""
|
|
472
|
+
logger.info("Starting unified Code Reference Indexer MCP server")
|
|
473
|
+
logger.info("Available tools:")
|
|
474
|
+
logger.info(
|
|
475
|
+
"1. search_code_references(indexes_path, target_file, keywords, max_results) - UNIFIED TOOL"
|
|
476
|
+
)
|
|
477
|
+
logger.info(
|
|
478
|
+
"2. get_indexes_overview(indexes_path) - Get overview of available indexes"
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
# Run MCP server
|
|
482
|
+
mcp.run()
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
if __name__ == "__main__":
|
|
486
|
+
main()
|