summaryrefslogtreecommitdiff
path: root/catalog.lua
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-11-27 08:46:14 -0700
committert <t@tjp.lol>2026-11-30 08:34:38 -0700
commit47039f21a170e29875a2676f7a2eb5a779144b74 (patch)
tree495ffa7dab8de455a8d2ebfafd45dfcce5da52b7 /catalog.lua
Add Antigravity ACP provider for Panto
Diffstat (limited to 'catalog.lua')
-rw-r--r--catalog.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/catalog.lua b/catalog.lua
new file mode 100644
index 0000000..ef10bdf
--- /dev/null
+++ b/catalog.lua
@@ -0,0 +1,46 @@
+local json = require('panto').ext.json
+local M = {}
+function M.catalog(req, names)
+ local all, by, list = {}, {}, json.array({})
+ for _,t in ipairs(req.tools) do all[t.name]=t end
+ if names==nil then
+ names={}; for name in pairs(all) do names[#names+1]=name end; table.sort(names)
+ end
+ for i,name in ipairs(names) do
+ local t=assert(all[name], 'Tool not in active rig: '..name); local s=json.decode(t.input_schema_json)
+ assert(s.type=='object','Expected MCP object input schema for '..name)
+ local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire], 'Invalid or colliding MCP tool name: '..name)
+ by[wire]={name=name,schema=s}; list[i]={name=wire,description=t.description,inputSchema=s}
+ end
+ return by,list
+end
+
+-- Advertise the exact extension schema. Reject unsupported assertions on use,
+-- rather than dropping constraints or preventing unrelated tools from loading.
+local known={type=true,properties=true,required=true,additionalProperties=true,items=true,minItems=true,maxItems=true,
+ enum=true,minimum=true,maximum=true,description=true,title=true,default=true,examples=true,['$schema']=true}
+local array_mt=getmetatable(json.array({}))
+local function matches(s,v)
+ if type(s)=='boolean' then return s end
+ for k in pairs(s) do if not known[k] then return false,'Unsupported schema keyword: '..k end end
+ local kind=type(v)
+ if kind=='table' then kind=getmetatable(v)==array_mt and 'array' or 'object' elseif v==json.null then kind='null' end
+ if s.type and s.type~=kind and not (s.type=='integer' and kind=='number' and v%1==0) then return false end
+ if s.enum then
+ local found=false; for _,x in ipairs(s.enum) do if json.encode(x)==json.encode(v) then found=true; break end end
+ if not found then return false end
+ end
+ if kind=='object' then
+ for _,k in ipairs(s.required or {}) do if v[k]==nil then return false end end
+ for k,x in pairs(v) do
+ local sub=(s.properties or {})[k]; if sub==nil then sub=s.additionalProperties end
+ if sub~=nil then local ok,why=matches(sub,x); if not ok then return false,why end end
+ end
+ elseif kind=='array' then
+ if s.minItems and #v<s.minItems or s.maxItems and #v>s.maxItems then return false end
+ if s.items~=nil then for _,x in ipairs(v) do local ok,why=matches(s.items,x); if not ok then return false,why end end end
+ elseif kind=='number' and (s.minimum and v<s.minimum or s.maximum and v>s.maximum) then return false end
+ return true
+end
+M.arguments=matches
+return M