@octocodeai/freellama-mcp-server 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONFIGURATION.md +106 -0
- package/DEVELOPING.md +112 -0
- package/LICENSE-MIT +1 -1
- package/README.md +133 -284
- package/dist/index.js +1514 -1409
- package/dist/research/bash-agent.js +2435 -0
- package/dist/research/octocode-agent.js +1639 -0
- package/docs/ARCHITECTURE.md +176 -101
- package/docs/CLI.md +94 -63
- package/docs/CPU_GPU_ROUTING.md +15 -14
- package/docs/MODEL_SELECTION.md +116 -5
- package/docs/MONITORING.md +26 -16
- package/docs/PRODUCTION.md +33 -26
- package/docs/README.md +9 -17
- package/docs/SCOPES_AND_WARMING.md +8 -9
- package/docs/TESTING.md +22 -35
- package/native/index.d.ts +179 -174
- package/native/index.js +3 -3
- package/package.json +12 -10
- package/adapters/agent_context.py +0 -850
- package/adapters/agent_transport.py +0 -215
- package/adapters/bash_agent.py +0 -345
- package/adapters/octocode_agent.py +0 -404
- package/adapters/shell_sandbox.py +0 -487
- package/docs/ECONOMICS.md +0 -110
- package/docs/INDEX.md +0 -21
- package/docs/MODEL_METADATA.md +0 -106
- package/docs/OLLAMA_SIDECAR.md +0 -78
- package/docs/PRODUCT_POSITIONING.md +0 -121
- package/docs/dev/ADR_RESOURCE_AWARE_BACKEND_ROUTING.md +0 -55
- package/docs/dev/FINDINGS_AND_POSITIONING.md +0 -290
- package/docs/dev/LOCAL_PERFORMANCE_TESTING.md +0 -298
- package/docs/dev/OLLAMA_SYSTEM_OPTIMIZATION.md +0 -255
package/CONFIGURATION.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# FreeLlama MCP configuration
|
|
2
|
+
|
|
3
|
+
Settings for the [FreeLlama MCP server](README.md).
|
|
4
|
+
|
|
5
|
+
## Environment variables
|
|
6
|
+
|
|
7
|
+
The following settings have environment-variable overrides. Set them in the MCP client's
|
|
8
|
+
server-launch config (for example `.mcp.json`'s `env` block) or the launching shell.
|
|
9
|
+
|
|
10
|
+
| Variable | Default | Affects |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| `FREELLAMA_OLLAMA_ENDPOINT` | `http://127.0.0.1:11434` | Default Ollama endpoint for `doctor`, the `models` detail/raw/library views, all `ollama_*` tools, and the autostarted serve's `--upstream` |
|
|
13
|
+
| `FREELLAMA_SERVE_ENDPOINT` | `http://127.0.0.1:11435` | Default `endpoint` for serve-backed tools and `delegate_research` |
|
|
14
|
+
| `FREELLAMA_MCP_DEFAULT_MODEL` | unset (routes to an installed coding model) | `delegate_research`'s default `model` |
|
|
15
|
+
| `FREELLAMA_MCP_DEFAULT_ADAPTER` | `bash` | `delegate_research`'s adapter (`octocode` to switch) |
|
|
16
|
+
| `FREELLAMA_MCP_MAX_TURNS` | `8` | Max agent turns for `delegate_research` |
|
|
17
|
+
| `FREELLAMA_MCP_DELEGATE_TIMEOUT_SECONDS` | `180` | Whole-subprocess timeout for `delegate_research` |
|
|
18
|
+
| `FREELLAMA_MCP_PULL_TIMEOUT_SECONDS` | `1200` | Default `ollama_manage` `"pull"` timeout |
|
|
19
|
+
| `FREELLAMA_MCP_FETCH_TIMEOUT_SECONDS` | `30` | Timeout for other direct Ollama HTTP calls |
|
|
20
|
+
| `FREELLAMA_MCP_ALLOWED_ROOTS` | checkout: this repository; published: must be set | Platform-separated allowlist of directories `delegate_research` may read (`:` on macOS/Linux, `;` on Windows) |
|
|
21
|
+
| `FREELLAMA_MCP_MODEL_EVIDENCE` | checkout: `packages/mcp/evidence/model-evidence.json`; published: unset | Path to per-model research grades (see "Runtime evidence") |
|
|
22
|
+
| `FREELLAMA_EXTERNAL_COST_MODEL` | unset | External-model label in estimated avoided-cost telemetry; set all three cost variables or none |
|
|
23
|
+
| `FREELLAMA_EXTERNAL_COST_INPUT_USD_PER_M` | unset | External input USD per million tokens |
|
|
24
|
+
| `FREELLAMA_EXTERNAL_COST_OUTPUT_USD_PER_M` | unset | External output USD per million tokens |
|
|
25
|
+
| `FREELLAMA_CONTROL_TIMEOUT_SECONDS` | `30` | Decision-only serve calls; read by the native client (`packages/rust-core/src/serve_client.rs`) |
|
|
26
|
+
| `FREELLAMA_TASK_TIMEOUT_SECONDS` | `900` | Generation calls; read by the native client (`packages/rust-core/src/serve_client.rs`) |
|
|
27
|
+
| `FREELLAMA_AUTH_TOKEN_FILE` | unset | Bearer-token file used by the native client and research adapters for all serve routes |
|
|
28
|
+
| `FREELLAMA_AGENT_TOKEN_CALIBRATION_DIR` | platform data directory | Prompt-free, model-specific token-estimator calibration shared across adapter processes |
|
|
29
|
+
| `FREELLAMA_MCP_AUTOSTART_SERVE` | `1` | When the default loopback serve endpoint does not answer, start `freellama serve` as a child of the MCP server (stopped with it): once in the background at launch, so other local clients find it, and again on a tool call if it is still down. `0` disables |
|
|
30
|
+
| `FREELLAMA_SERVE_BINARY` | checkout `target/release`/`debug`, then the platform package | Binary used for serve autostart |
|
|
31
|
+
| `FREELLAMA_AGENT_OS_SANDBOX` | `auto` | Bash adapter OS confinement: `bwrap` on Linux, `sandbox-exec` on macOS, when present. `off` keeps only the restricted shell |
|
|
32
|
+
| `FREELLAMA_AGENT_OCTOCODE_PACKAGE` | `octocode@19.1.0` | Pinned npm spec the Octocode adapter runs through `npx` |
|
|
33
|
+
|
|
34
|
+
Serve-side placement settings (read by `freellama serve`, not the MCP process):
|
|
35
|
+
|
|
36
|
+
| Variable | Default | Affects |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `FREELLAMA_EVICT_IDLE_MODELS` | on | Unload idle, unpinned models using reuse and load costs when a cold load needs room. `0` turns eviction off |
|
|
39
|
+
| `FREELLAMA_CPU_NUM_THREAD` | half the logical cores (not set on macOS) | `num_thread` for CPU-placed tasks only; GPU tasks leave it to Ollama |
|
|
40
|
+
| `FREELLAMA_MAX_QUEUE_WAIT_SECONDS` | `120` | How long a managed task queues for a slot or memory |
|
|
41
|
+
| `OLLAMA_NUM_PARALLEL`, `OLLAMA_KV_CACHE_TYPE`, `OLLAMA_FLASH_ATTENTION` | Ollama's | Read as hints for the memory estimate: parallel slots multiply the KV cache, and `q8_0`/`q4_0` shrink it only with flash attention. Set them for serve the same way as for Ollama |
|
|
42
|
+
|
|
43
|
+
Research-adapter settings are deployment defaults. The optional `delegate_research.agent` object
|
|
44
|
+
overrides the per-call budget (`maxTurns`, `contextTokens`, `outputTokens`); explicit per-call
|
|
45
|
+
fields win. Sampling, keep-alive, timeouts, and placement preference for research come from the
|
|
46
|
+
operator's `FREELLAMA_AGENT_*` variables or the adapter defaults.
|
|
47
|
+
The research subprocess inherits only these server variables: `FREELLAMA_*`; `PATH`, `HOME`,
|
|
48
|
+
`USER`, `LOGNAME`; `LANG`, `LC_ALL`, `LC_CTYPE`, `TZ`; `TMPDIR`, `TEMP`, `TMP`; Windows `SYSTEMROOT`,
|
|
49
|
+
`SYSTEMDRIVE`, `WINDIR`, `COMSPEC`, `PATHEXT`, `APPDATA`, `LOCALAPPDATA`, `USERPROFILE`;
|
|
50
|
+
`HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` (and lowercase forms); `NODE_EXTRA_CA_CERTS`,
|
|
51
|
+
`SSL_CERT_FILE`, `SSL_CERT_DIR`, `REQUESTS_CA_BUNDLE`; `XDG_CACHE_HOME`, `XDG_DATA_HOME`,
|
|
52
|
+
`npm_config_cache`.
|
|
53
|
+
|
|
54
|
+
| Variable | Default | Affects |
|
|
55
|
+
|---|---:|---|
|
|
56
|
+
| `FREELLAMA_AGENT_NUM_CTX` | `8192` | Ollama context window |
|
|
57
|
+
| `FREELLAMA_AGENT_EXECUTION_PREFERENCE` | `auto` | Managed coding-agent backend hint |
|
|
58
|
+
| `FREELLAMA_AGENT_MIN_PLACEMENT_EVIDENCE` | `configured` | Set `observed` to fail closed on cold/mismatched placement |
|
|
59
|
+
| `FREELLAMA_AGENT_NUM_PREDICT` | `512` | Reserved output budget |
|
|
60
|
+
| `FREELLAMA_AGENT_TEMPERATURE` / `FREELLAMA_AGENT_SEED` | `0` / `42` | Repeatable decoding |
|
|
61
|
+
| `FREELLAMA_AGENT_THINK` / `FREELLAMA_AGENT_KEEP_ALIVE` | `false` / `5m` | Ollama reasoning and residency |
|
|
62
|
+
| `FREELLAMA_AGENT_REQUEST_TIMEOUT_SECONDS` | `600` | Each Ollama chat attempt |
|
|
63
|
+
| `FREELLAMA_AGENT_TOOL_TIMEOUT_SECONDS` | Bash `30`, Octocode `45` | Each local tool call |
|
|
64
|
+
| `FREELLAMA_AGENT_RETRY_ATTEMPTS` / `FREELLAMA_AGENT_RETRY_BACKOFF_SECONDS` | `2` / `5` | Conversation-level retry |
|
|
65
|
+
| `FREELLAMA_AGENT_MAX_PARSE_REPAIRS` / `FREELLAMA_AGENT_PARSE_REPAIR_ECHO_CHARS` | `2` / `500` | Invalid JSON correction limit and retained reply text |
|
|
66
|
+
| `FREELLAMA_AGENT_CHARS_PER_TOKEN` | `4` | First-call token estimate; later calibrated from Ollama |
|
|
67
|
+
| `FREELLAMA_AGENT_SAFETY_MARGIN_TOKENS` | `256` | Input headroom beyond `num_predict` |
|
|
68
|
+
| `FREELLAMA_AGENT_IMAGE_TOKEN_ESTIMATE` | `1024` | Bounded charge per image |
|
|
69
|
+
| `FREELLAMA_AGENT_KEEP_RECENT` | `2` | Recent observations preserved verbatim |
|
|
70
|
+
| `FREELLAMA_AGENT_COMPACT_PREVIEW_CHARS` | `180` | Old-observation breadcrumb size |
|
|
71
|
+
| `FREELLAMA_AGENT_COMPACT_RETAIN_RATIO` | `0.8` | Current payload retained per emergency pass |
|
|
72
|
+
| `FREELLAMA_AGENT_CLIP_HEAD_RATIO` | `0.667` | Head share when an emergency clip preserves both ends |
|
|
73
|
+
| `FREELLAMA_AGENT_OBSERVATION_PAGE_CHARS` | `3000` | Lossless observation page target |
|
|
74
|
+
| `FREELLAMA_AGENT_PINNED_OVERFLOW` | `error` | Preserve system/task bytes; `clip` is explicit opt-in |
|
|
75
|
+
|
|
76
|
+
Invalid values fail before an Ollama request. Each successful result returns
|
|
77
|
+
`contextManagement` with the resolved policy, calibration source/scale, estimated input budget,
|
|
78
|
+
and compaction count. Ollama has no stable preflight tokenizer endpoint, so “exact before the first
|
|
79
|
+
call” is not claimed. Model-specific calibration persists after successful calls, so later
|
|
80
|
+
processes start conservatively from prior `prompt_eval_count` evidence without sharing estimates
|
|
81
|
+
between model templates.
|
|
82
|
+
|
|
83
|
+
**Security:** `delegate_research` grants a local model read access to `workspacePath`. The path is
|
|
84
|
+
confined to `FREELLAMA_MCP_ALLOWED_ROOTS` (default: this repository in a checkout; unset in a published
|
|
85
|
+
install until you set it), resolved through symlinks so a link inside an allowed root can't escape
|
|
86
|
+
it. The default `bash` adapter runs an allowlist of read-only tools in a restricted shell with a
|
|
87
|
+
scrubbed environment and, where available, an OS sandbox; it also rejects command substitution,
|
|
88
|
+
home-directory paths, `..`, and absolute paths outside that workspace. Production deployments should generate a permission-restricted token with
|
|
89
|
+
`freellama auth-token`, start `serve` with `--auth-token-file`, and set
|
|
90
|
+
`FREELLAMA_AUTH_TOKEN_FILE` for MCP. Authentication covers managed and raw passthrough routes; use
|
|
91
|
+
an external TLS and authorization layer for untrusted or multi-tenant networks.
|
|
92
|
+
|
|
93
|
+
## Runtime evidence
|
|
94
|
+
|
|
95
|
+
Admission weights can be set by task kind in the server runtime file's `[task_costs]` table.
|
|
96
|
+
Inspect `doctor {view:"full"}` at `platform_health.admission.costs.base_by_task` for effective
|
|
97
|
+
weights and `run_task {preview:true}` for current cost and capacity advice. The table changes
|
|
98
|
+
managed admission; it does not create Ollama
|
|
99
|
+
slots or relax memory guards. Existing queued work keeps its captured cost. See
|
|
100
|
+
[monitoring controls](https://github.com/bgauryy/FreeLlama/blob/main/docs/MONITORING.md#adaptive-concurrency).
|
|
101
|
+
|
|
102
|
+
**No measurements are compiled in.** In a repository checkout, per-model research grades load from
|
|
103
|
+
`packages/mcp/evidence/model-evidence.json`. A published package does not include that repository
|
|
104
|
+
file, so its evidence table is empty unless you set `FREELLAMA_MCP_MODEL_EVIDENCE`. An unmeasured
|
|
105
|
+
model yields a `verify` verdict, and an unreadable evidence file is reported on stderr and treated
|
|
106
|
+
as empty. Tool descriptions state the rules.
|
package/DEVELOPING.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Developing the FreeLlama MCP server
|
|
2
|
+
|
|
3
|
+
Build, test, and release notes for the [FreeLlama MCP server](README.md).
|
|
4
|
+
|
|
5
|
+
## Build
|
|
6
|
+
|
|
7
|
+
Build the native addon from the repository root and this package in place.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# From the repository root (yarn workspaces — one install for every package)
|
|
11
|
+
corepack enable
|
|
12
|
+
yarn install
|
|
13
|
+
yarn build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`yarn build` writes the MCP server, `packages/mcp/dist/index.js` (shebang, executable). During
|
|
17
|
+
checkout development it loads `native/freellama.<triple>.node`. Published installs resolve the
|
|
18
|
+
matching `@octocodeai/freellama-native-<target>` optional package instead, so the base MCP package remains
|
|
19
|
+
portable. The research adapters compile to `dist/research/{bash-agent,octocode-agent}.js`, and the
|
|
20
|
+
repository `docs/` guides are copied into `docs/`.
|
|
21
|
+
|
|
22
|
+
Piecewise, if you are iterating on one layer:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# 1. Native addon → packages/mcp/native/freellama.<triple>.node
|
|
26
|
+
yarn build:native
|
|
27
|
+
|
|
28
|
+
# 2. This server → dist/index.js and dist/research/*.js via esbuild, plus docs/
|
|
29
|
+
yarn workspace @octocodeai/freellama-mcp-server build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`yarn start` needs `dist/index.js` and the compiled `.node` addon — `yarn build` from the repository
|
|
33
|
+
root produces both in a checkout. `dist/index.js` loads `native/index.js`, which loads a local addon
|
|
34
|
+
first and then a matching optional platform package. The `.node` binary is gitignored (a build
|
|
35
|
+
artifact). `native/index.js` is a small hand-written loader; `native/index.d.ts` is generated from
|
|
36
|
+
`napi.rs` by `yarn build:native`. Both are checked in; do not edit the declarations by hand —
|
|
37
|
+
change the Rust doc comments or `ts_args_type`, rebuild, and commit. The unit test
|
|
38
|
+
`test/unit/native-dts-drift.test.ts` fails when the declarations and the `napi.rs` exports differ.
|
|
39
|
+
|
|
40
|
+
## Test
|
|
41
|
+
|
|
42
|
+
Vitest, in three tiers (all TypeScript, under `test/`):
|
|
43
|
+
|
|
44
|
+
| Tier | Command (from this package) | Checks | Needs |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| `test/unit/` | `yarn test` (watch: `yarn test:watch`) | pure functions straight from `src/*.ts` — no build step, this is the TDD loop | nothing, a few seconds |
|
|
47
|
+
| `test/integration/` | `yarn test:integration` | the built server over the real MCP protocol: tool contract, structured content, guardrails; rebuilds `dist/` itself | Ollama at `FREELLAMA_OLLAMA_ENDPOINT` (default :11434) |
|
|
48
|
+
| `test/e2e/` | `yarn test:e2e` | every tool against the live system: real routing/execution, pull → delete round trip (net-zero), a real delegated research run | serve + Ollama + models, ~40s |
|
|
49
|
+
|
|
50
|
+
The same commands work from the repository root (`yarn test` there also runs the CLI package's tests
|
|
51
|
+
and the Rust suite).
|
|
52
|
+
The integration/e2e tiers fail fast with a readable message when Ollama is down, and the lifecycle
|
|
53
|
+
test refuses to delete a model already installed on the test system.
|
|
54
|
+
|
|
55
|
+
For default-endpoint autostart, the server starts `freellama serve` in the background at launch and
|
|
56
|
+
logs a failure to stderr. On a tool call, a spawn failure, early exit, or readiness timeout rejects the
|
|
57
|
+
request while leaving the MCP transport available for diagnosis or retry. Autostart does not apply
|
|
58
|
+
to an explicit non-default endpoint; see `FREELLAMA_MCP_AUTOSTART_SERVE` in
|
|
59
|
+
[configuration](CONFIGURATION.md#environment-variables).
|
|
60
|
+
|
|
61
|
+
## Platform support
|
|
62
|
+
|
|
63
|
+
The native addon is named by target triple (`freellama.<platform>-<arch>[-<abi>].node`). The base
|
|
64
|
+
package has eight npm optional dependencies, one each for macOS arm64/x64, Linux arm64/x64 with
|
|
65
|
+
glibc or musl, and Windows arm64/x64 with MSVC. `native/index.js` tries the checkout artifact first,
|
|
66
|
+
then the host's optional package. A release is supported only when all eight artifact packages pass
|
|
67
|
+
the publish verifier; an installation made with `--omit=optional` cannot load the addon. `engines`
|
|
68
|
+
requires Node >= 20.
|
|
69
|
+
|
|
70
|
+
Machine discovery distinguishes total host memory (`memory_bytes`) from known unified memory
|
|
71
|
+
(`unified_memory_bytes`). Library-tag `fitsInMemory` is a conservative host-memory preflight and
|
|
72
|
+
includes `fitScope: "host_memory_budget_only"`; inspect `/api/ps` for actual accelerator placement.
|
|
73
|
+
|
|
74
|
+
Start the serve-backed tools' dependency from the repository root:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
cargo run --release -- serve
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`freellama proxy` only forwards raw `/api/*` calls; only `serve` has the `/_freellama/v1/*` routes
|
|
81
|
+
these tools call.
|
|
82
|
+
|
|
83
|
+
## Publish
|
|
84
|
+
|
|
85
|
+
`packages/mcp/` is the portable JavaScript package. Its `package.json` lists the platform packages
|
|
86
|
+
as exact-version optional dependencies; it intentionally does not embed a `.node` binary. Publish
|
|
87
|
+
the eight `packages/native/*` packages first, then publish `@octocodeai/freellama` (`npx @octocodeai/freellama`) and `@octocodeai/freellama-mcp-server` (`npx @octocodeai/freellama-mcp-server`)
|
|
88
|
+
at the same version. `yarn release:verify:publish` refuses a release if any of the ten packages
|
|
89
|
+
omits `assets/logo.jpg`, or if any platform package has a missing, empty, or unpacked
|
|
90
|
+
executable/addon pair.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
cd packages/mcp
|
|
94
|
+
npm pack --dry-run # confirm exactly what a publish would ship
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Treat `npm publish` as a public release action. Follow the
|
|
98
|
+
[release package checks](https://github.com/bgauryy/FreeLlama/blob/main/docs/TESTING.md#verify-release-packages) and obtain the repository owner's release authorization first.
|
|
99
|
+
|
|
100
|
+
## Why native bindings
|
|
101
|
+
|
|
102
|
+
- **No routing reimplementation.** `run_task`, `run_task {preview:true}`, and the installed-model list are HTTP
|
|
103
|
+
calls into a running `freellama serve`, matching the CLI requests in `packages/cli/src/requests.rs`. `doctor` talks to Ollama
|
|
104
|
+
and the host's portable machine-discovery layer directly. `ollama_manage` / `ollama_delete` hit Ollama's HTTP API. `delegate_research`
|
|
105
|
+
is a subprocess. Routing decisions still live in exactly one place — the Rust core; see
|
|
106
|
+
[what the MCP layer computes](README.md#what-the-mcp-layer-computes).
|
|
107
|
+
- **One connection pool.** `packages/rust-core/src/serve_client.rs` holds a single `reqwest::Client` in a
|
|
108
|
+
`OnceLock` and clones the handle per request; `napi.rs` and the CLI share it.
|
|
109
|
+
- **`unsafe_code` stays isolated.** The crate is `deny(unsafe_code)` except `napi.rs`, which
|
|
110
|
+
carries an explicit `#[allow(unsafe_code)]` for napi-derive's FFI glue.
|
|
111
|
+
- **The napi build is off by default** (`cargo build` never touches it); the addon is built with
|
|
112
|
+
`napi build --features napi` from the repo root.
|
package/LICENSE-MIT
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Guy Bary
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
6
|
associated documentation files (the "Software"), to deal in the Software without restriction, including
|