
forthling
io.github.DeSchaker由 GitHub 帳號 DeSchaker 發布v0.2.3更新於 Nov 7, 2026
Run Forth-2012 in a sandbox: definitions stay between calls, each result shows the stacks.
概覽
在沙箱工作階段中執行 Forth-2012 程式碼,呼叫之間保留定義與堆疊,並回傳輸出、堆疊內容與錯誤。
- 可以做什麼
- 執行 Forth 程式碼,回傳輸出、資料堆疊與浮點堆疊、錯誤訊息以及可選的執行追蹤
- 檢視目前堆疊內容,列出本工作階段已定義的字詞
- 查詢某個字詞的堆疊效果、說明、範例與所屬字表,未定義時提供相近名稱
- 載入記憶體檔案供 INCLUDE 使用,讀取程式碼寫入的內容,並可重設工作階段
- 帶領使用者完成內建的 20 課 Forth 教學,含答案檢查與提示
- 適用情境
- 適合讓助理撰寫、測試與除錯 Forth-2012 程式碼,或以互動方式教授 Forth,同時不必給它 shell 或磁碟存取權限。
- 執行需求
- 本機 stdio 程序:在支援 .mcpb 的用戶端安裝該套件,或以 Rust 1.85 以上安裝 forthling-mcp crate(預設 SQLite 功能需要 C 編譯器)。不需帳號、金鑰或環境變數。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 forthling,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
forthling-mcp
An MCP server that lets AI agents (Claude Code, Claude Desktop and other MCP clients) run Forth in forthling, always in its sandbox. The agent keeps one session: the words it defines and the stacks stay between calls.
Installing
Without Rust, as an MCP bundle: download forthling.mcpb from the
latest release and open it in
Claude Desktop (or another client that installs .mcpb files). The bundle holds the
server for Windows (x64), macOS (Apple Silicon and Intel) and Linux (x64).
From crates.io, with Rust 1.85 or newer:
It builds SQLite along, which takes a C compiler (on Windows that of Visual Studio, which
Rust there uses anyway); cargo install forthling-mcp --no-default-features leaves SQLite
out. From a clone of the repository: cargo install --path mcp, or
cargo build --release --manifest-path mcp/Cargo.toml, and the program is then
mcp/target/release/forthling-mcp. With Claude Code:
Other clients start it the same way: the command forthling-mcp, over stdio.
When a client connects, the server tells the model the basics in its instructions: the
idioms that trip models up, locals rather than ROT, PICK and ROLL, the JSON words and
the limits. llms.txt says the same at more length, for a model that reads
it beforehand; a test keeps the limits in both the same.
Tools
A line of code, and so a string in S", is at most 1024 characters. Larger input, such
as a JSON document, goes in data: the code reads it with DATA ( -- c-addr u ), which
gives a copy in ALLOCATEd memory (FREE it). The data stays for later calls until a
call sends other data, and may be at most as large as the Forth memory:
Each session has files of its own, in memory and never on the disk: INCLUDE, REQUIRE,
the FILE words and the block words use them, and they stay until forth_reset. files
puts files there before the code runs, as an object of names and texts, replacing files of
the same name; so an agent can give a library once and INCLUDE it, and what the code
writes, a later call can read. The files take at most 4 MiB in all; a write past that
fails with the word's ior, and files that do not fit are refused.
Each result is text the way the REPL shows it:
and the same as structured JSON (structuredContent, with an outputSchema):
{"output": "2401 ", "stack": [1, 2], "fstack": [], "compiling": false, "error": null, "steps": …, "max_depth": …}; steps and max_depth (only for forth_eval) tell how
many steps the call took and how deep the data stack went, counting the words of the
system it ran (. is written in Forth, so it counts too).
An error empties the stacks, so the result also tells what they held at the error, where it happened and which words were running; the model can put it right in one go:
and as JSON: "error": {"code": -10, "message": "division by zero", "stack": [5, 1], "fstack": [], "words": ["MAIN", "STEP", "/"], "source": "input", "line": 2, "column": 3, "token": "MAIN", …}, with isError true. A word that took its arguments before it
failed, such as / here, has taken them. An undefined word that is in a word list
outside the search order gets a hint, which the text adds after the word:
error -13: undefined word: JSON@ (it is in the word list JSON; ALSO JSON finds it).
A runaway program can leave a hundred thousand cells on the stack, or as many words
running (endless recursion). The result then keeps the top 32 cells and the innermost 32
words, the text says ... (n more) and the JSON has the full depth in stack_depth,
fstack_depth and words_depth. A definition that is still open (compiling true)
says so in the text: compiled (a definition is still open; ; ends it).
When the code ran T{ ... -> ... }T tests (ALSO TESTING), the result also has the counts
of that call, and the text starts with tests: 1 passed, 1 failed. The failure lines
(FAIL input:3 (sums): incorrect result: expected <1> 3, got <1> 2) are in the output.
In JSON: "tests": {"passed": 1, "failed": 1, "failures": [{"source": "input", "line": 3, "group": "sums", "expected": [3], "expected_depth": 1, "actual": [2], "actual_depth": 1, "stack": [], "expected_floats": [], "expected_floats_depth": 0, "actual_floats": [], "actual_floats_depth": 0}], "failures_dropped": 0}. The first 32 failures are kept, and each
list keeps its top 32 cells and floats (the depths tell how many there were). A file given with files
shows its name as source.
What an agent sees for typical mistakes
Each case was run through forth_eval (#47); the answer is the first lines of the text.
The code was run from a fresh session.
What gives no error, and so no message: an unclosed S" or ( takes the rest of the
line (as the standard says); : f >R ; leaves the return stack unbalanced and 1 f
returns without a word; ALLOCATE of a negative size and FREE twice answer with a
non-zero ior on the stack (-59, -60), and so does a failed DB-EXEC (-261); a
JSON path that is not there gives 0 0 0. These follow the standard or the word's
stack effect; the agent must read the stack.
With "trace": true, forth_eval also returns a trace: each word that ran, with how deep
it was nested and the data stack when it started (at most its top 8 cells), at most 1000
words; trace_dropped counts the rest. The insides of the system's own words are left
out. The text starts with it, indented the way TRACE-ON prints it:
and the JSON has "trace": [{"word": "F", "depth": 0, "stack": [], "stack_depth": 0}, {"word": "SQ", "depth": 1, "stack": [3], "stack_depth": 1}, …], "trace_dropped": 0. The
trace of a call that fails shows how it got to the error. In the code itself,
ALSO DEBUG TRACE-ON … TRACE-OFF prints the same lines as output.
BREAK (also ALSO DEBUG) marks a place to look at. It does not stop the program, since
no one could answer in the middle of a call; instead the result has breaks, what the
program looked like at each BREAK (at most 100; breaks_dropped counts the rest), with
the same fields as an error: stack, fstack, words, source, line, column and
token. The text starts with a line for each:
ALSO TUTORIAL gives the tutorial: 20 lessons of Forth, ten for beginners and ten
beyond, that an agent can walk a person through (LESSONS, n LESSON, CHECK tests the
answer, HINT, NEXT).
The JSON words are installed (ALSO JSON), and the SQLite words for databases in memory
(ALSO SQLITE, only :memory:, which SQL stops when the time is up and which cannot
grow larger than the Forth memory) and the regular expression words (ALSO REGEX, which
match in linear time); without the Cargo features sqlite and regex
(--no-default-features) the server is built without them.
The HTTP words (ALSO HTTP, see http/README.md) are a third feature,
http, which is off by default because it reaches the network. Build the server with it
(cargo install forthling-mcp --features http) and start it with the hosts that Forth code
may send requests to, once for each host: forthling-mcp --allow-host api.example.com
(*.example.com and * also work). Without --allow-host the network stays closed and the
model is not told about the words. It is the only option that opens something outside the
sandbox, and only for the hosts you name; a Forth word cannot add one.
The sandbox
Every session runs in forthling's sandbox: files only in memory, and each call at most 10 million steps, 5 seconds and 1 MiB of output; the session's definitions and the like at most 4 MiB in all. The options change these limits, each up to a ceiling the program fixes:
There is no option to switch the sandbox off or to permit files, so changing how the
server is started does not open them either. Only --allow-host opens the network, for
the hosts it names (see above).
What enforces it. The sandbox is enforced by the server, not by what the model is
told or promises: the tools take only Forth code (other arguments are refused), and no
Forth word can change a limit or a permission. A user who asks the AI to get around the
sandbox cannot do it through forthling. An agent that also has other tools, such as a
shell or editing files, can however go around it: change the MCP configuration, or start
another program. Against that, forthling cannot help; use the permissions of the agent
instead. In Claude Code: deny or limit the shell, deny edits to the MCP configuration
(.mcp.json, ~/.claude.json), and allow only the MCP servers you want through managed
settings. For extra safety against a bug in forthling, run the server in a container or
as a user with few rights.
Testing
Links
- Source and the rest of forthling: https://github.com/DeSchaker/forthling
- The MCP Registry knows this server as
io.github.DeSchaker/forthling(the line below lets it check that the crate is ours). - mcp-name: io.github.DeSchaker/forthling
來源:mcp/README.md,提交 dab1ea9
工具
0版本歷史
4- v0.2.3最新Nov 7, 2026
- v0.2.2Nov 6, 2026
- v0.2.1Nov 3, 2026
- v0.1.1Nov 1, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分