MCPcopy Create free account
hub / github.com/cocoindex-io/cocoindex-code / main

Function main

src/cocoindex_code/server.py:177–332  ·  view source on GitHub ↗

Backward-compatible entry point for ``cocoindex-code`` CLI. Auto-detects/creates settings from env vars, then delegates to daemon.

()

Source from the content-addressed store, hash-verified

175
176
177def main() -> None:
178 """Backward-compatible entry point for ``cocoindex-code`` CLI.
179
180 Auto-detects/creates settings from env vars, then delegates to daemon.
181 """
182 import argparse
183
184 from .settings import (
185 EmbeddingSettings,
186 LanguageOverride,
187 default_project_settings,
188 default_user_settings,
189 find_legacy_project_root,
190 find_project_root,
191 project_settings_path,
192 save_project_settings,
193 save_user_settings,
194 user_settings_path,
195 )
196
197 parser = argparse.ArgumentParser(
198 prog="cocoindex-code",
199 description="MCP server for codebase indexing and querying.",
200 )
201 subparsers = parser.add_subparsers(dest="command")
202 subparsers.add_parser("serve", help="Run the MCP server (default)")
203 subparsers.add_parser("index", help="Build/refresh the index and report stats")
204 args = parser.parse_args()
205
206 # --- Discover project root ---
207 cwd = Path.cwd()
208 project_root = find_project_root(cwd)
209
210 if project_root is None:
211 # Try env var
212 env_root = os.environ.get("COCOINDEX_CODE_ROOT_PATH")
213 if env_root:
214 project_root = Path(env_root).resolve()
215 else:
216 # Use marker-based discovery
217 legacy_root = find_legacy_project_root(cwd)
218 project_root = legacy_root if legacy_root is not None else cwd
219
220 # --- Auto-create project settings if needed ---
221 proj_settings_file = project_settings_path(project_root)
222 if not proj_settings_file.is_file():
223 ps = default_project_settings()
224
225 # Migrate COCOINDEX_CODE_EXCLUDED_PATTERNS
226 raw_excluded = os.environ.get("COCOINDEX_CODE_EXCLUDED_PATTERNS", "").strip()
227 if raw_excluded:
228 try:
229 extra_excluded = json.loads(raw_excluded)
230 if isinstance(extra_excluded, list):
231 ps.exclude_patterns.extend(
232 p.strip() for p in extra_excluded if isinstance(p, str) and p.strip()
233 )
234 except json.JSONDecodeError:

Callers 1

__main__.pyFile · 0.70

Calls 14

find_project_rootFunction · 0.85
find_legacy_project_rootFunction · 0.85
project_settings_pathFunction · 0.85
default_project_settingsFunction · 0.85
LanguageOverrideClass · 0.85
save_project_settingsFunction · 0.85
user_settings_pathFunction · 0.85
default_user_settingsFunction · 0.85
_convert_embedding_modelFunction · 0.85
EmbeddingSettingsClass · 0.85
save_user_settingsFunction · 0.85
create_mcp_serverFunction · 0.85

Tested by

no test coverage detected