Skip to content

Server CLI: Serve Flags ​

This page documents the full flag contract of memex_server serve: all 40 flags, the strict-parsing rules behind them, environment-variable fallbacks, and the assembly consequences that turn flags into running faces. The parser is parse_serve_args (server/src/serve_args.cpp, extracted from cmd_serve); its acceptance tests are the serve_args ctest (server/tests/test_serve_args.cpp, direct parser calls, no process spawn). For in-app settings switches see Configuration Effects.

Argument shape ​

serve sub-command flags are parsed from the sub-command-stripped argument segment (serve_args.hpp:51-54):

  • argv[0] is the first flag (e.g. {"--port", "24370"}) — no program name, no sub-command.
  • A bare word (anything not starting with --) is a positional argument and is rejected with exit code 2 — the sub-argv shape has no bare words.
  • argc = 0 is legal and yields all defaults (equivalent to a bare serve).

Strict parsing (exit code 2 contract) ​

Every failure below prints a reason to stderr and exits rc 2 — nothing falls back to a default silently (serve_args.cpp:1-4 header note):

ViolationExampleRule
Unknown flag--prot (typo of --port)serve_args.cpp:326-330 — a misspelled flag must not quietly leave a port or safety switch at its default
Positional argumentserve extraserve_args.cpp:99-102
Missing value at tailserve --port as last argserve_args.cpp:74-85 — the old behavior (silent skip) let ports and safety switches drift to defaults
Boolean with a value--s3-use-ssl=trueserve_args.cpp:198-201 and the other boolean branches — booleans have no value to take
Non-strict number--port abc, --port 99999999999serve_args.cpp:32-49 — only an optional - plus all digits; anything else, empty strings, and overflow beyond int magnitude are rejected instead of wrapping (std::atoi silently maps "abc"→0 and truncates huge values, which turns a typo into a different "valid" config)
Out-of-range port--port 0, --port 70000per-flag range checks below
Bad --ldap-group-role form--ldap-group-role admins (no =)serve_args.cpp:266-270 — must be group=role with both sides non-empty

Inline form: every value flag accepts --flag=value in addition to --flag value (serve_args.cpp:93-97, codex-761). Boolean flags never take a value in either form.

Flag reference ​

Ports and faces ​

FlagDefaultRangeEffect of 0
--port243601–65535— (required > 0)
--webhook-port243610–65535closes webhook intake; everything else keeps running
--model-port0 (off)0–65535model gateway off (default)
--files-port0 (off)0–65535file face off (default)
--uplink-port0 (off)0–65535external one-way uplink face off (default)

Defaults live in serve_args.hpp:16-22; the safety-default stance is deliberate — the file face, uplink face, and model gateway all require an explicit port to open.

In-group assistant (phase 3) ​

FlagEffect
--assistant <bot>bot name that polls the four commands (@助手/@纪要/@整理/@检索); empty = off
--assistant-token <token>plaintext token for that bot

Assembly gates (main.cpp:276-295): the assistant additionally requires webhook intake open, a token (flag or MEMEX_ASSISTANT_TOKEN env — prefer the env, flag values are visible in ps), and the bot to already exist via memex_server bot add + join. Each unmet gate prints a reason and the assistant stays off (server still boots).

FlagEffect
--uplink-ext-denylist <csv>whole-table replace of the dangerous-extension denylist (comma-separated, lowercase, no dots; suffixless files never match). Empty string clears the list (= no extension limit). Default table: 23 entries — exe dll bat cmd com scr msi msp cpl hta jar js jse vbs vbe wsf wsh ps1 sh bash apk deb rpm (files_server.hpp:93-97)
--uplink-ext-allowlist <csv>non-empty value enables allowlist mode: extensions outside the list are rejected (suffixless too) and the denylist becomes moot (serve_args.cpp:155-158)
--uplink-max-mb <n>per-face upload cap in MiB, ≥ 0; 0 = keep using the global upload limit (serve_args.cpp:159-167)
--uplink-login-secret <s>deployment-level second password for external logins: /uplink/session must carry a matching secondary field, mismatch = 401 (files_server.hpp:102-104)

Feature keys ​

FlagEffect
--tool-cred-secret <s>master key for the credential face (server-side GCM derivation). Absent = credential face not enabled
--task-pull-secret <s>master key for the task-source pull face (PBKDF2 at the same strength). Absent = pull face not enabled = zero outbound calls; the config route answers 503
FlagDefaultNotes
--s3-endpointemptyintranet HTTP + path-style by default (main.cpp:66-72)
--s3-bucketemptybucket is bootstrapped idempotently at startup (head-check first, 10 × 2 s retries; failure prints a reason and the face still starts with uploads answering 503, main.cpp:74-84)
--s3-access-keyempty
--s3-secret-keyempty
--s3-regionautono environment fallback for this one flag
--s3-use-ssloffboolean, no value

The file face only opens for real when --files-port > 0 and all four S3 values are set (main.cpp:70); port given but S3 incomplete prints the missing-variable hint and the face answers 503 (main.cpp:87-91).

LDAP / AD (optional enterprise identity) ​

Absent --ldap-host = LDAP off — login resolution stays fully local and lightweight deployments behave byte-for-byte as before (ldap.hpp:9-10). Standing red lines (ldap.hpp:11-16): directory unavailable = login rejected (fail-closed, never falls back to local passwords); passwords only ever travel inside the bind request (never logged/stored); groups outside the explicit mapping grant nothing; local accounts always work as the recovery path.

FlagDefaultNotes
--ldap-hostempty (off)
--ldap-port3891–65535
--ldap-timeout-ms4000≥ 0
--ldap-user-baseemptye.g. ou=people,dc=corp
--ldap-user-attruidAD commonly sAMAccountName
--ldap-memberof-attrmemberOfOpenLDAP needs the memberof overlay
--ldap-bind-dn-templateemptydirect-bind template, {u} = username (OpenLDAP style)
--ldap-bind-dnemptyservice-account DN, search-then-bind (AD style)
--ldap-bind-passwordemptyprefer env MEMEX_LDAP_BIND_PASSWORD — flag values show up in ps (serve_args.cpp:239-246)
--ldap-group-role <g=r>emptyexplicit group→role mapping, repeatable; unknown groups are ignored, and without an admin entry in the table nobody ever gets admin (serve_args.cpp:261-271)
--ldap-disabled-attr / --ldap-disabled-rule / --ldap-disabled-valueemptyoptional disabled-detection triple; AD defaults: userAccountControl / 1.2.840.113556.1.4.803 / 2 (serve_args.cpp:250-260)
--ldap-kick-disabled <n>1directory-disabled × existing sessions: 0 = only refuse new logins, non-0 = kick existing sessions
--ldap-recheck-seconds60session recheck interval, ≥ 0; 0 = never recheck
--ldap-ssloffboolean — ldaps:// whole-connection TLS (636 stance), certificate hostname check always on
--ldap-starttlsoffboolean — connect on 389 then upgrade TLS; mutually exclusive with --ldap-ssl (ldap.cpp:540)
--ldap-allow-plainoffboolean — explicit plaintext-bind opt-in (default rejects it as a red line; tests/controlled intranets only, startup logs it)
--ldap-tls-insecureoffboolean — skip certificate verification for self-signed certs (startup warns)
--ldap-auto-bindoffboolean — existing local account without a binding: directory auth success auto-binds it (default off = explicit CLI binding only)
--ldap-auto-provisionoffboolean — account missing: directory auth success creates a shadow account with a random unknowable local password (LDAP-only login)

Environment fallbacks (flags always win) ​

Empty flag values fall back to environment variables; a flag on the command line beats the env even if a debug script rewrote the env (serve_args.cpp:332-334). Env vars keep secrets out of ps/logs in container deployments:

VariableFills
MEMEX_S3_ENDPOINT / MEMEX_S3_BUCKET / MEMEX_S3_ACCESS_KEY / MEMEX_S3_SECRET_KEYthe four S3 values (serve_args.cpp:339-342)
MEMEX_LDAP_HOST / MEMEX_LDAP_USER_BASE / MEMEX_LDAP_BIND_DN_TEMPLATE / MEMEX_LDAP_BIND_DN / MEMEX_LDAP_BIND_PASSWORD / MEMEX_LDAP_MEMBEROF_ATTRthe six LDAP strings (serve_args.cpp:346-355)
MEMEX_LDAP_GROUP_ROLEcomma-separated group=role list, appended to flag mappings (serve_args.cpp:356-370)
MEMEX_ASSISTANT_TOKENassistant token when --assistant-token is absent (main.cpp:280-284)

One asymmetry worth knowing: a malformed entry inside MEMEX_LDAP_GROUP_ROLE (no =, or empty sides) is silently skipped (serve_args.cpp:363-366), while the same malformed shape on the flag is rc 2. The flag path is the strict one — prefer it when mappings matter.

Verification ​

The serve_args ctest (server/tests/test_serve_args.cpp) drives parse_serve_args directly and covers: defaults, every port boundary (0 / negative / out-of-range / overflow / garbage → rc 2), uplink table replacement and max-mb math, S3/LDAP env fallbacks with flag-wins, group→role mappings from both flag and env, and every strict-parse leg (unknown flag / positional / missing value / boolean-with-value / inline form). Run it with ctest -R serve_args in the server build tree.

Verification date: 2026-11-15 (flag inventory re-extracted from serve_args.cpp via grep -oP 'arg == "--\K[a-z0-9-]+' = 40; port and range facts re-checked against the source lines cited above).

Intranet office IM · Dual-engine clients · Traceability first