Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /ViperJuice_Code-Index-MCP /examples /demo_index_management.py
| #!/usr/bin/env python3 | |
| """ | |
| Demonstration of MCP Portable Index Management | |
| Shows how the system works when properly authenticated with GitHub | |
| """ | |
| import json | |
| import subprocess | |
| from pathlib import Path | |
| from datetime import datetime | |
| def print_section(title): | |
| print(f"\n{'='*60}") | |
| print(f" {title}") | |
| print(f"{'='*60}\n") | |
| def demo_index_discovery(): | |
| """Demonstrate index discovery functionality""" | |
| print_section("1. INDEX DISCOVERY") | |
| from mcp_server.utils.index_discovery import IndexDiscovery | |
| discovery = IndexDiscovery(Path('.')) | |
| info = discovery.get_index_info() | |
| print("๐ Index Discovery Results:") | |
| print(f" โ Enabled: {info['enabled']}") | |
| print(f" โ Has local index: {info['has_local_index']}") | |
| print(f" โ Auto-download: {info['auto_download']}") | |
| print(f" โ GitHub artifacts: {info['github_artifacts']}") | |
| if info['metadata']: | |
| print("\n๐ Index Metadata:") | |
| meta = info['metadata'] | |
| print(f" - Version: {meta.get('version')}") | |
| print(f" - Created: {meta.get('created_at')}") | |
| print(f" - Files: {meta.get('indexed_files')}") | |
| print(f" - Size: {meta.get('index_size_bytes', 0) / 1024 / 1024:.1f} MB") | |
| def demo_mcp_server_startup(): | |
| """Demonstrate MCP server startup with portable index""" | |
| print_section("2. MCP SERVER STARTUP") | |
| print("๐ When MCP server starts:") | |
| print(" 1. Checks for .mcp-index.json") | |
| print(" 2. Detects portable index at .mcp-index/code_index.db") | |
| print(" 3. Uses portable index instead of default") | |
| print(" 4. No reindexing needed - instant startup!") | |
| # Show the actual code that runs | |
| print("\n๐ Code executed in mcp_server_cli.py:") | |
| print(""" | |
| discovery = IndexDiscovery(workspace_root) | |
| if discovery.is_index_enabled(): | |
| index_path = discovery.get_local_index_path() | |
| if index_path: | |
| sqlite_store = SQLiteStore(str(index_path)) | |
| """) | |
| def demo_cli_commands(): | |
| """Demonstrate CLI commands""" | |
| print_section("3. CLI COMMANDS") | |
| print("๐ Available mcp-index commands:") | |
| commands = [ | |
| ("mcp-index init", "Initialize index management in any repo"), | |
| ("mcp-index build", "Build index locally"), | |
| ("mcp-index push", "Upload to GitHub artifacts"), | |
| ("mcp-index pull", "Download latest index"), | |
| ("mcp-index sync", "Smart sync (pull if needed, push if newer)"), | |
| ("mcp-index info", "Show current index status"), | |
| ("mcp-index list", "List available artifacts"), | |
| ("mcp-index toggle --disable", "Disable indexing") | |
| ] | |
| for cmd, desc in commands: | |
| print(f" $ {cmd:<25} # {desc}") | |
| def demo_github_workflow(): | |
| """Demonstrate GitHub workflow""" | |
| print_section("4. GITHUB WORKFLOW") | |
| print("โ๏ธ Workflow triggers:") | |
| print(" - Push to main branch") | |
| print(" - Pull requests") | |
| print(" - Weekly schedule") | |
| print(" - Manual dispatch") | |
| print("\n๐ฆ Workflow steps:") | |
| print(" 1. Check if indexing enabled (via MCP_INDEX_ENABLED)") | |
| print(" 2. Try to download existing index") | |
| print(" 3. Build index if needed") | |
| print(" 4. Compress to ~9MB (from 41MB)") | |
| print(" 5. Upload as GitHub artifact") | |
| print(" 6. Validate checksum") | |
| print(" 7. Update PR comment with stats") | |
| print(" 8. Clean up old artifacts (30+ days)") | |
| def demo_cost_analysis(): | |
| """Show cost analysis""" | |
| print_section("5. COST ANALYSIS") | |
| print("๐ฐ For Public Repositories:") | |
| print(" โ Storage: FREE (unlimited artifacts)") | |
| print(" โ Bandwidth: FREE (unlimited downloads)") | |
| print(" โ Compute: ZERO (all indexing local)") | |
| print(" โ Retention: 90 days max") | |
| print("\n๐ณ For Private Repositories:") | |
| print(" - Storage: Free up to 500MB per artifact") | |
| print(" - Our index: ~9MB compressed (well under limit)") | |
| print(" - Bandwidth: Counts against Actions minutes") | |
| print(" - Compute: Still ZERO (local indexing)") | |
| def demo_developer_workflow(): | |
| """Show typical developer workflow""" | |
| print_section("6. DEVELOPER WORKFLOW") | |
| print("๐ฉโ๐ป New Developer Joins Team:") | |
| print(" 1. Clone repository") | |
| print(" 2. MCP detects .mcp-index.json") | |
| print(" 3. Auto-downloads latest index (9MB)") | |
| print(" 4. Instant code navigation - no wait!") | |
| print("\n๐จโ๐ป Developer Makes Changes:") | |
| print(" 1. Edit code files") | |
| print(" 2. Run 'mcp-index sync'") | |
| print(" 3. Index updates locally") | |
| print(" 4. Push changes") | |
| print(" 5. GitHub workflow updates artifact") | |
| print("\n๐ค CI/CD Integration:") | |
| print(" - PR gets dedicated index artifact") | |
| print(" - Main branch maintains latest index") | |
| print(" - Old artifacts auto-cleaned after 30 days") | |
| def main(): | |
| print("\n๐ฏ MCP PORTABLE INDEX MANAGEMENT DEMONSTRATION") | |
| print("="*60) | |
| # Check if we're in the right directory | |
| if not Path('.mcp-index.json').exists(): | |
| print("โ Error: Not in a repository with MCP index management") | |
| print(" Run 'mcp-index init' first") | |
| return | |
| # Run demonstrations | |
| demo_index_discovery() | |
| demo_mcp_server_startup() | |
| demo_cli_commands() | |
| demo_github_workflow() | |
| demo_cost_analysis() | |
| demo_developer_workflow() | |
| print_section("SUMMARY") | |
| print("โ MCP Portable Index Management provides:") | |
| print(" โข Zero-setup experience for developers") | |
| print(" โข No GitHub compute costs") | |
| print(" โข Fast 9MB downloads vs slow reindexing") | |
| print(" โข Works with any repository") | |
| print(" โข Supports all 48 MCP languages") | |
| print("\n๐ Ready for production use!") | |
| if __name__ == "__main__": | |
| main() |
Xet Storage Details
- Size:
- 5.83 kB
- Xet hash:
- aec944fb97defb1ca982923b607b0805a6cd15ed8fe292b784a2dd8de26024fb
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.