forked from marfrit/lmcp
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fa98dd655 | |||
| a7b3c44f1c | |||
| 840341d2dd | |||
| 8748fe53bc | |||
| 8d8d8fac65 | |||
| 3dd01e5313 | |||
| d2c2962ad1 | |||
| c5375b8a77 | |||
| e05438f0e3 | |||
| 9707f7ae93 | |||
| 9e53b23b11 | |||
| 7e62f71931 | |||
| 55ead8041f | |||
| 2ac502e50f | |||
| deb73d129e |
+13
@@ -0,0 +1,13 @@
|
||||
# Generated by windows/sync.sh — see windows/README.md
|
||||
windows/pkg/lmcp.lua
|
||||
windows/pkg/server.lua
|
||||
windows/pkg/json.lua
|
||||
|
||||
# Bundled Lua + LuaSocket runtime for the Windows MSI; downloaded
|
||||
# separately, not in git.
|
||||
windows/pkg/lua/
|
||||
|
||||
# Editor / OS noise
|
||||
*.swp
|
||||
*.swo
|
||||
.DS_Store
|
||||
+111
-5
@@ -11,6 +11,10 @@ local server = lmcp.new("example-tools", {
|
||||
port = tonumber(arg[1]) or 8080,
|
||||
})
|
||||
|
||||
-- The optional 5th `opts` arg to server:tool carries MCP annotations.
|
||||
-- Omit it and clients assume the worst (destructive, openWorld) — fine
|
||||
-- for prototypes; declare annotations once you know each tool's stance.
|
||||
|
||||
server:tool("shell", "Execute a shell command", {
|
||||
type = "object",
|
||||
properties = {
|
||||
@@ -24,7 +28,15 @@ server:tool("shell", "Execute a shell command", {
|
||||
local result = handle:read('*a')
|
||||
handle:close()
|
||||
return result ~= '' and result or '(no output)'
|
||||
end)
|
||||
end, {
|
||||
annotations = {
|
||||
title = "Run shell",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = true,
|
||||
idempotentHint = false,
|
||||
openWorldHint = true,
|
||||
},
|
||||
})
|
||||
|
||||
server:tool("read_file", "Read a file", {
|
||||
type = "object",
|
||||
@@ -38,7 +50,15 @@ server:tool("read_file", "Read a file", {
|
||||
local content = f:read('*a')
|
||||
f:close()
|
||||
return content
|
||||
end)
|
||||
end, {
|
||||
annotations = {
|
||||
title = "Read file",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = false,
|
||||
},
|
||||
})
|
||||
|
||||
server:tool("write_file", "Write content to a file", {
|
||||
type = "object",
|
||||
@@ -53,7 +73,15 @@ server:tool("write_file", "Write content to a file", {
|
||||
f:write(args.content)
|
||||
f:close()
|
||||
return string.format("Written %d bytes to %s", #args.content, args.path)
|
||||
end)
|
||||
end, {
|
||||
annotations = {
|
||||
title = "Write file",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = true,
|
||||
idempotentHint = true,
|
||||
openWorldHint = false,
|
||||
},
|
||||
})
|
||||
|
||||
server:tool("list_dir", "List directory contents", {
|
||||
type = "object",
|
||||
@@ -67,7 +95,85 @@ server:tool("list_dir", "List directory contents", {
|
||||
local result = handle:read('*a')
|
||||
handle:close()
|
||||
return result
|
||||
end, {
|
||||
annotations = {
|
||||
title = "List directory",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = false,
|
||||
},
|
||||
})
|
||||
|
||||
-- ---- Resources (MCP primitive — see issue #5) ----
|
||||
-- Tools-only servers force the client to spend a tools/call round-trip
|
||||
-- for every read. Resources let the client list and read by URI, with a
|
||||
-- stable identity it can cache and reference in prompts.
|
||||
|
||||
server:resource("text://greeting", {
|
||||
name = "Greeting",
|
||||
mimeType = "text/plain",
|
||||
}, function() return "Hello from lmcp!" end)
|
||||
|
||||
-- Tiny binary resource: 8-byte PNG signature, demonstrates blob handling.
|
||||
server:resource("data://lmcp.png", {
|
||||
name = "PNG signature",
|
||||
mimeType = "image/png",
|
||||
}, function()
|
||||
return { blob_bytes = "\x89PNG\r\n\x1a\n", mimeType = "image/png" }
|
||||
end)
|
||||
|
||||
io.stderr:write("Starting lmcp example server...\n")
|
||||
server:run()
|
||||
-- Template: any local file. `args.path` is captured greedily (no leading
|
||||
-- slash because the template literal already includes ///).
|
||||
server:resource_template("file:///{path}", {
|
||||
name = "Local file",
|
||||
mimeType = "text/plain",
|
||||
}, function(args)
|
||||
local f = io.open("/" .. args.path, "r")
|
||||
if not f then error("file not found: /" .. args.path) end
|
||||
local content = f:read("*a"); f:close()
|
||||
return content
|
||||
end)
|
||||
|
||||
-- ---- Prompts (MCP primitive — see issue #6) ----
|
||||
-- Parameterised prompt templates the client surfaces as a menu
|
||||
-- (slash-commands, snippets). Handler returns either a plain string (one
|
||||
-- user-role text message) or a full { description?, messages = {...} }
|
||||
-- shape for finer control.
|
||||
|
||||
server:prompt("release_note", {
|
||||
description = "Draft a release note for a given version",
|
||||
arguments = {
|
||||
{ name = "version", description = "Tag, e.g. v0.7.1", required = true },
|
||||
{ name = "since", description = "Previous tag", required = false },
|
||||
},
|
||||
}, function(args)
|
||||
return "Write concise release notes for version " .. (args.version or "?")
|
||||
.. " since " .. (args.since or "the previous tag")
|
||||
.. ". Group by category (features / fixes / docs)."
|
||||
end)
|
||||
|
||||
-- Completion for the release_note prompt's `version` argument. Returned
|
||||
-- list is filtered against `value` (prefix match) by the server's spec
|
||||
-- contract is "candidates"; clients may further filter.
|
||||
server:complete("ref/prompt", "release_note", "version", function(value, ctx)
|
||||
local all = { "v0.5.0", "v0.5.1", "v0.5.2", "v0.5.3", "v0.5.4",
|
||||
"v0.6.0", "v0.7.0", "v0.7.1", "v1.0.0-rc1" }
|
||||
if value == "" then return all end
|
||||
local out = {}
|
||||
for _, v in ipairs(all) do
|
||||
if v:sub(1, #value) == value then out[#out + 1] = v end
|
||||
end
|
||||
return out
|
||||
end)
|
||||
|
||||
local transport = os.getenv("LMCP_TRANSPORT") or "http"
|
||||
if transport == "stdio" then
|
||||
if os.getenv("LMCP_PORT") then
|
||||
io.stderr:write("lmcp: LMCP_PORT ignored in stdio mode\n")
|
||||
end
|
||||
server:run_stdio()
|
||||
else
|
||||
io.stderr:write("Starting lmcp example server...\n")
|
||||
server:run()
|
||||
end
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import urllib.request, json, threading, queue, sys
|
||||
BASE="http://192.168.88.184:8080"
|
||||
q=queue.Queue()
|
||||
def sse():
|
||||
try:
|
||||
r=urllib.request.urlopen(BASE+"/sse", timeout=30)
|
||||
for raw in r:
|
||||
s=raw.decode(errors="replace").strip()
|
||||
if s.startswith("data:"): q.put(s[5:].strip())
|
||||
except Exception as e: q.put("ERR:"+str(e))
|
||||
threading.Thread(target=sse,daemon=True).start()
|
||||
try:
|
||||
ep=q.get(timeout=10)
|
||||
if ep.startswith("ERR:"): print("stash unreachable:",ep); sys.exit(1)
|
||||
purl=BASE+ep if ep.startswith("/") else ep
|
||||
def post(o):
|
||||
urllib.request.urlopen(urllib.request.Request(purl,data=json.dumps(o).encode(),headers={"Content-Type":"application/json"}),timeout=15).read()
|
||||
post({"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"apropos","version":"1"}}})
|
||||
q.get(timeout=10)
|
||||
post({"jsonrpc":"2.0","method":"notifications/initialized"})
|
||||
query=sys.argv[1] if len(sys.argv)>1 else ""
|
||||
limit=int(sys.argv[2]) if len(sys.argv)>2 else 3
|
||||
post({"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"recall","arguments":{"query":query,"limit":limit}}})
|
||||
d=json.loads(q.get(timeout=25))
|
||||
txt=d.get("result",{}).get("content",[{}])[0].get("text","[]")
|
||||
facts=json.loads(txt)
|
||||
if not facts: print("(no memory found for: %s)"%query); sys.exit(0)
|
||||
for f in facts: print("- %s (score %.2f)" % (f.get("content","").strip(), f.get("score",0)))
|
||||
except Exception as e: print("recall error:",e); sys.exit(1)
|
||||
@@ -505,7 +505,14 @@ server:tool("remote_list_hosts",
|
||||
)
|
||||
end
|
||||
return table.concat(lines, "\n")
|
||||
end
|
||||
end,
|
||||
{ annotations = {
|
||||
title = "List fleet hosts",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_shell", "Run a shell command on a fleet host. lmcp-primary with ssh fallback.",
|
||||
@@ -515,7 +522,14 @@ server:tool("remote_shell", "Run a shell command on a fleet host. lmcp-primary w
|
||||
cwd = { type = "string", description = "Working directory" },
|
||||
timeout = { type = "integer", description = "Timeout (seconds)", default = 120 },
|
||||
}, required = { "host", "command" } },
|
||||
function(a) return call_remote("shell", a, true, ssh_shell) end
|
||||
function(a) return call_remote("shell", a, true, ssh_shell) end,
|
||||
{ annotations = {
|
||||
title = "Remote shell",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = true,
|
||||
idempotentHint = false,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_read_file", "Read a file from a fleet host.",
|
||||
@@ -523,7 +537,14 @@ server:tool("remote_read_file", "Read a file from a fleet host.",
|
||||
host = HOST_ARG,
|
||||
path = { type = "string", description = "File path" },
|
||||
}, required = { "host", "path" } },
|
||||
function(a) return call_remote("read_file", a, true, ssh_read_file) end
|
||||
function(a) return call_remote("read_file", a, true, ssh_read_file) end,
|
||||
{ annotations = {
|
||||
title = "Remote read file",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_write_file", "Write content to a file on a fleet host.",
|
||||
@@ -532,7 +553,14 @@ server:tool("remote_write_file", "Write content to a file on a fleet host.",
|
||||
path = { type = "string" },
|
||||
content = { type = "string" },
|
||||
}, required = { "host", "path", "content" } },
|
||||
function(a) return call_remote("write_file", a, true, ssh_write_file) end
|
||||
function(a) return call_remote("write_file", a, true, ssh_write_file) end,
|
||||
{ annotations = {
|
||||
title = "Remote write file",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = true,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_edit_file",
|
||||
@@ -544,7 +572,14 @@ server:tool("remote_edit_file",
|
||||
new_string = { type = "string" },
|
||||
replace_all = { type = "boolean", default = false },
|
||||
}, required = { "host", "path", "old_string", "new_string" } },
|
||||
function(a) return call_remote("edit_file", a, false, nil) end
|
||||
function(a) return call_remote("edit_file", a, false, nil) end,
|
||||
{ annotations = {
|
||||
title = "Remote edit file",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = true,
|
||||
idempotentHint = false,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_shell_bg",
|
||||
@@ -555,7 +590,14 @@ server:tool("remote_shell_bg",
|
||||
cwd = { type = "string" },
|
||||
log = { type = "string", description = "Log file path" },
|
||||
}, required = { "host", "command" } },
|
||||
function(a) return call_remote("shell_bg", a, false, nil) end
|
||||
function(a) return call_remote("shell_bg", a, false, nil) end,
|
||||
{ annotations = {
|
||||
title = "Remote shell (background)",
|
||||
readOnlyHint = false,
|
||||
destructiveHint = true,
|
||||
idempotentHint = false,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_list_dir", "List directory entries on a fleet host.",
|
||||
@@ -563,7 +605,14 @@ server:tool("remote_list_dir", "List directory entries on a fleet host.",
|
||||
host = HOST_ARG,
|
||||
path = { type = "string", default = "." },
|
||||
}, required = { "host" } },
|
||||
function(a) return call_remote("list_dir", a, true, ssh_list_dir) end
|
||||
function(a) return call_remote("list_dir", a, true, ssh_list_dir) end,
|
||||
{ annotations = {
|
||||
title = "Remote list directory",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
server:tool("remote_search_files", "find-by-pattern on a fleet host.",
|
||||
@@ -572,7 +621,14 @@ server:tool("remote_search_files", "find-by-pattern on a fleet host.",
|
||||
pattern = { type = "string" },
|
||||
path = { type = "string", default = "/" },
|
||||
}, required = { "host", "pattern" } },
|
||||
function(a) return call_remote("search_files", a, true, ssh_search_files) end
|
||||
function(a) return call_remote("search_files", a, true, ssh_search_files) end,
|
||||
{ annotations = {
|
||||
title = "Remote find files",
|
||||
readOnlyHint = true,
|
||||
destructiveHint = false,
|
||||
idempotentHint = true,
|
||||
openWorldHint = true,
|
||||
} }
|
||||
)
|
||||
|
||||
io.stderr:write(string.format("lmcp-hub starting on port %d with %d backends from %s\n",
|
||||
|
||||
@@ -60,6 +60,13 @@ encode_value = function(v)
|
||||
local t = type(v)
|
||||
if v == nil or v == json.null then
|
||||
return 'null'
|
||||
elseif v == json.empty_object then
|
||||
-- Sentinel for forcing {} (object) instead of [] (array) when
|
||||
-- the field semantically requires an object but is empty.
|
||||
-- Without this, every empty Lua table goes through is_array()
|
||||
-- and emits as [], breaking spec-strict JSON-RPC consumers
|
||||
-- (e.g. ping result, MUST be {}).
|
||||
return '{}'
|
||||
elseif t == 'boolean' then
|
||||
return v and 'true' or 'false'
|
||||
elseif t == 'number' then
|
||||
@@ -110,9 +117,20 @@ local function decode_string(s, pos)
|
||||
pos = pos + 1
|
||||
c = s:sub(pos, pos)
|
||||
if c == 'u' then
|
||||
local hex = s:sub(pos + 1, pos + 4)
|
||||
parts[#parts + 1] = utf8.char(tonumber(hex, 16))
|
||||
local cp = tonumber(s:sub(pos + 1, pos + 4), 16)
|
||||
pos = pos + 5
|
||||
-- Combine UTF-16 surrogate pair so non-BMP chars (emoji,
|
||||
-- supplementary CJK) decode correctly instead of as two
|
||||
-- lone surrogates → invalid UTF-8.
|
||||
if cp and cp >= 0xD800 and cp <= 0xDBFF
|
||||
and s:sub(pos, pos + 1) == "\\u" then
|
||||
local lo = tonumber(s:sub(pos + 2, pos + 5), 16)
|
||||
if lo and lo >= 0xDC00 and lo <= 0xDFFF then
|
||||
cp = (cp - 0xD800) * 0x400 + (lo - 0xDC00) + 0x10000
|
||||
pos = pos + 6
|
||||
end
|
||||
end
|
||||
parts[#parts + 1] = utf8.char(cp)
|
||||
else
|
||||
local esc = { n = '\n', r = '\r', t = '\t', b = '\b', f = '\f' }
|
||||
parts[#parts + 1] = esc[c] or c
|
||||
@@ -210,6 +228,12 @@ end
|
||||
-- Sentinel for JSON null
|
||||
json.null = setmetatable({}, { __tostring = function() return 'null' end })
|
||||
|
||||
-- Sentinel for an empty JSON object ({}). Use when a field semantically
|
||||
-- requires an object but is empty — e.g. `ping` result, MCP _meta = {}.
|
||||
-- Without this, an empty Lua table goes through is_array() → '[]'.
|
||||
-- See memory project_json_empty_table_gotcha.md.
|
||||
json.empty_object = setmetatable({}, { __tostring = function() return '{}' end })
|
||||
|
||||
-- Helper: encode a table as a JSON array even if empty
|
||||
function json.array(t)
|
||||
return setmetatable(t or {}, { __is_array = true })
|
||||
|
||||
+889
-35
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,292 @@
|
||||
-- /opt/lmcp/tools.d/hertz.lua — hertz-specific tool registrations.
|
||||
--
|
||||
-- Invoked by the packaged server.lua's tools.d scan (lmcp ≥ v1.2.0, issue #22).
|
||||
-- Receives (server, run) — the configured lmcp instance and the
|
||||
-- coroutine-aware run() helper. We add hertz-only tools on top of the
|
||||
-- packaged generics (shell, read_file, write_file, edit_file, list_dir,
|
||||
-- search_files, fetch, web_search, shell_bg).
|
||||
--
|
||||
-- Previously these all lived in /opt/lmcp/server.lua (a copy-paste fork of
|
||||
-- the packaged server.lua). That pattern drifted on every release; now the
|
||||
-- packaged file stays canonical and only the genuine hertz-specifics live
|
||||
-- here.
|
||||
|
||||
local server, run = ...
|
||||
|
||||
-- Local helpers — single-host scoped, not worth lifting into the packaged lib.
|
||||
local function read_file_raw(path)
|
||||
local f = io.open(path, 'r')
|
||||
if not f then return nil end
|
||||
local c = f:read('*a'); f:close(); return c
|
||||
end
|
||||
|
||||
local function farad(cmd, timeout)
|
||||
return run("incus exec farad -- sh -c " .. string.format("%q", cmd),
|
||||
timeout or 15)
|
||||
end
|
||||
|
||||
-- ---- LXD tools ----
|
||||
|
||||
server:tool("incus_exec", "Execute a command inside an Incus container on hertz.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
container = { type = "string", description = "Container name" },
|
||||
command = { type = "string", description = "Command to execute" },
|
||||
timeout = { type = "integer", default = 30 },
|
||||
},
|
||||
required = { "container", "command" },
|
||||
}, function(a)
|
||||
return run(string.format("incus exec %s -- sh -c %q",
|
||||
a.container:gsub("[^%w%-]", ""), a.command), a.timeout or 30)
|
||||
end)
|
||||
|
||||
server:tool("incus_list", "List all Incus containers on hertz.",
|
||||
{ type = "object" },
|
||||
function() return run("incus list -c ns4 -f csv", 10) end)
|
||||
|
||||
-- ---- Fritz!Box tools ----
|
||||
|
||||
server:tool("fritz", "Execute Fritz!Box TR-064 command (info, hosts, wan, "
|
||||
.. "wol <mac>, reconnect, reboot, reboot-repeater <ip>, routes, route-add, "
|
||||
.. "route-del, services, actions, call).",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
command = { type = "string", description = "fritz subcommand and args" },
|
||||
},
|
||||
required = { "command" },
|
||||
},
|
||||
function(a) return run("sudo /root/.local/bin/fritz " .. a.command, 15) end)
|
||||
|
||||
-- ---- Network tools ----
|
||||
|
||||
server:tool("ping_host", "Check if a host is reachable (1 ICMP ping, 2s timeout).", {
|
||||
type = "object",
|
||||
properties = { host = { type = "string" } },
|
||||
required = { "host" },
|
||||
}, function(a)
|
||||
local host = a.host:gsub("[^%w%.%-:]", "")
|
||||
return run("ping -c1 -W2 " .. host, 5)
|
||||
end)
|
||||
|
||||
server:tool("network_status",
|
||||
"Check reachability of all infrastructure hosts and MCP endpoints.",
|
||||
{ type = "object" },
|
||||
function()
|
||||
local script = [[
|
||||
hosts="hertz:localhost boltzmann:boltzmann tesla:tesla data:192.168.88.30 broglie:192.168.88.160 higgs:10.170.16.10"
|
||||
for entry in $hosts; do
|
||||
name="${entry%%:*}"
|
||||
ip="${entry#*:}"
|
||||
if ping -c1 -W2 "$ip" >/dev/null 2>&1; then
|
||||
status="UP"
|
||||
if [ "$name" != "data" ]; then
|
||||
if timeout 3 bash -c "echo >/dev/tcp/${ip}/8080" 2>/dev/null; then
|
||||
status="UP (MCP ok)"
|
||||
else
|
||||
status="UP (no MCP)"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
status="DOWN"
|
||||
fi
|
||||
printf "%-12s %-20s %s\n" "$name" "$ip" "$status"
|
||||
done
|
||||
]]
|
||||
return run(script, 30)
|
||||
end)
|
||||
|
||||
server:tool("wol_and_wait",
|
||||
"Wake the data server via Fritz!Box WoL and wait until it (or broglie MCP) is reachable.",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
mac = { type = "string", default = "", description = "MAC address (auto-detected if empty)" },
|
||||
wait_for_mcp = { type = "boolean", default = true, description = "Wait for broglie MCP instead of just ping" },
|
||||
timeout = { type = "integer", default = 120 },
|
||||
},
|
||||
},
|
||||
function(a)
|
||||
local mac = a.mac
|
||||
if not mac or mac == "" then
|
||||
local hosts_out = run("sudo /root/.local/bin/fritz hosts 2>/dev/null | grep -i 'data\\|192.168.88.30'", 10)
|
||||
mac = hosts_out and hosts_out:match("(%x%x:%x%x:%x%x:%x%x:%x%x:%x%x)") or ""
|
||||
if mac == "" then return "Error: could not detect MAC for data. Provide it manually." end
|
||||
end
|
||||
run("sudo /root/.local/bin/fritz wol " .. mac:gsub("[^%x:]", ""), 10)
|
||||
|
||||
local timeout = a.timeout or 120
|
||||
local check
|
||||
if a.wait_for_mcp == false then
|
||||
check = "ping -c1 -W2 192.168.88.30"
|
||||
else
|
||||
check = "timeout 3 bash -c 'echo >/dev/tcp/192.168.88.160/8080'"
|
||||
end
|
||||
local target = (a.wait_for_mcp == false) and "data" or "broglie:8080"
|
||||
|
||||
local elapsed = 0
|
||||
while elapsed < timeout do
|
||||
os.execute("sleep 5")
|
||||
elapsed = elapsed + 5
|
||||
local rc = os.execute(check)
|
||||
if rc == true or rc == 0 then
|
||||
return string.format("WoL sent to %s. %s reachable after %ds.",
|
||||
mac, target, elapsed)
|
||||
end
|
||||
end
|
||||
return string.format("WoL sent to %s but %s not reachable after %ds.",
|
||||
mac, target, timeout)
|
||||
end)
|
||||
|
||||
-- ---- Proxmox fallback ----
|
||||
|
||||
server:tool("pct_exec",
|
||||
"Execute a command in a Proxmox CT on data (SSH fallback when broglie is down).",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
ctid = { type = "string", description = "Container ID (e.g. 108, 165)" },
|
||||
command = { type = "string" },
|
||||
timeout = { type = "integer", default = 30 },
|
||||
},
|
||||
required = { "ctid", "command" },
|
||||
},
|
||||
function(a)
|
||||
local ctid = a.ctid:gsub("[^%d]", "")
|
||||
return run(string.format("ssh -o ConnectTimeout=5 root@data 'pct exec %s -- sh -c %q'",
|
||||
ctid, a.command), a.timeout or 30)
|
||||
end)
|
||||
|
||||
-- ---- Home Assistant ----
|
||||
|
||||
server:tool("ha_cli",
|
||||
"Run Home Assistant CLI command inside farad (e.g. 'core restart', 'backups list', 'info').",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
command = { type = "string", description = "ha subcommand, e.g. 'core restart', 'supervisor info', 'backups list'" },
|
||||
raw_json = { type = "boolean", default = false, description = "Return raw JSON output" },
|
||||
},
|
||||
required = { "command" },
|
||||
},
|
||||
function(a)
|
||||
local flags = a.raw_json and " --raw-json" or ""
|
||||
return farad("ha " .. a.command .. flags)
|
||||
end)
|
||||
|
||||
server:tool("ha_api",
|
||||
"Call Home Assistant Core REST API. Requires token in /opt/lmcp/ha_token on hertz.",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
method = { type = "string", default = "GET" },
|
||||
endpoint = { type = "string", description = "/api/states, /api/services/climate/set_temperature, etc." },
|
||||
body = { type = "string", description = "JSON body for POST" },
|
||||
},
|
||||
required = { "endpoint" },
|
||||
},
|
||||
function(a)
|
||||
local token = read_file_raw("/opt/lmcp/ha_token")
|
||||
if not token or token == "" then
|
||||
return "Error: no HA token. Create a long-lived token in HA UI → Profile → "
|
||||
.. "Long-Lived Access Tokens, then: echo '<token>' | sudo tee /opt/lmcp/ha_token"
|
||||
end
|
||||
token = token:gsub("%s+", "")
|
||||
local method = (a.method or "GET"):upper()
|
||||
local cmd = string.format(
|
||||
"curl -sf -X %s -H 'Authorization: Bearer %s' -H 'Content-Type: application/json'",
|
||||
method, token)
|
||||
if a.body and a.body ~= "" then
|
||||
cmd = cmd .. " -d " .. string.format("'%s'", a.body:gsub("'", "'\\''"))
|
||||
end
|
||||
cmd = cmd .. " http://localhost:8123" .. a.endpoint
|
||||
return farad(cmd, 15)
|
||||
end)
|
||||
|
||||
-- ---- MQTT (Eurotronic thermostats + general) ----
|
||||
|
||||
server:tool("mqtt_pub", "Publish an MQTT message (via Mosquitto in farad).", {
|
||||
type = "object",
|
||||
properties = {
|
||||
topic = { type = "string" },
|
||||
message = { type = "string" },
|
||||
retain = { type = "boolean", default = false },
|
||||
},
|
||||
required = { "topic", "message" },
|
||||
}, function(a)
|
||||
local retain = a.retain and "-r " or ""
|
||||
return farad(string.format("mosquitto_pub %s-t '%s' -m '%s'",
|
||||
retain, a.topic:gsub("'", "'\\''"), a.message:gsub("'", "'\\''")))
|
||||
end)
|
||||
|
||||
server:tool("mqtt_sub",
|
||||
"Subscribe to MQTT topics and collect messages (via Mosquitto in farad).",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
topic = { type = "string", description = "Topic pattern, e.g. 'eurotronic/#' or '#'" },
|
||||
count = { type = "integer", default = 10, description = "Number of messages to collect" },
|
||||
timeout = { type = "integer", default = 5, description = "Seconds to wait" },
|
||||
verbose = { type = "boolean", default = true, description = "Show topics with messages" },
|
||||
},
|
||||
required = { "topic" },
|
||||
},
|
||||
function(a)
|
||||
local v = a.verbose ~= false and "-v " or ""
|
||||
return farad(string.format("mosquitto_sub %s-t '%s' -C %d -W %d",
|
||||
v, a.topic:gsub("'", "'\\''"), a.count or 10, a.timeout or 5),
|
||||
(a.timeout or 5) + 5)
|
||||
end)
|
||||
|
||||
-- ---- Mediagrab (kids show downloader) ----
|
||||
|
||||
server:tool("mediagrab",
|
||||
"Manage kids show downloads in doppler container. Commands: list, weekly, "
|
||||
.. "archive, test <url>, add '<json>'",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
command = { type = "string", description = "Command: list, weekly, archive, 'test <url>', 'add <json>'" },
|
||||
},
|
||||
required = { "command" },
|
||||
},
|
||||
function(a)
|
||||
return run("incus exec doppler -- python3 /opt/mediagrab/mediagrab.py "
|
||||
.. a.command, 120)
|
||||
end)
|
||||
|
||||
-- ---- Fleet wake (pipi: wake-only, no power-off) ----
|
||||
server:tool("wake_fleet",
|
||||
"Wake a fleet NUC (pve1..pve4) via Fritz!Box Wake-on-LAN. Powers a node ON only; it cannot power anything off. Node boots in ~30-60s.",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
node = { type = "string", description = "Node to wake: '1'..'4' or 'pve1'..'pve4'" },
|
||||
},
|
||||
required = { "node" },
|
||||
},
|
||||
function(a)
|
||||
local node = tostring(a.node or ""):gsub("[^%w]", "")
|
||||
if not node:match("^p?v?e?[1-4]$") then
|
||||
return "Error: node must be 1-4 or pve1-pve4 (got: " .. tostring(a.node) .. ")"
|
||||
end
|
||||
return run("sudo /root/.local/bin/wake-pve " .. node .. " 2>&1", 15)
|
||||
end)
|
||||
|
||||
-- ---- apropos: lean facade for stash recall (read-only memory) ----
|
||||
server:tool("apropos",
|
||||
"Search shared fleet memory (stash) for facts about the fleet, projects, decisions, and preferences. query = 2-6 words on the topic; limit = max results (default 3). Read-only.",
|
||||
{
|
||||
type = "object",
|
||||
properties = {
|
||||
query = { type = "string", description = "2-6 words describing what to recall" },
|
||||
limit = { type = "integer", description = "max results, default 3" },
|
||||
},
|
||||
required = { "query" },
|
||||
},
|
||||
function(a)
|
||||
local q = tostring(a.query or ""):gsub("[^%w%s%-%.]", " "):gsub("%s+", " ")
|
||||
if q:gsub("%s","") == "" then return "Error: query required" end
|
||||
local lim = tonumber(a.limit) or 3
|
||||
return run("python3 /opt/lmcp/helpers/stash_recall.py '" .. q .. "' " .. lim, 30)
|
||||
end)
|
||||
@@ -0,0 +1,103 @@
|
||||
-- /opt/lmcp/tools.d/nash.lua -- nash shared memory tools
|
||||
--
|
||||
-- Provides add/search/list/delete tools for the nash memory service.
|
||||
-- Requires NASH_URL env var (e.g. http://192.168.88.143:8000).
|
||||
-- When unset, tools return an error guiding the user to set it.
|
||||
--
|
||||
-- SPDX-License-Identifier: MIT
|
||||
|
||||
local server, run = ...
|
||||
|
||||
local function nash_url()
|
||||
local url = os.getenv("NASH_URL")
|
||||
if not url or url == "" then return nil end
|
||||
return url:gsub("/+$", "")
|
||||
end
|
||||
|
||||
local function curl_json(url, method, body, timeout)
|
||||
timeout = timeout or 10
|
||||
local out = "/tmp/lmcp-nash-" .. os.time() .. "-" .. math.random(10000, 99999) .. ".json"
|
||||
local fmt = "http_code=%{http_code}"
|
||||
local cmd
|
||||
if body then
|
||||
local tmp = out .. ".req"
|
||||
local f = io.open(tmp, "w")
|
||||
if f then f:write(body); f:close() end
|
||||
cmd = string.format(
|
||||
"curl -sS -X %s --max-time %d -H 'Content-Type: application/json' --data-binary '@%s' -o '%s' -w '%s' '%s'",
|
||||
method, timeout, tmp, out, fmt, url
|
||||
)
|
||||
os.execute("rm -f '" .. tmp .. "' 2>/dev/null")
|
||||
else
|
||||
cmd = string.format(
|
||||
"curl -sS -X %s --max-time %d -o '%s' -w '%s' '%s'",
|
||||
method, timeout, out, fmt, url
|
||||
)
|
||||
end
|
||||
local raw = run(cmd, timeout + 5) or ""
|
||||
local http_code = tonumber(raw:match("(%d+)$")) or 0
|
||||
local body_out = ""
|
||||
local f = io.open(out, "r")
|
||||
if f then body_out = f:read("*a") or ""; f:close() end
|
||||
os.execute("rm -f '" .. out .. "' 2>/dev/null")
|
||||
return body_out, http_code
|
||||
end
|
||||
|
||||
server:tool("nash_add", "Store a text entry in shared nash memory.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
text = { type = "string", description = "Text content to remember" },
|
||||
},
|
||||
required = { "text" },
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local json, code = curl_json(base .. "/add", "POST", '{"text":' .. require("json").encode(a.text) .. '}')
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
|
||||
server:tool("nash_search", "Semantic search across shared nash memory.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
query = { type = "string", description = "Search query" },
|
||||
limit = { type = "integer", description = "Max results (default 5)", default = 5 },
|
||||
},
|
||||
required = { "query" },
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local body = '{"query":' .. require("json").encode(a.query) .. ',"limit":' .. (a.limit or 5) .. '}'
|
||||
local json, code = curl_json(base .. "/search", "POST", body)
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
|
||||
server:tool("nash_list", "List all entries in shared nash memory.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
limit = { type = "integer", description = "Max results (default 100)", default = 100 },
|
||||
},
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local body = '{"limit":' .. (a.limit or 100) .. '}'
|
||||
local json, code = curl_json(base .. "/scroll", "POST", body)
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
|
||||
server:tool("nash_delete", "Delete an entry from shared nash memory by ID.", {
|
||||
type = "object",
|
||||
properties = {
|
||||
id = { type = "string", description = "Entry ID to delete" },
|
||||
},
|
||||
required = { "id" },
|
||||
}, function(a)
|
||||
local base = nash_url()
|
||||
if not base then return "Error: set NASH_URL env var (e.g. http://192.168.88.143:8000)" end
|
||||
local body = '{"id":' .. require("json").encode(a.id) .. '}'
|
||||
local json, code = curl_json(base .. "/delete", "POST", body)
|
||||
if code ~= 200 then return "Error: nash API HTTP " .. code .. ": " .. json end
|
||||
return json
|
||||
end)
|
||||
@@ -0,0 +1,57 @@
|
||||
# lmcp Windows MSI build
|
||||
|
||||
This directory contains the WiX manifest and packaging files for the
|
||||
Windows MSI build of lmcp.
|
||||
|
||||
## Recommended: cross-build on Linux (one command)
|
||||
|
||||
```sh
|
||||
./build-msi.sh /path/to/output/dir
|
||||
```
|
||||
|
||||
Downloads Lua 5.4 Win64 binaries from LuaBinaries, cross-compiles
|
||||
LuaSocket via `mingw-w64`, stages `pkg/lua/`, and runs `wixl` to
|
||||
produce `lmcp-<version>.msi`. No Windows VM required.
|
||||
|
||||
Prereqs on a Debian/Ubuntu builder:
|
||||
```sh
|
||||
sudo apt install wixl unzip gcc-mingw-w64-x86-64 \
|
||||
binutils-mingw-w64-x86-64 mingw-w64-x86-64-dev curl
|
||||
```
|
||||
|
||||
Version comes from `lmcp.wxs` `Version="…"`. Bump that before
|
||||
building a release.
|
||||
|
||||
## Alternative: build on Windows via WiX toolset
|
||||
|
||||
```cmd
|
||||
sync.sh REM see "tracked vs. generated"
|
||||
REM ensure pkg/lua/ has the runtime — see below
|
||||
candle.exe lmcp.wxs
|
||||
light.exe lmcp.wixobj -o lmcp-1.x.y.msi
|
||||
```
|
||||
|
||||
## What's tracked vs. generated
|
||||
|
||||
- **Tracked** (edit in git):
|
||||
- `lmcp.wxs` — WiX MSI manifest
|
||||
- `sync.sh` — copies root .lua sources → `pkg/`
|
||||
- `README.md` — this file
|
||||
- `pkg/install_service.bat` — Windows service installer
|
||||
- `pkg/start.bat` — manual launcher
|
||||
|
||||
- **Generated / external** (gitignored):
|
||||
- `pkg/lmcp.lua`, `pkg/server.lua`, `pkg/json.lua` — produced by
|
||||
`sync.sh`. Never edit directly; edit the root files and re-sync.
|
||||
- `pkg/lua/` — the Lua + LuaSocket runtime drop-in. Download
|
||||
separately and place here. Suggested source: the lua-binaries
|
||||
project (https://github.com/rjpcomputing/luaforwindows) or a
|
||||
similar pre-built bundle. The MSI expects `pkg/lua/lua.exe`,
|
||||
`pkg/lua/lua54.dll`, and the `pkg/lua/socket/` + `pkg/lua/mime/`
|
||||
subdirectories per the manifest.
|
||||
|
||||
## Issue history
|
||||
|
||||
Issue #18 (closed in v1.1.0) introduced this workflow after the
|
||||
`pkg/` lua sources had silently drifted ~6 months out of date,
|
||||
missing every feature added since April 2026.
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/bin/sh
|
||||
# windows/build-msi.sh — produce lmcp-<ver>.msi on Linux via wixl.
|
||||
#
|
||||
# This is the first-time-discovered cross-build path: download Lua 5.4
|
||||
# Win64 binaries from LuaBinaries, cross-compile LuaSocket with mingw-w64,
|
||||
# stage windows/pkg/lua/, then invoke wixl on the WiX manifest.
|
||||
#
|
||||
# Avoids the VM106-clone + WiX-on-Windows path entirely. ~1 minute on a
|
||||
# warm cache; ~3-5 minutes cold (downloads ~700 KB + cross-compiles).
|
||||
#
|
||||
# Prereqs (apt install on Debian aarch64):
|
||||
# apt-get install -y wixl unzip gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 \
|
||||
# mingw-w64-x86-64-dev
|
||||
#
|
||||
# Usage: ./build-msi.sh [output_dir]
|
||||
# Output: $output_dir/lmcp-<ver>.msi (default: $PWD)
|
||||
#
|
||||
# Version comes from windows/lmcp.wxs Version="…" attribute.
|
||||
set -eu
|
||||
|
||||
here=$(dirname "$(readlink -f "$0")")
|
||||
root=$(cd "$here/.." && pwd)
|
||||
out_dir=${1:-$PWD}
|
||||
work=$(mktemp -d /tmp/lmcp-msi-XXXXXX)
|
||||
trap "rm -rf $work" EXIT
|
||||
|
||||
# Versions — bump as upstream releases.
|
||||
LUA_VER=5.4.2
|
||||
LUASOCKET_VER=3.1.0
|
||||
|
||||
# Pull current lmcp version from the WiX manifest.
|
||||
lmcp_ver=$(sed -n 's/.*Version="\([^"]*\)".*/\1/p' "$here/lmcp.wxs" | head -1)
|
||||
[ -n "$lmcp_ver" ] || { echo "build-msi.sh: cannot parse Version from lmcp.wxs" >&2; exit 1; }
|
||||
|
||||
echo "build-msi.sh: lmcp $lmcp_ver, lua $LUA_VER, luasocket $LUASOCKET_VER"
|
||||
|
||||
echo "==> 1/5 sync lmcp .lua sources into pkg/"
|
||||
"$here/sync.sh"
|
||||
|
||||
echo "==> 2/5 fetch lua $LUA_VER win64 binaries + dev library"
|
||||
cd "$work"
|
||||
curl -sSLf -o lua-bin.zip \
|
||||
"https://downloads.sourceforge.net/project/luabinaries/${LUA_VER}/Tools%20Executables/lua-${LUA_VER}_Win64_bin.zip"
|
||||
curl -sSLf -o lua-lib.zip \
|
||||
"https://downloads.sourceforge.net/project/luabinaries/${LUA_VER}/Windows%20Libraries/Dynamic/lua-${LUA_VER}_Win64_dllw6_lib.zip"
|
||||
mkdir -p luabin lualib include/lua/54 include/lua54 bin/lua/54 bin/lua54 lib/lua/54 lib/lua54
|
||||
unzip -q -o lua-bin.zip -d luabin
|
||||
unzip -q -o lua-lib.zip -d lualib
|
||||
cp lualib/include/*.h include/lua/54/
|
||||
cp lualib/include/*.h include/lua54/
|
||||
cp lualib/liblua54.a lib/lua/54/
|
||||
cp lualib/liblua54.a lib/lua54/
|
||||
cp lualib/lua54.dll bin/lua/54/
|
||||
cp lualib/lua54.dll bin/lua54/
|
||||
|
||||
echo "==> 3/5 cross-compile LuaSocket $LUASOCKET_VER for win64"
|
||||
curl -sSLf -o luasocket.tar.gz \
|
||||
"https://github.com/lunarmodules/luasocket/archive/refs/tags/v${LUASOCKET_VER}.tar.gz"
|
||||
tar xzf luasocket.tar.gz
|
||||
cd "luasocket-${LUASOCKET_VER}"
|
||||
make -s PLAT=mingw \
|
||||
CC=x86_64-w64-mingw32-gcc \
|
||||
LD=x86_64-w64-mingw32-gcc \
|
||||
LUAV=54 \
|
||||
LUAINC_mingw_base="$work/include" \
|
||||
LUALIB_mingw_base="$work/bin" \
|
||||
> /dev/null
|
||||
|
||||
echo "==> 4/5 stage pkg/lua/"
|
||||
pkg_lua="$here/pkg/lua"
|
||||
rm -rf "$pkg_lua"
|
||||
mkdir -p "$pkg_lua/socket" "$pkg_lua/mime"
|
||||
|
||||
# WiX manifest expects "lua.exe" (not "lua54.exe").
|
||||
cp "$work/luabin/lua54.exe" "$pkg_lua/lua.exe"
|
||||
cp "$work/luabin/lua54.dll" "$pkg_lua/lua54.dll"
|
||||
cp src/socket.lua "$pkg_lua/"
|
||||
cp src/mime.lua "$pkg_lua/"
|
||||
cp src/ltn12.lua "$pkg_lua/"
|
||||
cp src/socket-3.0.0.dll "$pkg_lua/socket/core.dll"
|
||||
cp src/ftp.lua "$pkg_lua/socket/"
|
||||
cp src/headers.lua "$pkg_lua/socket/"
|
||||
cp src/http.lua "$pkg_lua/socket/"
|
||||
cp src/smtp.lua "$pkg_lua/socket/"
|
||||
cp src/tp.lua "$pkg_lua/socket/"
|
||||
cp src/url.lua "$pkg_lua/socket/"
|
||||
cp src/mime-1.0.3.dll "$pkg_lua/mime/core.dll"
|
||||
|
||||
echo "==> 5/5 wixl: produce MSI"
|
||||
# wixl wants forward slashes; rewrite Windows-style backslashes in Source=.
|
||||
wxs_tmp="$work/lmcp.wxs"
|
||||
sed 's|Source="pkg\\|Source="pkg/|g; s|\\\([a-zA-Z]\)|/\1|g' "$here/lmcp.wxs" > "$wxs_tmp"
|
||||
mkdir -p "$out_dir"
|
||||
out_msi="$out_dir/lmcp-${lmcp_ver}.msi"
|
||||
(cd "$here" && wixl -v "$wxs_tmp" -o "$out_msi")
|
||||
|
||||
echo ""
|
||||
echo "==> done: $out_msi"
|
||||
ls -la "$out_msi"
|
||||
sha256sum "$out_msi"
|
||||
@@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
|
||||
<!-- Bump Version on every release. See windows/README.md. -->
|
||||
<Product Id="*"
|
||||
Name="lmcp — Lua MCP Server"
|
||||
Language="1033"
|
||||
Version="1.1.0"
|
||||
Manufacturer="QAP'LA Project"
|
||||
UpgradeCode="A7F3E2D1-4B5C-6D7E-8F9A-0B1C2D3E4F5A">
|
||||
|
||||
<Package InstallerVersion="200"
|
||||
Compressed="yes"
|
||||
InstallScope="perMachine"
|
||||
Description="Lightweight MCP server in Lua. 2MB RSS."
|
||||
Comments="Zero-dependency MCP server." />
|
||||
|
||||
<MediaTemplate EmbedCab="yes" />
|
||||
|
||||
<MajorUpgrade DowngradeErrorMessage="A newer version is already installed." />
|
||||
|
||||
<Directory Id="TARGETDIR" Name="SourceDir">
|
||||
<Directory Id="ProgramFiles64Folder">
|
||||
<Directory Id="INSTALLFOLDER" Name="lmcp">
|
||||
<Directory Id="LUA_DIR" Name="lua">
|
||||
<Directory Id="SOCKET_DIR" Name="socket" />
|
||||
<Directory Id="MIME_DIR" Name="mime" />
|
||||
</Directory>
|
||||
</Directory>
|
||||
</Directory>
|
||||
</Directory>
|
||||
|
||||
<!-- lmcp application files -->
|
||||
<DirectoryRef Id="INSTALLFOLDER">
|
||||
<Component Id="JsonLua" Guid="B1A2C3D4-E5F6-7890-ABCD-EF1234567890">
|
||||
<File Id="json.lua" Source="pkg\json.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="LmcpLua" Guid="B1A2C3D4-E5F6-7890-ABCD-EF1234567891">
|
||||
<File Id="lmcp.lua" Source="pkg\lmcp.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="ServerLua" Guid="B1A2C3D4-E5F6-7890-ABCD-EF1234567892">
|
||||
<File Id="server.lua" Source="pkg\server.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="StartBat" Guid="B1A2C3D4-E5F6-7890-ABCD-EF1234567893">
|
||||
<File Id="start.bat" Source="pkg\start.bat" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="InstallService" Guid="B1A2C3D4-E5F6-7890-ABCD-EF1234567894">
|
||||
<File Id="install_service.bat" Source="pkg\install_service.bat" KeyPath="yes" />
|
||||
</Component>
|
||||
</DirectoryRef>
|
||||
|
||||
<!-- Lua runtime -->
|
||||
<DirectoryRef Id="LUA_DIR">
|
||||
<Component Id="LuaExe" Guid="C2B3D4E5-F6A7-8901-BCDE-F12345678900">
|
||||
<File Id="lua.exe" Source="pkg\lua\lua.exe" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="LuaDll" Guid="C2B3D4E5-F6A7-8901-BCDE-F12345678901">
|
||||
<File Id="lua54.dll" Source="pkg\lua\lua54.dll" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="SocketLua" Guid="C2B3D4E5-F6A7-8901-BCDE-F12345678902">
|
||||
<File Id="socket.lua" Source="pkg\lua\socket.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="MimeLua" Guid="C2B3D4E5-F6A7-8901-BCDE-F12345678903">
|
||||
<File Id="mime.lua" Source="pkg\lua\mime.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="Ltn12Lua" Guid="C2B3D4E5-F6A7-8901-BCDE-F12345678904">
|
||||
<File Id="ltn12.lua" Source="pkg\lua\ltn12.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
</DirectoryRef>
|
||||
|
||||
<!-- LuaSocket native DLLs -->
|
||||
<DirectoryRef Id="SOCKET_DIR">
|
||||
<Component Id="SocketCoreDll" Guid="D3C4E5F6-A7B8-9012-CDEF-123456789010">
|
||||
<File Id="socket_core.dll" Name="core.dll" Source="pkg\lua\socket\core.dll" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="SocketFtp" Guid="D3C4E5F6-A7B8-9012-CDEF-123456789011">
|
||||
<File Id="ftp.lua" Source="pkg\lua\socket\ftp.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="SocketHeaders" Guid="D3C4E5F6-A7B8-9012-CDEF-123456789012">
|
||||
<File Id="headers.lua" Source="pkg\lua\socket\headers.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="SocketHttp" Guid="D3C4E5F6-A7B8-9012-CDEF-123456789013">
|
||||
<File Id="http.lua" Source="pkg\lua\socket\http.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="SocketTp" Guid="D3C4E5F6-A7B8-9012-CDEF-123456789014">
|
||||
<File Id="tp.lua" Source="pkg\lua\socket\tp.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
<Component Id="SocketUrl" Guid="D3C4E5F6-A7B8-9012-CDEF-123456789015">
|
||||
<File Id="url.lua" Source="pkg\lua\socket\url.lua" KeyPath="yes" />
|
||||
</Component>
|
||||
</DirectoryRef>
|
||||
|
||||
<DirectoryRef Id="MIME_DIR">
|
||||
<Component Id="MimeCoreDll" Guid="E4D5F6A7-B8C9-0123-DEFA-234567890120">
|
||||
<File Id="mime_core.dll" Name="core.dll" Source="pkg\lua\mime\core.dll" KeyPath="yes" />
|
||||
</Component>
|
||||
</DirectoryRef>
|
||||
|
||||
<Feature Id="MainFeature" Title="lmcp Server" Level="1">
|
||||
<ComponentRef Id="JsonLua" />
|
||||
<ComponentRef Id="LmcpLua" />
|
||||
<ComponentRef Id="ServerLua" />
|
||||
<ComponentRef Id="StartBat" />
|
||||
<ComponentRef Id="InstallService" />
|
||||
<ComponentRef Id="LuaExe" />
|
||||
<ComponentRef Id="LuaDll" />
|
||||
<ComponentRef Id="SocketLua" />
|
||||
<ComponentRef Id="MimeLua" />
|
||||
<ComponentRef Id="Ltn12Lua" />
|
||||
<ComponentRef Id="SocketCoreDll" />
|
||||
<ComponentRef Id="SocketFtp" />
|
||||
<ComponentRef Id="SocketHeaders" />
|
||||
<ComponentRef Id="SocketHttp" />
|
||||
<ComponentRef Id="SocketTp" />
|
||||
<ComponentRef Id="SocketUrl" />
|
||||
<ComponentRef Id="MimeCoreDll" />
|
||||
</Feature>
|
||||
|
||||
</Product>
|
||||
</Wix>
|
||||
@@ -0,0 +1,24 @@
|
||||
@echo off
|
||||
REM Install lmcp as a Windows service using NSSM (Non-Sucking Service Manager)
|
||||
REM Download nssm from https://nssm.cc if not present
|
||||
|
||||
if not exist "%~dp0nssm.exe" (
|
||||
echo ERROR: nssm.exe not found in %~dp0
|
||||
echo Download from https://nssm.cc and place nssm.exe here.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set INSTALL_DIR=%~dp0
|
||||
set SERVICE_NAME=lmcp
|
||||
|
||||
echo Installing lmcp as Windows service...
|
||||
%INSTALL_DIR%nssm.exe install %SERVICE_NAME% "%INSTALL_DIR%lua\lua.exe" "%INSTALL_DIR%server.lua"
|
||||
%INSTALL_DIR%nssm.exe set %SERVICE_NAME% AppDirectory "%INSTALL_DIR%"
|
||||
%INSTALL_DIR%nssm.exe set %SERVICE_NAME% AppEnvironmentExtra "LMCP_PORT=8080"
|
||||
%INSTALL_DIR%nssm.exe set %SERVICE_NAME% DisplayName "lmcp MCP Server"
|
||||
%INSTALL_DIR%nssm.exe set %SERVICE_NAME% Description "Lightweight MCP server in Lua"
|
||||
%INSTALL_DIR%nssm.exe set %SERVICE_NAME% Start SERVICE_AUTO_START
|
||||
%INSTALL_DIR%nssm.exe start %SERVICE_NAME%
|
||||
|
||||
echo Done. Service '%SERVICE_NAME%' installed and started.
|
||||
echo Check: sc query %SERVICE_NAME%
|
||||
@@ -0,0 +1,7 @@
|
||||
@echo off
|
||||
REM lmcp — Lua MCP Server
|
||||
REM Start the server on port 8080 (or LMCP_PORT if set)
|
||||
cd /d "%~dp0"
|
||||
if not defined LMCP_PORT set LMCP_PORT=8080
|
||||
echo Starting lmcp on port %LMCP_PORT%...
|
||||
lua\lua.exe server.lua
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
# windows/sync.sh — refresh windows/pkg/ from root .lua sources (issue #18).
|
||||
#
|
||||
# Run BEFORE invoking the WiX build so the MSI bundles whatever is in
|
||||
# master. The .lua files in windows/pkg/ are regenerated on every run
|
||||
# and are gitignored — never edit them directly.
|
||||
#
|
||||
# Idempotent: re-running just re-copies. Safe to call from a Makefile,
|
||||
# a CI step, or by hand before `candle.exe + light.exe`.
|
||||
|
||||
set -eu
|
||||
|
||||
here=$(dirname "$(readlink -f "$0")")
|
||||
root=$(cd "$here/.." && pwd)
|
||||
|
||||
for f in lmcp.lua server.lua json.lua; do
|
||||
if [ ! -f "$root/$f" ]; then
|
||||
echo "windows/sync.sh: missing source $root/$f" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$root/$f" "$here/pkg/$f"
|
||||
echo " synced $f"
|
||||
done
|
||||
|
||||
echo "windows/sync.sh: done — pkg/ matches root .lua at $(date +%Y-%m-%dT%H:%M:%S)"
|
||||
Reference in New Issue
Block a user