Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,15 @@ See [docs/architecture.md](docs/architecture.md#known-limitations) for the full

## Configuration

The MCP server reads an optional `.codeprism.toml` in the project root when it starts. The CLI
commands take their options as flags instead (`--languages`, `--workers`, ...).
The MCP server's startup index, `codeprism index` and the `index_project` MCP tool read an optional
`.codeprism.toml` in the project root. Explicit indexing flags or tool arguments override the file;
omitted options inherit it. For example, `index --languages python` overrides the configured language
list, and `--embeddings` / `--no-embeddings` override `enable_embeddings`. The MCP tool likewise accepts
`embeddings=true` or `embeddings=false`; omitting it preserves the file's setting.

Parser workers keep their entry-point defaults: CLI and MCP indexing use one process per CPU core
(`parse_workers = 0`), while library callers default to in-process parsing (`parse_workers = 1`).
Use `index --workers N` to override the CLI worker count.

```toml
[codeprism]
Expand Down
30 changes: 16 additions & 14 deletions codeprism/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def index(
None,
"--languages",
"-l",
help="Comma-separated language list (default: python,javascript,typescript,go,rust,java,c,cpp,ruby,php)",
help="Comma-separated language list (default: project config, or all supported languages)",
),
embeddings: bool = typer.Option(
False,
"--embeddings",
embeddings: bool | None = typer.Option(
None,
"--embeddings/--no-embeddings",
"-e",
help="Also build semantic vector index (requires codeprism[embeddings])",
help="Override semantic vector indexing (default: project config; requires codeprism[embeddings])",
),
force: bool = typer.Option(
False, "--force", "-f", help="Re-parse all files even if unchanged (skip incremental check)"
Expand All @@ -124,6 +124,7 @@ def index(

Re-runs are incremental by default: only changed or new files are parsed.
Use --force to re-parse everything from scratch.
Project .codeprism.toml settings apply unless explicitly overridden by flags.
"""
if languages:
requested_languages = [language.strip() for language in languages.split(",")]
Expand All @@ -148,22 +149,23 @@ def index(
async def _index(
path: str,
languages: str | None,
embeddings: bool = False,
embeddings: bool | None = None,
force: bool = False,
workers: int = 0,
) -> None:
from .core.config import CodePrismConfig
from .core.graph import GraphEngine
from .core.paths import get_db_path
from .core.paths import get_db_path, get_project_config_path
from .core.storage import StorageManager
from .indexer.project_indexer import ProjectIndexer

langs = [lang.strip() for lang in languages.split(",")] if languages else None
config = (
CodePrismConfig(languages=langs, enable_embeddings=embeddings, parse_workers=workers)
if langs
else CodePrismConfig(enable_embeddings=embeddings, parse_workers=workers)
)
config = CodePrismConfig.load(get_project_config_path(path))
if langs is not None:
config.languages = langs
if embeddings is not None:
config.enable_embeddings = embeddings
config.parse_workers = workers

db_path = get_db_path(path)
storage = StorageManager(db_path)
Expand All @@ -172,7 +174,7 @@ async def _index(

mode = "[dim](full re-index)[/dim]" if force else "[dim](incremental)[/dim]"
console.print(f"Indexing [bold]{path}[/bold] {mode}")
if embeddings:
if config.enable_embeddings:
console.print("[dim]Embeddings enabled — will build vector index after parsing...[/dim]")
indexer = ProjectIndexer(graph, storage, config)
result = await indexer.index(path, force=force)
Expand All @@ -193,7 +195,7 @@ async def _index(
f"{result.edge_count} edges · {result.duration_seconds:.2f}s"
f"{skipped_note}"
)
if embeddings:
if config.enable_embeddings:
console.print("[green]Semantic index built.[/green] search_symbol now uses embeddings.")
else:
console.print(f"[yellow]Completed with {len(result.errors)} error(s).[/yellow]")
Expand Down
19 changes: 11 additions & 8 deletions codeprism/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,28 @@ async def _lifespan(server: FastMCP) -> AsyncIterator[None]:
async def index_project(
path: str,
languages: list[str] | None = None,
embeddings: bool = False,
embeddings: bool | None = None,
) -> dict[str, Any]:
"""Build or rebuild the knowledge graph for a project directory.

embeddings: also build the vector index for semantic search (requires codeprism[embeddings]).
Load the project's .codeprism.toml, then override explicitly supplied languages
or embeddings. embeddings: build the vector index for semantic search
(requires codeprism[embeddings]); omit to inherit the project setting.
"""
global _engine
from ..core.config import CodePrismConfig
from ..core.graph import GraphEngine
from ..core.paths import get_db_path
from ..core.paths import get_db_path, get_project_config_path
from ..core.storage import StorageManager
from ..indexer.project_indexer import ProjectIndexer

# parse_workers=0: one parser process per core (the server entry point is guarded)
cfg = (
CodePrismConfig(languages=languages, enable_embeddings=embeddings, parse_workers=0)
if languages
else CodePrismConfig(enable_embeddings=embeddings, parse_workers=0)
)
cfg = CodePrismConfig.load(get_project_config_path(path))
if languages is not None:
cfg.languages = languages
if embeddings is not None:
cfg.enable_embeddings = embeddings
cfg.parse_workers = 0
db_path = get_db_path(path)
storage = StorageManager(db_path)
await storage.initialize()
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]

### Fixed
- CLI `index` and the `index_project` MCP tool now load `.codeprism.toml`, matching the server's
startup index. Explicit language and embedding options override the file, while omitted options
preserve it; `index --no-embeddings` can disable configured embeddings. Automatic CLI/MCP parser
workers and the library's in-process default remain unchanged. (#48)
- Substring symbol search ranks exact names and prefixes before limiting results. MCP
`search_symbol` now accepts `limit` (1-500, default 50) and reports filtered `total` and
`truncated`; kind/project filters apply before pagination. Semantic search keeps its
Expand Down
Loading
Loading