Skip to content

Commit e13cf0e

Browse files
authored
Merge pull request #48 from voarsh2/cli-fascade
MCP Bridge (ctxce) + Optional Auth: single MCP server (HTTP/stdio) for Indexer & Memory, VS Code auto‑wiring, backend auth endpoints
2 parents 1a56499 + 2f23704 commit e13cf0e

49 files changed

Lines changed: 6455 additions & 451 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ REFRAG_RUNTIME=llamacpp
128128
REFRAG_ENCODER_MODEL=BAAI/bge-base-en-v1.5
129129
REFRAG_PHI_PATH=/work/models/refrag_phi_768_to_dmodel.bin
130130
REFRAG_SENSE=heuristic
131+
REFRAG_PSEUDO_DESCRIBE=1
131132
GLM_API_KEY=
132133
# Llama.cpp sidecar (optional)
133134
# Use docker network hostname from containers; localhost remains ok for host-side runs if LLAMACPP_URL not exported
134135
LLAMACPP_URL=http://host.docker.internal:8081
135136
LLAMACPP_TIMEOUT_SEC=300
136137
DECODER_MAX_TOKENS=4000
137138
REFRAG_DECODER_MODE=prompt # prompt|soft
139+
REFRAG_COMMIT_DESCRIBE=1
138140

139141
REFRAG_SOFT_SCALE=1.0
140142
LLAMACPP_USE_GPU=1
@@ -149,6 +151,8 @@ MAX_MICRO_CHUNKS_PER_FILE=500
149151
QDRANT_TIMEOUT=20
150152
MEMORY_AUTODETECT=1
151153
MEMORY_COLLECTION_TTL_SECS=300
154+
SMART_SYMBOL_REINDEXING=1
155+
MAX_CHANGED_SYMBOLS_RATIO=0.6
152156

153157

154158
# Watcher-safe defaults (recommended)
@@ -196,4 +200,9 @@ INFO_REQUEST_LIMIT=10
196200
INFO_REQUEST_CONTEXT_LINES=5
197201
# INFO_REQUEST_EXPLAIN_DEFAULT=0
198202
# INFO_REQUEST_RELATIONSHIPS=0
203+
GLM_API_BASE=https://api.z.ai/api/coding/paas/v4/
204+
GLM_MODEL=glm-4.6
199205
COMMIT_VECTOR_SEARCH=0
206+
STRICT_MEMORY_RESTORE=1
207+
CTXCE_AUTH_ENABLED=0
208+
CTXCE_AUTH_ADMIN_TOKEN=change-me-admin-token

.env.example

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ REFRAG_PHI_PATH=/work/models/refrag_phi_768_to_dmodel.json
152152
REFRAG_SENSE=heuristic
153153

154154
# Enable index-time pseudo descriptions for micro-chunks (requires REFRAG_DECODER)
155-
# REFRAG_PSEUDO_DESCRIBE=1
155+
REFRAG_PSEUDO_DESCRIBE=1
156156

157157
# Llama.cpp sidecar (optional)
158158
# Docker CPU-only (stable): http://llamacpp:8080
@@ -189,7 +189,8 @@ MEMORY_AUTODETECT=1
189189
MEMORY_COLLECTION_TTL_SECS=300
190190

191191
# Smarter re-indexing for symbol cache, reuse embeddings and reduce decoder/pseudo tags to re-index
192-
SMART_SYMBOL_REINDEXING=0
192+
SMART_SYMBOL_REINDEXING=1
193+
MAX_CHANGED_SYMBOLS_RATIO=0.6
193194

194195
# Watcher-safe defaults (recommended)
195196
# Applied to watcher via compose; uncomment to apply globally.
@@ -226,7 +227,7 @@ SMART_SYMBOL_REINDEXING=0
226227
REFRAG_COMMIT_DESCRIBE=1
227228
COMMIT_VECTOR_SEARCH=0
228229

229-
STRICT_MEMORY_RESTORE=0
230+
STRICT_MEMORY_RESTORE=1
230231

231232
# info_request() tool settings (simplified codebase retrieval)
232233
# Default result limit for info_request queries
@@ -237,3 +238,60 @@ INFO_REQUEST_CONTEXT_LINES=5
237238
# INFO_REQUEST_EXPLAIN_DEFAULT=0
238239
# Enable relationship mapping by default (imports_from, calls, related_paths)
239240
# INFO_REQUEST_RELATIONSHIPS=0
241+
242+
243+
# ---------------------------------------------------------------------------
244+
# Optional Auth & Bridge Configuration (OFF by default)
245+
# ---------------------------------------------------------------------------
246+
247+
# Global auth toggle for backend services (upload_service, MCP indexer/memory).
248+
# When set to 1, services will require a valid session for protected operations.
249+
# When unset or 0, auth is disabled and behavior matches previous versions.
250+
# CTXCE_AUTH_ENABLED=0
251+
252+
# Shared token used by /auth/login for the bridge and other service clients.
253+
# When CTXCE_AUTH_ENABLED=1 and this is set, /auth/login will only issue
254+
# sessions when the provided token matches this value.
255+
# CTXCE_AUTH_SHARED_TOKEN=change-me-dev-token
256+
257+
# Create "open-dev" tokens when a shared token is unset, basically allows requesting a session with no real auth
258+
# CTXCE_AUTH_ALLOW_OPEN_TOKEN_LOGIN=0
259+
260+
# Optional admin token for creating additional users via /auth/users once the
261+
# first user has been bootstrapped. If unset, only the initial user can be
262+
# created (no additional users).
263+
# CTXCE_AUTH_ADMIN_TOKEN=change-me-admin-token
264+
265+
# Auth database location (default: sqlite file under WORK_DIR/.codebase).
266+
# Use a SQLite URL for local/dev, or point to a different path.
267+
# CTXCE_AUTH_DB_URL=sqlite:////work/.codebase/ctxce_auth.sqlite
268+
269+
# Session TTL (seconds) for issued auth sessions.
270+
# 0 or negative values disable expiry (sessions do not expire). When >0,
271+
# active sessions are extended with a sliding window whenever they are used.
272+
# CTXCE_AUTH_SESSION_TTL_SECONDS=0
273+
274+
# Collection registry & ACL (only used when CTXCE_AUTH_ENABLED=1).
275+
# When enabled, infrastructure/health checks may populate an internal SQLite
276+
# registry of known Qdrant collections, and ACL rules can be applied by services.
277+
278+
# ACL bypass (dev/early deployments): allow all users to access all collections.
279+
# CTXCE_ACL_ALLOW_ALL=0
280+
281+
# MCP boundary enforcement (OFF by default).
282+
# When enabled, MCP servers will enforce collection ACLs using the auth DB.
283+
# Requires CTXCE_AUTH_ENABLED=1. If CTXCE_ACL_ALLOW_ALL=1, enforcement is bypassed.
284+
# This is intended for gradually rolling out collection-level permissions without
285+
# changing existing client auth/session mechanisms.
286+
# CTXCE_MCP_ACL_ENFORCE=0
287+
288+
# Bridge-side configuration (ctx-mcp-bridge):
289+
# The bridge will POST to this URL for auth login and store the returned
290+
# session id, then inject it into all MCP tool calls as the `session` field.
291+
# CTXCE_AUTH_BACKEND_URL=http://localhost:8004
292+
293+
# Optional defaults for bridge CLI (env) auth:
294+
# CTXCE_AUTH_TOKEN=dev-shared-token
295+
# CTXCE_AUTH_USERNAME=you@example.com
296+
# CTXCE_AUTH_PASSWORD=your-password
297+

.github/workflows/publish-cli.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish ctxce CLI to npm
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version to publish (ensure package.json is updated)"
8+
required: false
9+
push:
10+
tags:
11+
- "ctxce-cli-v*"
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
id-token: write
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Use Node.js 20
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: "20"
26+
registry-url: "https://registry.npmjs.org"
27+
28+
- name: Install dependencies
29+
working-directory: ctx-mcp-bridge
30+
run: npm install
31+
32+
- name: Publish to npm
33+
working-directory: ctx-mcp-bridge
34+
run: npm publish --access public --provenance

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Model artifacts
44
models/
55

6+
# Node
7+
node_modules/
8+
69
# Qdrant snapshots
710
qdrant/snapshots/
811

ctx-mcp-bridge/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tgz

ctx-mcp-bridge/README.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Context Engine MCP Bridge
2+
3+
`@context-engine-bridge/context-engine-mcp-bridge` provides the `ctxce` CLI, a
4+
Model Context Protocol (MCP) bridge that speaks to the Context Engine indexer
5+
and memory servers and exposes them as a single MCP server.
6+
7+
It is primarily used by the VS Code **Context Engine Uploader** extension,
8+
available on the Marketplace:
9+
10+
- <https://marketplace.visualstudio.com/items?itemName=context-engine.context-engine-uploader>
11+
12+
The bridge can also be run standalone (e.g. from a terminal, or wired into
13+
other MCP clients) as long as the Context Engine stack is running.
14+
15+
## Prerequisites
16+
17+
- Node.js **>= 18** (see `engines` in `package.json`).
18+
- A running Context Engine stack (e.g. via `docker-compose.dev-remote.yml`) with:
19+
- MCP indexer HTTP endpoint (default: `http://localhost:8003/mcp`).
20+
- MCP memory HTTP endpoint (optional, default: `http://localhost:8002/mcp`).
21+
- For optional auth:
22+
- The upload/auth services must be configured with `CTXCE_AUTH_ENABLED=1` and
23+
a reachable auth backend URL (e.g. `http://localhost:8004`).
24+
25+
## Installation
26+
27+
You can install the package globally, or run it via `npx`.
28+
29+
### Global install
30+
31+
```bash
32+
npm install -g @context-engine-bridge/context-engine-mcp-bridge
33+
```
34+
35+
This installs the `ctxce` (and `ctxce-bridge`) CLI in your PATH.
36+
37+
### Using npx (no global install)
38+
39+
```bash
40+
npx @context-engine-bridge/context-engine-mcp-bridge ctxce --help
41+
```
42+
43+
The examples below assume `ctxce` is available on your PATH; if you use `npx`,
44+
just prefix commands with `npx @context-engine-bridge/context-engine-mcp-bridge`.
45+
46+
## CLI overview
47+
48+
The main entrypoint is:
49+
50+
```bash
51+
ctxce <command> [...args]
52+
```
53+
54+
Supported commands (from `src/cli.js`):
55+
56+
- `ctxce mcp-serve` – stdio MCP bridge (for stdio-based MCP clients).
57+
- `ctxce mcp-http-serve` – HTTP MCP bridge (for HTTP-based MCP clients).
58+
- `ctxce auth <subcmd>` – auth helper commands (`login`, `status`, `logout`).
59+
60+
### Environment variables
61+
62+
These environment variables are respected by the bridge:
63+
64+
- `CTXCE_INDEXER_URL` – MCP indexer URL (default: `http://localhost:8003/mcp`).
65+
- `CTXCE_MEMORY_URL` – MCP memory URL, or empty/omitted to disable memory
66+
(default: `http://localhost:8002/mcp`).
67+
- `CTXCE_HTTP_PORT` – port for `mcp-http-serve` (default: `30810`).
68+
69+
For auth (optional, shared with the upload/auth backend):
70+
71+
- `CTXCE_AUTH_ENABLED` – whether auth is enabled in the backend.
72+
- `CTXCE_AUTH_BACKEND_URL` – auth backend URL (e.g. `http://localhost:8004`).
73+
- `CTXCE_AUTH_TOKEN` – dev/shared token for `ctxce auth login`.
74+
- `CTXCE_AUTH_SESSION_TTL_SECONDS` – session TTL / sliding expiry (seconds).
75+
76+
The CLI also stores auth sessions in `~/.ctxce/auth.json`, keyed by backend URL.
77+
78+
## Running the MCP bridge (stdio)
79+
80+
The stdio bridge is suitable for MCP clients that speak stdio directly (for
81+
example, certain editors or tools that expect an MCP server on stdin/stdout).
82+
83+
```bash
84+
ctxce mcp-serve \
85+
--workspace /path/to/your/workspace \
86+
--indexer-url http://localhost:8003/mcp \
87+
--memory-url http://localhost:8002/mcp
88+
```
89+
90+
Flags:
91+
92+
- `--workspace` / `--path` – workspace root (default: current working directory).
93+
- `--indexer-url` – override indexer URL (default: `CTXCE_INDEXER_URL` or
94+
`http://localhost:8003/mcp`).
95+
- `--memory-url` – override memory URL (default: `CTXCE_MEMORY_URL` or
96+
disabled when empty).
97+
98+
## Running the MCP bridge (HTTP)
99+
100+
The HTTP bridge exposes the MCP server via an HTTP endpoint (default
101+
`http://127.0.0.1:30810/mcp`) and is what the VS Code extension uses in its
102+
`http` transport mode.
103+
104+
```bash
105+
ctxce mcp-http-serve \
106+
--workspace /path/to/your/workspace \
107+
--indexer-url http://localhost:8003/mcp \
108+
--memory-url http://localhost:8002/mcp \
109+
--port 30810
110+
```
111+
112+
Flags:
113+
114+
- `--workspace` / `--path` – workspace root (default: current working directory).
115+
- `--indexer-url` – MCP indexer URL.
116+
- `--memory-url` – MCP memory URL (or omit/empty to disable memory).
117+
- `--port` – HTTP port for the bridge (default: `CTXCE_HTTP_PORT`
118+
or `30810`).
119+
120+
Once running, you can point an MCP client at:
121+
122+
```text
123+
http://127.0.0.1:<port>/mcp
124+
```
125+
126+
## Auth helper commands (`ctxce auth ...`)
127+
128+
These commands are used both by the VS Code extension and standalone flows to
129+
log in and manage auth sessions for the backend.
130+
131+
### Login (token)
132+
133+
```bash
134+
ctxce auth login \
135+
--backend-url http://localhost:8004 \
136+
--token $CTXCE_AUTH_SHARED_TOKEN
137+
```
138+
139+
This hits the backend `/auth/login` endpoint and stores a session entry in
140+
`~/.ctxce/auth.json` under the given backend URL.
141+
142+
### Login (username/password)
143+
144+
```bash
145+
ctxce auth login \
146+
--backend-url http://localhost:8004 \
147+
--username your-user \
148+
--password your-password
149+
```
150+
151+
This calls `/auth/login/password` and persists the returned session the same
152+
way as the token flow.
153+
154+
### Status
155+
156+
Human-readable status:
157+
158+
```bash
159+
ctxce auth status --backend-url http://localhost:8004
160+
```
161+
162+
Machine-readable status (used by the VS Code extension):
163+
164+
```bash
165+
ctxce auth status --backend-url http://localhost:8004 --json
166+
```
167+
168+
The `--json` variant prints a single JSON object to stdout, for example:
169+
170+
```json
171+
{
172+
"backendUrl": "http://localhost:8004",
173+
"state": "ok", // "ok" | "missing" | "expired" | "missing_backend"
174+
"sessionId": "...",
175+
"userId": "user-123",
176+
"expiresAt": 0 // 0 or a Unix timestamp
177+
}
178+
```
179+
180+
Exit codes:
181+
182+
- `0``state: "ok"` (valid session present).
183+
- `1``state: "missing"` or `"missing_backend"`.
184+
- `2``state: "expired"`.
185+
186+
### Logout
187+
188+
```bash
189+
ctxce auth logout --backend-url http://localhost:8004
190+
```
191+
192+
Removes the stored auth entry for the given backend URL from
193+
`~/.ctxce/auth.json`.
194+
195+
## Relationship to the VS Code extension
196+
197+
The VS Code **Context Engine Uploader** extension is the recommended way to use
198+
this bridge for day-to-day development. It:
199+
200+
- Launches the standalone upload client to push code into the remote stack.
201+
- Starts/stops the MCP HTTP bridge (`ctxce mcp-http-serve`) for the active
202+
workspace when `autoStartMcpBridge` is enabled.
203+
- Uses `ctxce auth status --json` and `ctxce auth login` under the hood to
204+
manage user sessions via UI prompts.
205+
206+
This package README is aimed at advanced users who want to:
207+
208+
- Run the MCP bridge outside of VS Code.
209+
- Integrate the Context Engine MCP servers with other MCP-compatible clients.
210+
211+
You can safely mix both approaches: the extension and the standalone bridge
212+
share the same auth/session storage in `~/.ctxce/auth.json`.

ctx-mcp-bridge/bin/ctxce.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
import { runCli } from "../src/cli.js";
3+
4+
runCli().catch((err) => {
5+
console.error("[ctxce] Fatal error:", err && err.stack ? err.stack : err);
6+
process.exit(1);
7+
});

0 commit comments

Comments
 (0)