Skip to content

Latest commit

 

History

History
119 lines (85 loc) · 15.2 KB

server.md

File metadata and controls

119 lines (85 loc) · 15.2 KB

HTTP server, MCP 2026 transport, and Web UI

Gortex exposes three transports — stdio MCP (the default gortex mcp), a Unix-socket daemon, and an HTTP API. The HTTP layer is what IDE plugins, CI, the web UI, and remote agents talk to.

Server mode (/v1/* JSON API)

The daemon exposes all MCP tools as an HTTP/JSON API under versioned /v1/* routes once you give it an HTTP address: the --http-addr flag, the GORTEX_DAEMON_HTTP_ADDR env var, or daemon.http_addr in the global config (~/.gortex/config.yaml, or $XDG_CONFIG_HOME/gortex/config.yaml when XDG_CONFIG_HOME is an absolute path), in that order of precedence. The address is read at startup. A daemon run by gortex daemon install-service starts without flags, so use the config key there. The daemon serves the repos you track, so add the repo first, then bring the HTTP surface up:

# Track the repo (or run from inside it — the cwd's repo auto-tracks), then start the HTTP backend
gortex track /path/to/repo
gortex daemon start --http-addr 127.0.0.1:7411

# Non-localhost bind requires an auth token
gortex daemon start --http-addr 0.0.0.0:7411 --http-auth-token "$(openssl rand -hex 32)"

# Or keep the address in config, e.g. for the install-service daemon:
#   ~/.gortex/config.yaml (or $XDG_CONFIG_HOME/gortex/config.yaml)
#   daemon:
#     http_addr: 127.0.0.1:7411

# Optional one-shot HTTP API alongside MCP stdio; first enable
# mcp.allow_embedded in the user-level config.
gortex mcp --index /path/to/repo --server --port 8765

Endpoints (all under /v1/):

Endpoint Method Description
/v1/health GET Status, node/edge counts, uptime
/v1/tools GET List all available tools with descriptions
/v1/tools/{name} POST Invoke any MCP tool with JSON arguments. Accepts ?format=gcx or top-level "format" in the body. Under the core/defer default surface, aliased analyze kinds (processes, communities, contracts, …) are routed through the facade to their legacy handlers without requiring tools_search promotion — the dashboard's /v1/processes, /v1/communities, and /v1/contracts endpoints rely on this. Non-aliased kinds dispatch as usual.
/v1/stats GET Graph statistics by kind and language, plus server_id + started_at
/v1/graph GET Full brief-graph dump (nodes + edges + stats); accepts ?project= and/or ?repo= for scoping
/v1/graph/constellation GET Bounded graph preview with precomputed positions and indexed edges
/v1/events GET SSE stream of graph-change events (the daemon watches tracked repos by default)

Auth & binding. A localhost --http-addr (e.g. 127.0.0.1:7411) permits local clients without a token. Pass --http-auth-token <token> or set $GORTEX_DAEMON_HTTP_TOKEN to require Authorization: Bearer <token> on every /mcp and /v1/* request (constant-time compare; CORS preflights bypass auth). A token is recommended even on loopback; non-localhost binds without one are rejected at startup. /healthz is exempt from auth so liveness probes work.

HTTP sessions are agent sessions. Every /mcp and /v1/tools call is confined like an MCP agent, with or without an X-Gortex-Cwd header: caller-named paths must resolve inside a tracked repository, Git metadata and agent / editor configuration are not writable, and track_repository refuses force and non-repository roots. Out-of-repository writes (gortex export --out, generated docs) and force-tracking a broad root need the gortex CLI, which declares the operator role on its daemon connection. See SECURITY.md.

Browser access. Loopback is reachable by web pages. Both /mcp and /v1, including preflights, reject every browser Origin by default. To permit a trusted web UI, set both --http-allowed-origin https://ui.example (authorization to call the API) and --cors-origin https://ui.example (CORS response headers). Origin checks still apply when a valid token is supplied. CORS defaults to disabled; an explicit --cors-origin '*' does not bypass the Origin allowlist. Requests without an Origin header, such as ordinary CLI clients, retain their existing access and token checks. A request with no Origin but Sec-Fetch-Site: cross-site or same-site (a browser loading the URL as an <img>, <script> or iframe from another site) is refused; the one exception is a top-level navigation (GET with Sec-Fetch-Mode: navigate and Sec-Fetch-Dest: document), e.g. following a link or a script-driven redirect, whose response the page that started it cannot read. A ?cwd= query on such a cross-site request is ignored; the X-Gortex-Cwd header is not. Every response carries X-Content-Type-Options: nosniff and Cross-Origin-Resource-Policy: same-origin. A * or null entry in --http-allowed-origin names no single site, so it is ignored with a startup warning.

Host check (DNS rebinding). While no token is configured, the listener answers only to local Host names — localhost (also localhost.), 127.0.0.1, [::1], Docker's host.docker.internal and gateway.docker.internal (each also with a trailing dot), with any port, or no Host at all (an HTTP/1.0 health check) — and returns 403 for any other name. Where the Docker names are not pinned in the hosts file, an attacker controlling DNS on your network could rebind one of them to a page they serve; such a page reaches only GET routes (tool calls and other POSTs carry its Origin and are refused). Set a token to rule that out. A page whose domain has been re-pointed at 127.0.0.1 is same-origin with the listener and sends no Origin, but its Host still names that domain. To reach a token-less listener by another name (an /etc/hosts alias, a devcontainer or VM hostname), pass --http-allowed-host <name> (repeatable; on the daemon it applies to /mcp and every /v1 route, and --conversation-host is its older spelling). gortex mcp --server and gortex eval-server take the same flag. With a token set the Host is not checked, so a non-loopback bind with --http-auth-token works under its own name.

From a container on Docker Desktop, the host's daemon answers at host.docker.internal with no extra flag:

# on the host
gortex daemon start --http-addr 127.0.0.1:7411
# inside the container or devcontainer
curl http://host.docker.internal:7411/v1/health

Any other name the container uses for the host (for example a --add-host gortex-host:host-gateway alias) must be listed: gortex daemon start --http-addr 127.0.0.1:7411 --http-allowed-host gortex-host. Note that a 127.0.0.1 bind is reachable from containers only where Docker forwards host loopback (Docker Desktop does); otherwise bind the bridge address, which requires a token.

The embedded gortex mcp --server REST listener follows the same deny-by-default browser policy. Its --cors-origin https://ui.example flag both permits that specific origin and enables its CORS response headers; '*' does not grant browser access. Use --auth-token or $GORTEX_SERVER_TOKEN to require a token there; without one it, like gortex eval-server, answers only to local Host names (extend them with --http-allowed-host), and a --cors-origin null is ignored with a warning. Prefer the environment variables to the token flags: a flag value is visible to other local users in the process list. Authorizing a web origin grants that site's scripts access to the tool API with the server's filesystem privileges; name only a site you trust.

Scoping the graph. The daemon serves every tracked repo from one shared index, so the HTTP surface spans all of them. Add or remove repos from the served set with gortex track <path> / gortex untrack <path>; query-time ?project= / ?repo= parameters (see the /v1/graph row above) narrow a request to a single workspace or repo without restarting the daemon.

Constellation preview. /v1/graph/constellation returns up to 1,600 nodes and 3,000 edges, ranked by corpus degree. Repeat repo and kind to narrow the selection; project expands into its configured repositories. File nodes are excluded unless explicitly selected. Each node includes its original symbol ID, location and degree; divide its integer x and y by 1,000 for display coordinates. Edges are [source_index, target_index, cross_repo] triples; indices refer to the response's node array and cross_repo is 0 or 1. total_nodes and total_edges count the corpus before display filters (edges with missing endpoints are excluded). Use the original node IDs for source and caller queries.

3D previews. GET /v1/graph/3d returns Galaxies, Strata and City in one response. It accepts the same filters and reports the same corpus totals as Constellation. The scenes share a nodes table with symbol IDs, locations and full-corpus degree. Each scene contains groups by repository prefix and edges as [source_index, target_index, flags] triples referring to that table. Bit 0 marks a cross-repository edge and bit 1 marks a call. Strata includes only cross-repository links; City's bridges are cross-repository calls.

Each group has an origin triple and points of the form [node_index, x, y, z, hot]. Divide coordinates by 1,000 for display. In City, y is building height. hot is the scene's degree highlight (0 or 1). Groups omit nodes without a repository prefix. Repositories are ordered by prefix; symbols within each repository are ranked by full-corpus degree. The limits are 16 repositories × 80 symbols and 500 links in Galaxies, 8 × 60 and 400 in Strata, and 12 × 30 and 80 in City. Filter by repository to see one outside the default limits.

Both endpoints share a bounded cache keyed by preview type, scope and graph revision. Fresh previews are privately revalidated using ETags. If another build is running, a previous complete snapshot for that scope can be returned with X-Gortex-Snapshot-Stale: true and Cache-Control: no-store; if none exists, the server returns 503 so the client can retry. The full /v1/graph response is unchanged.

Multi-server roster. When the daemon is running, it can route MCP traffic across multiple Gortex servers — a local Unix socket for the repos on this machine, plus one or more remote HTTPS servers for shared / cloud indexes. The roster lives at ~/.gortex/servers.toml; manage it with gortex daemon server list / add / remove. Auth tokens can be embedded directly (--auth-token) or pulled from an env var the daemon reads at request time (--auth-token-env, preferred). Restart the daemon to pick up roster changes.

MCP 2026 Streamable HTTP transport (/mcp)

gortex daemon start --http-addr <addr> exposes the MCP 2026 Streamable HTTP transport — the wire format the June 2026 MCP release locks in — on the same TCP address as the /v1/* JSON API.

Verb Path Behaviour
POST /mcp Accepts one or more JSON-RPC frames. Requests receive a correlated response or response array; notification-only input returns 202 with an empty body. Unknown sessions return 404 before dispatch.
GET /mcp Opens an SSE stream the server uses to push server-initiated notifications (progress, sampling) onto the bound session.
DELETE /mcp Terminates a session. Idempotent — returns 204 even when the id is unknown.
OPTIONS /mcp CORS preflight; advertises the allowed methods.

Session lifecycle and request handling. POST requests may carry Mcp-Session-Id; the transport replays matching state out of a streamable.SessionStore (the default in-memory MemoryStore is TTL-evicted; swap for a Redis-backed adapter to share state across replicas behind a load balancer). A standalone, non-batched initialize begins without an id, mints a fresh one, and returns it on the response header. An unknown or expired id on POST requests, including initialize, is rejected before dispatch with HTTP 404 and no Mcp-Session-Id response header. JSON-RPC requests receive a correlated -32001 session not found body; responses and notifications do not receive JSON-RPC replies. Clients may then reinitialize without an id and retry the rejected request once. Idle sessions are evicted after a TTL (default 30 m, GORTEX_MCP_SESSION_IDLE_TTL to tune, a negative value disables expiry); any request on the session resets the clock, so a client issuing calls at least that frequently never expires. The horizon is advertised in whole seconds on every POST response as Mcp-Session-Idle-Ttl and inside the initialize result's _meta under gortex/session_idle_ttl_seconds, so clients can schedule keep-alives (for example a tools/list at half the TTL) instead of discovering expiry through the 404. The Mcp-Protocol-Version header is echoed when provided; absent, the transport advertises its default. tools/call frames flow through the same multi-server router that serves /v1/tools/<name>, so workspace scoping carries over unchanged.

Daemon enablement. gortex daemon start --http-addr 127.0.0.1:7411 [--http-auth-token <token>] brings the transport up alongside the unix-socket dispatcher. Non-localhost binds require an auth token (or $GORTEX_DAEMON_HTTP_TOKEN). /healthz is exempt so liveness probes work. Once --http-addr is set, the daemon mounts /mcp alongside the /v1/* surface on the same address — no extra flag needed.

Web UI

The web UI lives in its own repo at gortexhq/web so it can be deployed independently of the backend (Vercel / a static host / your own Next.js deployment). It's a standalone Next.js 15 app that talks to the daemon's HTTP surface over /v1/*:

# 1) Track the repo and start the HTTP backend (bearer-auth required for non-localhost binds)
gortex track /path/to/repo
gortex daemon start --http-addr 127.0.0.1:7411 \
  --http-allowed-origin http://localhost:3000 --cors-origin http://localhost:3000

# 2) Clone and run the UI in another terminal
git clone https://github.com/gortexhq/web.git gortex-web && cd gortex-web
echo 'NEXT_PUBLIC_GORTEX_URL=http://localhost:7411' > .env.local
npm install && npm run dev
# Open http://localhost:3000
Page Features
Dashboard Health, stats, language pie chart, node kind bar chart
Graph Explorer Sigma.js 2D + five react-three-fiber 3D modes (City / Strata / Galaxies / Constellation / Graph3D), node filters, selection, detail panel
Search Semantic + BM25 search via /v1/*, results grouped by kind
Symbol Detail Source code, signature, callers/callees/usages/deps tabs
Communities Community cards with cohesion bars, expandable members
Processes Collapsible call-tree steps, product vs test process split
Analysis Dead code, hotspots, cycles, index health — 4 tabs
Contracts API contracts (HTTP, gRPC, GraphQL, topics, WebSocket, env vars) with provider/consumer matching, request/response type tracing, yours / tests / deps / all scope filter
Services Service-level graph visualization with per-repo stats
AI Chat LLM-powered chat with code context (placeholder)