|
| 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`. |
0 commit comments