feat: add HTTP transport mode and server config file support#80
feat: add HTTP transport mode and server config file support#80PatrickSys merged 4 commits intomasterfrom
Conversation
Reads ~/.codebase-context/config.json on startup to pre-register project roots and per-project exclude pattern overrides without requiring a connected MCP client. Config roots are additive — they survive syncKnownRoots() refreshes from client root changes. - src/server/config.ts: new module to load/parse config file - src/project-state.ts: add extraExcludePatterns field - src/index.ts: wire applyServerConfig() in main() and startHttp(), preserve configRoots in syncKnownRoots(), merge extraExcludePatterns in performIndexingOnce() - tests/server-config.test.ts: 11 unit tests covering all edge paths
Greptile SummaryThis PR adds two related capabilities: an SSE-based HTTP transport mode ( Key changes:
Issues found:
Confidence Score: 4/5Safe to merge after addressing the empty-root-resolves-to-CWD bug; all other issues are minor style/quality items. The core logic is sound — configRoots survive syncs, port priority ordering is correct, error handling is graceful, and test coverage is solid. One concrete P1 bug exists: a config entry without a src/server/config.ts — the missing-root-defaults-to-CWD issue and the unbounded port range check both live here.
|
| Filename | Overview |
|---|---|
| src/server/config.ts | New config loader for ~/.codebase-context/config.json; solid error handling and tilde expansion, but a missing root field silently resolves to CWD via path.resolve(''), and port validation doesn't cap at 65535. |
| src/index.ts | Integrates config loading into both stdio (main) and HTTP (startHttp) startup paths; configRoots map correctly survives syncKnownRoots() refreshes; extraExcludePatterns are applied at index time; loadServerConfig() is called twice in the HTTP path (minor redundancy). |
| src/project-state.ts | Minimal, clean addition of optional extraExcludePatterns field to ProjectState with a clear doc comment. |
| tests/server-config.test.ts | 11 well-scoped tests covering ENOENT, malformed JSON, invalid types, tilde/relative path resolution, valid config, and port validation edge cases; no gaps found. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
CLI[CLI startup] --> HTTP{--http flag?}
HTTP -->|yes| SH[startHttp]
HTTP -->|no| MAIN[main]
SH --> LC1[loadServerConfig]
MAIN --> LC2[loadServerConfig]
LC1 --> ASC1[applyServerConfig]
LC2 --> ASC2[applyServerConfig]
ASC1 --> CR[configRoots map]
ASC2 --> CR
ASC1 --> EP[project.extraExcludePatterns]
ASC2 --> EP
SH --> PR[Port resolution CLI flag > env var > config > 3100]
PR --> HS[startHttpServer host:port]
MAIN --> STDIO[StdioServerTransport]
SYNC[syncKnownRoots client roots change] --> CHK{configRoot missing from nextRoots?}
CHK -->|yes| ADD[re-add from configRoots]
CHK -->|no| KEEP[keep client entry]
ADD --> KR[knownRoots]
KEEP --> KR
EP --> IDX[performIndexingOnce CodebaseIndexer with merged excludePatterns]
Reviews (1): Last reviewed commit: "style: apply prettier formatting" | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a844e53727
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PatrickSys
left a comment
There was a problem hiding this comment.
Adversarial review complete on commit 912e6f6.
I found one real correctness bug in the new config parser: malformed projects[] entries without a usable root were resolving to process.cwd(). That is fixed now, along with a regression test. I also tightened server.port validation to reject values above 65535.
I reviewed the existing inline comments, replied to each one, and resolved the threads. I am not merging this PR because GitHub still reports Quality Checks failing on the repo's existing pnpm audit --prod vulnerabilities (2 vulnerabilities found, 1 moderate | 1 high). The PR-specific code paths build, type-check, and the full test suite passes locally, but the PR is still not in a clean mergeable state.
Summary
--httpflag starts an SSE-based MCP server on a configurable port (default 3100), alongside the existing stdio mode. SupportsCODEBASE_CONTEXT_PORTenv var and~/.codebase-context/config.jsonport override. Includes factory and HTTP server modules with proper connection lifecycle management.~/.codebase-context/config.jsonis read on startup to pre-register project roots and per-projectexcludePatterns— no MCP client connection required. Config roots are additive and survivesyncKnownRoots()refreshes from client root changes.Test plan
pnpm run buildexits 0pnpm run test— all 323 tests pass, including 11 new tests intests/server-config.test.ts--http, connect an MCP client tohttp://localhost:3100/sse, verify tools respond~/.codebase-context/config.jsonwith a project root, start server (stdio or HTTP), verify root is pre-indexed without client sending rootsCODEBASE_CONTEXT_PORT=4000 codebase-context --http— server binds to port 4000