test0r e05438f0e3 v1.2.0/#22: tools.d/ plugin scan — host-local tool extensions
Adds a directory-scan plugin mechanism to the packaged server.lua
so hosts can drop their own tools alongside the packaged generics
without forking server.lua.

Mechanism:
- After all packaged tool registrations + before transport selection,
  the server scans LMCP_TOOLS_DIR (default /opt/lmcp/tools.d on POSIX,
  %ProgramData%\lmcp\tools.d on Windows) for *.lua files.
- Each plugin file is invoked as a function receiving (server, run):
    local server, run = ...
    server:tool("my_local_tool", "...", {...}, function(a) return ... end)
- Load errors and runtime errors are reported on stderr and skipped;
  the server continues with the tools it successfully loaded.

Why:
Hosts like hertz and ampere have always carried local /opt/lmcp/server.lua
overrides containing both packaged-overlap tools (shell, read_file, …)
AND host-specific tools (fritz, ha_api, mqtt_*, lxc_exec, …). When the
override drifts, the host either loses packaged improvements (the v1.1.1
fetch/web_search regression on hertz/ampere) or accumulates hand-merged
patches that vanish on shutdown (the original symptom in issue #22).
With tools.d/, hosts drop ONLY their custom tools as plugin files; the
packaged server.lua stays canonical. apt upgrade picks up new packaged
tools automatically.

Smoke-tested:
  $ mkdir -p /tmp/probe && cat > /tmp/probe/p.lua <<E
  local server, run = ...
  server:tool("plugin_probe", "test", {type="object"},
              function() return "ok" end)
  E
  $ LMCP_TOOLS_DIR=/tmp/probe lua server.lua
  lmcp: loaded plugin /tmp/probe/p.lua
  $ curl POST tools/list → plugin_probe present in the 10 tools listed

Existing single-file server deployments (no /opt/lmcp/tools.d/) keep
working unchanged — io.popen on a non-existent directory returns nil
and the plugin loop no-ops. Backwards compatible.

Closes the structural side of #22 (the ad-hoc-override pattern); ampere
+ hertz migration to use tools.d/ for their custom tools is the operator
follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 23:32:12 +00:00
2026-04-14 19:58:40 +00:00

lmcp — Lua MCP server

Lightweight Model Context Protocol (MCP) server in pure Lua.

Runtime dependencies

  • Lua 5.1+
  • luasocket — needed for the TCP listener. Packaged as lua-socket on Arch/ALARM, lua-socket on Debian.

Files

File Role
lmcp.lua library: protocol handling, tool registration
server.lua HTTP server loop
json.lua vendored JSON encoder/decoder
example_server.lua sample server with a couple of tools

Install

Packaged as lmcp in the marfrit overlay repo:

# Arch / ALARM
sudo pacman -S lmcp

# Debian
sudo apt install lmcp

Files land under /usr/share/lua/5.4/ (Lua LUA_PATH). The example server installs as /usr/bin/lmcp-example.

S
Description
Lightweight MCP server in pure Lua. 2MB RSS. Zero deps beyond luasocket.
Readme 296 KiB
Languages
Lua 93.1%
Shell 6.2%
Batchfile 0.7%