@malloydata/cli 0.0.55-next.2026.6.9.3c90651 → 0.0.55-next.2026.6.9.e247f30

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/dist/cli.js CHANGED
@@ -4523,7 +4523,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4523
4523
  `+t}async function uq(t){if(t.uri&&t.source||!t.uri&&t.source===void 0)return{ok:!1,problems:[{severity:"error",code:"bad-input",message:"Exactly one of {uri, source} must be provided."}]};let e=t.source!==void 0?p3a(t.source):void 0,r=t.uri?kCi(t.uri):A3a(t.baseUri),{urlReader:n,readSource:i}=d3a(r,e),s=new Xdt.Runtime({config:Oc,urlReader:n});try{let o=await o2(()=>s.loadModel(r).getModel());return{ok:!0,loaded:{model:o,rootUrl:r,runtime:s,readSource:i},problems:cq(o.problems)}}catch(o){return o instanceof Xdt.MalloyError?{ok:!1,problems:cq(o.problems)}:{ok:!1,problems:[bH(o,r.href)]}}}var wyr,LCi,PCi,Xdt,l3a,Zdt=Ie(()=>{"use strict";wyr=ut(require("node:url")),LCi=ut(require("node:fs")),PCi=ut(require("node:path")),Xdt=ut(lc());Lv();oy();Syr();l3a="memory://mcp/"});function _H(t){if(t)return[t.range.start.line,t.range.start.character]}function lq(t){return t?t.forRoute().map(e=>({route:e.route,text:e.content})):[]}function ERe(t,e){return!!t&&t.url===e}function vyr(t,e){if(!t||!e)return;let r=t.split(`
4524
4524
  `),{start:n,end:i}=e.range;if(n.line<0||n.line>=r.length||i.line<0||i.line>=r.length)return;if(n.line===i.line)return r[n.line].slice(n.character,i.character);let s=[r[n.line].slice(n.character)];for(let o=n.line+1;o<i.line;o++)s.push(r[o]);return s.push(r[i.line].slice(0,i.character)),s.join(`
4525
4525
  `)}function h3a(t){let e=t.structDef.join;return e==="one"||e==="many"||e==="cross"?e:"one"}function FCi(t){let e=t.structDef;return e.type==="array"&&e.elementTypeDef?.type!=="record_element"}function g3a(t){let e=t.structDef;return e.type==="array"&&e.elementTypeDef?.type==="record_element"}function m3a(t){return t.structDef.type==="record"}function E3a(t,e){return FCi(t)?e.filter(r=>r.name!=="value"):e}function C3a(t,e){let n=e.find(i=>i.name===t.name)?.expressionType;return n&&((0,ept.expressionIsAggregate)(n)||(0,ept.expressionIsAnalytic)(n))?"measure":"dimension"}function y3a(t,e){if(FCi(t)||g3a(t)||m3a(t))return;let r=t.structDef;if(r.sourceID){let n=r.sourceID.split("@")[0];if(n&&e.has(n))return n}if(r.name&&e.has(r.name))return r.name;if(e.has(t.name))return t.name}function qCi(t,e,r,n){let i=lq(t.annotations),s=t.location,o=ERe(s,n.rootUri),a={name:t.name,kind:"dimension"};if(i.length>0&&(a.annotations=i),o){let l=_H(s);l&&(a.location=l)}if(t.isExploreField()){let l=t,A=y3a(l,n.knownSources);if(a.kind="join",a.relationship=h3a(l),A&&(a.source_ref=A),(n.opts.expand==="inline"||!A)&&r<f3a){let f=l.structDef.fields??[],h=[];for(let g of l.allFields)h.push(qCi(g,f,r+1,n));a.fields=E3a(l,h)}return a}if(t.isQueryField()){let l=t;a.kind="view";let A=l.expression||void 0;if(A&&A!==t.name&&(a.expression=A),o&&s){let p=n.readSource(s.url),f=vyr(p,s);f&&(a.body=f)}return a}let c=t;a.kind=C3a(c,e),a.type=c.type;let u=c.expression||void 0;return u&&u!==t.name&&(a.expression=u),a}function I3a(t,e){let r=[],n=[],i=[],s=[],o=t.structDef.fields??[];for(let l of t.allFields){let A=qCi(l,o,0,e);switch(A.kind){case"dimension":r.push(A);break;case"measure":n.push(A);break;case"view":i.push(A);break;case"join":s.push(A);break}}let a=lq(t.annotations),c={name:t.name,dimensions:r,measures:n,views:i,joins:s};a.length>0&&(c.annotations=a);let u=_H(t.location);return u&&(c.location=u),t.primaryKey&&(c.primaryKey=t.primaryKey),c}function UCi(t){if(t.type==="filter expression")return t.filterType?`filter<${t.filterType}>`:"filter";if(t.type==="array"){let e=t.elementTypeDef;return e?e.type==="record_element"?"record[]":`${UCi(e)}[]`:"array"}return t.type}function b3a(t,e,r){let n={name:e,type:UCi(t.type),hasDefault:t.default!==void 0},i=lq(t.annotations);i.length>0&&(n.annotations=i);let s=t.location;if(s&&ERe(s,r.rootUri)){let o=_H(s);o&&(n.location=o);let a=vyr(r.readSource(s.url),s);a&&(n.body=a)}return n}function Tyr(t){try{return[...t().givens.keys()]}catch{return[]}}async function _3a(t,e,r,n){let i=t.queries(),s=new Set([...t.explores.map(f=>f.name),...i.named]),o={rootUri:e,knownSources:s,opts:n,readSource:r},a=[];for(let f of t.explores)ERe(f.location,e)&&a.push(I3a(f,o));let c=[];for(let f of i.named){let h=t.getPreparedQueryByName(f),g=h.location;if(!ERe(g,e))continue;let E={name:f},C=lq(h.annotations);C.length>0&&(E.annotations=C);let y=_H(g);y&&(E.location=y);let b=vyr(r(e),g);b&&(E.body=b);let O=Tyr(()=>h);O.length>0&&(E.givens=O),c.push(E)}let u=[];for(let f=0;f<i.unnamed;f++){let h=t.getPreparedQueryByIndex(f),g={index:f},E=lq(h.annotations);E.length>0&&(g.annotations=E);let C=_H(h.location);C&&(g.location=C);try{let y=[...h.givens.keys()];y.length>0&&(g.givens=y),n.emitRunSql&&(g.sql=h.preparedResult.sql.trim())}catch(y){n.emitRunSql&&(g.error=y instanceof Error?y.message:String(y))}u.push(g)}let l=[];for(let[f,h]of t.givens)l.push(b3a(h,f,o));let A=lq(t.annotations),p={rootUri:e,sources:a,queries:c,runs:u};return A.length>0&&(p.annotations=A),l.length>0&&(p.givens=l),p}async function CRe(t,e={}){let r=await uq(t);if(!r.ok||!r.loaded)return{ok:!1,problems:r.problems};let{model:n,rootUrl:i,readSource:s}=r.loaded;try{return{ok:!0,model:await _3a(n,i.href,s,{expand:e.expand??"ref",emitRunSql:e.emitRunSql??!1}),problems:r.problems}}catch(o){return{ok:!1,problems:[...r.problems,bH(o,i.href)]}}}async function GCi(t){let e=await uq(t);if(!e.ok||!e.loaded)return{ok:!1,runs:[],queries:[],problems:e.problems};let{model:r,rootUrl:n}=e.loaded,i=r.queries(),s=Array.from({length:i.unnamed},(a,c)=>{let u=r.getPreparedQueryByIndex(c),l={index:c},A=_H(u.location);A&&(l.location=A);let p=lq(u.annotations);p.length>0&&(l.annotations=p);let f=Tyr(()=>u);return f.length>0&&(l.givens=f),l}),o=i.named.map(a=>{let c=r.getPreparedQueryByName(a),u=c.location;return{pq:c,queryName:a,loc:u}}).filter(({loc:a})=>ERe(a,n.href)).map(({pq:a,queryName:c,loc:u})=>{let l={name:c},A=_H(u);A&&(l.location=A);let p=lq(a.annotations);p.length>0&&(l.annotations=p);let f=Tyr(()=>a);return f.length>0&&(l.givens=f),l});return{ok:!0,rootUri:n.href,runs:s,queries:o,problems:e.problems}}var ept,f3a,Dyr=Ie(()=>{"use strict";ept=ut(lc());Zdt();f3a=4});async function Nyr(t,e={}){let r=await uq(t);if(!r.ok||!r.loaded)return{ok:!1,problems:r.problems.map(u=>WCi(u,t))};let{model:n,rootUrl:i,runtime:s}=r.loaded,o=n.queries(),a=s.loadModel(i),c;if(e.name){if(!o.named.includes(e.name)){let u={queries:o.named,runs:o.unnamed};return{ok:!1,problems:[{severity:"error",code:"selector-not-found",message:`No query named '${e.name}'. Available: ${JSON.stringify(u)}`,uri:i.href}]}}c=a.loadQueryByName(e.name)}else if(typeof e.index=="number"){if(e.index<0||e.index>=o.unnamed)return{ok:!1,problems:[{severity:"error",code:"selector-out-of-range",message:`Index ${e.index} out of range; file has ${o.unnamed} run: statement(s).`,uri:i.href}]};c=a.loadQueryByIndex(e.index)}else{if(o.unnamed===0)return{ok:!1,problems:[{severity:"error",code:"no-run",message:"Source has no run: statement. Specify a named query via `name`, or add a run: to the source.",uri:i.href}]};c=a.loadFinalQuery()}return Qyr(c,e.rowLimit??Pv,e.givens,r.problems,{nudge:u=>WCi(u,t),uri:i.href})}async function Qyr(t,e,r,n,i={}){let s=r?{givens:r}:void 0;try{let o=Date.now(),a=(await t.getSQL(s)).trim(),c=Date.now(),u=await o2(()=>t.run({rowLimit:e,...s})),l=Date.now(),A=u.toJSON().queryResult.result;return{ok:!0,sql:a,rowCount:A.length,truncated:A.length===e,rows:A,compileTimeMS:c-o,totalTimeMS:l-o,problems:n}}catch(o){let a=i.nudge??(c=>c);return o instanceof HCi.MalloyError?{ok:!1,problems:[...n,...cq(o.problems).map(a)]}:{ok:!1,problems:[...n,bH(o,i.uri)]}}}function WCi(t,e){if(t.code!=="field-not-found")return t;let r=e.uri?`Call compile_file with uri="${e.uri}" to see what fields, measures, views, and joins exist on this source.`:"Call compile on the same source (or compile_file on any imported file) to see what fields, measures, views, and joins exist.";return{...t,message:`${t.message} \u2014 ${r}`,help_topic:t.help_topic??"fields"}}var HCi,zyr=Ie(()=>{"use strict";HCi=ut(lc());Zdt();yU();oy()});function KCi(t){return t.split(/\r?\n/).some(e=>VCi.test(e)||$Ci.test(e))}function x3a(t){let e=t.split(/\r?\n/);for(let r=0;r<e.length;r++){let n=VCi.exec(e[r]);if(n){let s=n[1],o=[];for(let a=r+1;a<e.length;a++){if(/^[ \t]*\|##[ \t]*$/.test(e[a])){let c=o.map(u=>u.startsWith(s)?u.slice(s.length):u).join(`
4526
- `).trim();return c.length>0?c:void 0}o.push(e[a])}return}let i=$Ci.exec(e[r]);if(i){let s=i[1].trim();return s.length>0?s:void 0}}}function X0e(t){return{severity:"error",code:"model-not-found",message:`No published model '${t}'. Models are exposed by carrying the \`##|(mcp-description) \u2026 |##\` marker; call list_models to see what is available.`}}function Lyr(t,e){if(eQ.default.isAbsolute(e)||e.includes("\0"))return{problem:X0e(e)};let r=eQ.default.resolve(t,e),n=eQ.default.relative(t,r);if(n.startsWith("..")||eQ.default.isAbsolute(n))return{problem:X0e(e)};if(n.split(eQ.default.sep).some(ZMt))return{problem:X0e(e)};if(!_de(r)||!tpt.default.existsSync(r))return{problem:X0e(e)};let i;try{i=tpt.default.readFileSync(r,"utf8")}catch{return{problem:X0e(e)}}return KCi(i)?{abs:r}:{problem:X0e(e)}}function YCi(t){let e=[];for(let r of xde(t)){let n;try{n=tpt.default.readFileSync(r,"utf8")}catch{continue}if(!KCi(n))continue;let i=eQ.default.relative(t,r).split(eQ.default.sep).join("/"),s=x3a(n);e.push(s?{handle:i,description:s}:{handle:i})}return e.sort((r,n)=>r.handle.localeCompare(n.handle)),e}async function JCi(t,e,r={}){let n=Lyr(t,e);return"problem"in n?{ok:!1,problems:[n.problem]}:CRe({uri:n.abs},r)}async function XCi(t,e,r){let n=Lyr(t,e);if("problem"in n)return{ok:!1,problems:[n.problem]};let i=await uq({uri:n.abs});if(!i.ok||!i.loaded)return{ok:!1,problems:i.problems};let{runtime:s,rootUrl:o}=i.loaded;try{let a=s.loadModel(o).loadRestrictedQuery(r),c=cq(await a.validate());return{ok:!c.some(l=>l.severity==="error"),problems:[...i.problems,...c]}}catch(a){return a instanceof jCi.MalloyError?{ok:!1,problems:[...i.problems,...cq(a.problems)]}:{ok:!1,problems:[...i.problems,bH(a)]}}}async function ZCi(t,e,r,n={}){let i=Lyr(t,e);if("problem"in i)return{ok:!1,problems:[i.problem]};let s=await uq({uri:i.abs});if(!s.ok||!s.loaded)return{ok:!1,problems:s.problems};let{runtime:o,rootUrl:a}=s.loaded,c=o.loadModel(a).loadRestrictedQuery(r);return Qyr(c,n.rowLimit??Pv,n.givens,s.problems)}function eyi(t){if(!t)throw new Error("Restricted MCP mode (--restricted) requires a project directory: pass -p DIR to scope which models are exposed.");return eQ.default.resolve(t)}var tpt,eQ,jCi,VCi,$Ci,tyi=Ie(()=>{"use strict";tpt=ut(require("node:fs")),eQ=ut(require("node:path")),jCi=ut(lc());Zdt();Dyr();zyr();yU();oy();VCi=/^([ \t]*)##\|\(mcp-description\)[ \t]*$/,$Ci=/^[ \t]*##\(mcp-description\)[ \t]?(.*)$/});function yRe(t){let{result:e,errors:r}=(0,ryi.prettify)(t);return{formatted:e,errors:r}}var ryi,Pyr=Ie(()=>{"use strict";ryi=ut(CX())});var nyi=m((e60,B3a)=>{B3a.exports={name:"@malloydata/cli",version:"0.0.55-next.2026.6.9.3c90651",description:"Malloy CLI",bin:{"malloy-cli":"dist/index.js","malloy-packages":"scripts/malloy-packages.ts"},files:["dist/**","scripts/malloy-packages.ts"],engines:{node:">=20"},pkg:{assets:["node_modules/@duckdb/node-bindings-*/libduckdb.*","node_modules/@duckdb/node-bindings-*/duckdb.dll"]},scripts:{lint:"tsc --noEmit && gts lint",test:"NODE_ENV=test jest --projects jest.config.js --runInBand","test-silent":"NODE_ENV=test JEST_SILENT_REPORTER_SHOW_PATHS=true jest --projects jest.config.js --runInBand --reporters jest-silent-reporter","test-e2e":"npm run package-npm test > /dev/null 2>&1 && NODE_ENV=test jest --projects=jest-e2e.config.js --runInBand","test-silent-e2e":"npm run package-npm test > /dev/null 2>&1 && NODE_ENV=test JEST_SILENT_REPORTER_SHOW_PATHS=true jest --projects=jest-e2e.config.js --runInBand --reporters jest-silent-reporter",build:"ts-node scripts/build","build-action":"esbuild --platform=node --bundle ./.github/actions/permission-check/lib/index.ts --outfile=./.github/actions/permission-check/dist/index.js","build-action-dev":"npm run build-action -- --watch",cli:"npx ts-node ./dist/cli.js",watch:"ts-node scripts/build watch",package:"ts-node scripts/package","package-npm":"ts-node scripts/package-npm","npm-publish":"ts-node scripts/npm-publish",postpack:"npm run build","malloy-update-next":"npm install --no-fund --no-audit --save-exact $(./scripts/malloy-packages.ts next) && ts-node scripts/sync-duckdb.ts && npm install --no-fund --no-audit","malloy-update":"npm install --no-fund --no-audit --save-exact $(./scripts/malloy-packages.ts latest) && ts-node scripts/sync-duckdb.ts && npm install --no-fund --no-audit","malloy-link":"npm --no-fund --no-audit link $(./scripts/malloy-packages.ts)","malloy-unlink":"npm --no-fund --no-save --no-audit unlink $(./scripts/malloy-packages.ts) && npm --no-fund --no-audit install --force"},repository:{type:"git",url:"git+https://github.com/malloydata/malloy-cli.git"},author:"Malloy",license:"MIT",bugs:{url:"https://github.com/malloydata/malloy-cli/issues"},homepage:"https://github.com/malloydata/malloy-cli#readme",builtIntoPackageDependencies:["@malloydata/db-bigquery","@malloydata/db-duckdb","@malloydata/db-mysql","@malloydata/db-postgres","@malloydata/db-snowflake","@malloydata/db-presto","@malloydata/db-trino","@malloydata/malloy","@malloydata/malloy-connections","@malloydata/malloy-sql","chalk","commander","logform","winston"],optionalDependencies:{"@duckdb/node-bindings-darwin-arm64":"1.5.3-r.2","@duckdb/node-bindings-darwin-x64":"1.5.3-r.2","@duckdb/node-bindings-linux-arm64":"1.5.3-r.2","@duckdb/node-bindings-linux-arm64-musl":"1.5.3-r.2","@duckdb/node-bindings-linux-x64":"1.5.3-r.2","@duckdb/node-bindings-linux-x64-musl":"1.5.3-r.2","@duckdb/node-bindings-win32-arm64":"1.5.3-r.2","@duckdb/node-bindings-win32-x64":"1.5.3-r.2"},devDependencies:{"@actions/core":"^1.11.1","@actions/github":"^6.0.0","@commander-js/extra-typings":"^12.1.0","@duckdb/node-api":"1.5.3-r.2","@duckdb/node-bindings":"1.5.3-r.2","@malloydata/db-bigquery":"0.0.405","@malloydata/db-duckdb":"0.0.405","@malloydata/db-postgres":"0.0.405","@malloydata/db-snowflake":"0.0.405","@malloydata/db-trino":"0.0.405","@malloydata/malloy":"0.0.405","@malloydata/malloy-connections":"0.0.405","@malloydata/malloy-sql":"0.0.405","@types/jest":"^29.2.5","@types/node":"^20.14.8","@typescript-eslint/eslint-plugin":"^5.48.2","@typescript-eslint/parser":"^5.48.2","@yao-pkg/pkg":"^6.20.0",ajv:"^8.12.0",axios:"^1.4.0",chalk:"^4.0.0",commander:"^12.1.0","csv-stringify":"^6.4.0",esbuild:"0.28.0",eslint:"^8.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^3.4.0",gts:"^3.1.1",jest:"^29.3.1","jest-silent-reporter":"^0.6.0",logform:"^2.5.1","ts-jest":"^29.1.0","ts-node":"^10.9.1",typescript:"^5.9.3",winston:"^3.9.0"},dependencies:{"@modelcontextprotocol/sdk":"^1.29.0",zod:"^4.3.6"}}});function TI(t){let e={...t};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:e}}async function Aq(){await Oc.shutdown("idle")}function S3a(t){t.registerTool("prettify",{title:"Pretty-print Malloy source",description:"Reformat a Malloy source string. Returns the formatted source and any parse errors (lexer + parser only \u2014 semantic errors are not checked here; use `compile` for that). When `errors` is non-empty the formatted output is best-effort and may not round-trip; fix the parse errors first. Useful for cleaning up freshly-authored or machine-generated Malloy before saving.",inputSchema:{source:Gyr}},async({source:r})=>TI(yRe(r))),t.registerTool("language_help",{title:"Malloy language reference (by topic)",description:"Look up a section of the Malloy language reference by topic slug or title. Call this before guessing syntax \u2014 especially for pipelines, reduction vs projection, aggregate locality, calculations/window functions, filtered aggregates, pick expressions, time ranges, tags/annotations. Also call this after any compile error whose fix is not obvious from the message \u2014 problems[] entries carry a `help_topic` field when there's a natural match. Call with no topic to list the available topics.",inputSchema:{topic:xh.string().optional().describe("Topic slug or title to look up (case-insensitive; substrings match). Omit to list all available topics.")}},async({topic:r})=>{if(!r)return TI({topics:Ryr()});let n=QCi(r);return TI(n?{slug:n.slug,title:n.title,body:n.body}:{error:`No topic matches '${r}'.`,topics:Ryr()})});let e=vCi(Jdt());for(let r of e)t.registerPrompt(r.name,{title:r.name,description:r.description},()=>({messages:[{role:"user",content:{type:"text",text:r.body}}]})),t.registerResource(r.name,`malloy-skill://${r.name}`,{title:r.name,description:r.description,mimeType:"text/markdown"},async n=>({contents:[{uri:n.href,mimeType:"text/markdown",text:r.body}]}))}function w3a(t){t.registerTool("compile_file",{title:"Inspect a Malloy file (compile)",description:"PREFER THIS OVER READING A .malloy FILE AS TEXT. Compile a .malloy file at the given URI and return the full structured model: sources (with dimensions, measures, views, joins), named queries, top-level run: statements with their SQL, givens (model-level parameters declared with `given:`), and annotations. Each query/run carries the transitive set of given names it references \u2014 the values a caller must supply to execute it. This is the primary way to understand what is in a .malloy file \u2014 what data sources it defines, what can be queried, what the schema looks like \u2014 whether you are about to edit it, answer a question with it, or just explore it. Reading the file as text shows you syntax; compiling it shows you semantics. Joins to named sources render by reference via `source_ref` (look up the referenced source by name in the same response); pass `expand: 'inline'` to get recursive inlined fields instead.",inputSchema:{uri:kyr,expand:qyr,emit_run_sql:Uyr}},async({uri:e,expand:r,emit_run_sql:n})=>{let i=await CRe({uri:e},{expand:r,emitRunSql:n});return await Aq(),TI(i)}),t.registerTool("compile",{title:"Compile an inline Malloy source string",description:'Compile a Malloy source string (not backed by a file). Same output shape as compile_file. Use this when drafting new Malloy \u2014 the common pattern is `import "file.malloy"` + a new `run: ...`, which you iterate on against the `problems[]` feedback until clean. The compiler is ground truth; do not guess syntax. When in doubt about what fields / measures / views exist in the imported file, call compile_file on it first.',inputSchema:{source:Gyr,base_uri:iyi,expand:qyr,emit_run_sql:Uyr}},async({source:e,base_uri:r,expand:n,emit_run_sql:i})=>{let s=await CRe({source:e,baseUri:r},{expand:n,emitRunSql:i});return await Aq(),TI(s)}),t.registerTool("run_file",{title:"Execute a run: from a Malloy file",description:"Execute one run: or named query from a .malloy file against the user's configured connections. Selection: `name` wins if provided, else `index` (0-based into run: statements), else the final run:. Returns the generated SQL and rows (default 10000, set row_limit to override). If the run/query references givens (model-level parameters \u2014 see `compile_file` output), supply per-call values via the `givens` map.",inputSchema:{uri:kyr,name:xh.string().optional().describe("Name of a `query:` definition to execute. Wins over `index`."),index:xh.number().int().optional().describe("0-based index into run: statements."),row_limit:Wyr,givens:Hyr}},async({uri:e,name:r,index:n,row_limit:i,givens:s})=>{let o=await Nyr({uri:e},{name:r,index:n,rowLimit:i,givens:s});return await Aq(),TI(o)}),t.registerTool("run",{title:"Execute inline Malloy source",description:"Compile an inline Malloy source and execute its final run: statement against the user's configured connections. Returns the generated SQL and rows (default 10000, set row_limit to override). If the source declares givens (model-level parameters), supply per-call values via the `givens` map. Use this after compile is clean to see the answer.",inputSchema:{source:Gyr,base_uri:iyi,row_limit:Wyr,givens:Hyr}},async({source:e,base_uri:r,row_limit:n,givens:i})=>{let s=await Nyr({source:e,baseUri:r},{rowLimit:n,givens:i});return await Aq(),TI(s)}),t.registerTool("list_runs",{title:"List runnable queries in a Malloy file",description:"Lightweight discovery: return the runnable run: statements (with optional names and indexes) and named `query:` definitions in a file, without serializing the full model. Each entry also carries the transitive set of given names it references \u2014 the parameters a caller must supply to execute it. Use this when you only need to know what can be executed; if you need the full givens schema (types, defaults, annotations) or any source/field detail, use compile_file instead.",inputSchema:{uri:kyr}},async({uri:e})=>{let r=await GCi({uri:e});return await Aq(),TI(r)})}function T3a(t,e){t.registerTool("list_models",{title:"List published Malloy models",description:"List the models this server exposes. Each entry has a `handle` (pass it as `model` to describe_model / compile / run) and a `description` written by the model author. These are the only models you can query \u2014 you cannot open files by path or import anything else.",inputSchema:{}},async()=>TI({models:YCi(e)})),t.registerTool("describe_model",{title:"Inspect a published model",description:"Return the curated semantic surface of a published model: sources (with dimensions, measures, views, joins), named queries, and givens. Pick `model` from `list_models`. This is how you learn what is queryable before writing a restricted query \u2014 prefer it over guessing field names.",inputSchema:{model:Fyr,expand:qyr,emit_run_sql:Uyr}},async({model:r,expand:n,emit_run_sql:i})=>{let s=await JCi(e,r,{expand:n,emitRunSql:i});return await Aq(),TI(s)}),t.registerTool("compile",{title:"Validate a restricted query against a model",description:"Compile (validate only, no execution) Malloy `query` text against the published `model`. Returns `problems[]`; iterate until clean, then `run`. Forbidden constructs (import, given: declarations, connection.table/sql, name!type(...), the sql_* functions, ##! flags) are rejected with code `restricted-construct-forbidden`.",inputSchema:{model:Fyr,query:syi}},async({model:r,query:n})=>{let i=await XCi(e,r,n);return await Aq(),TI(i)}),t.registerTool("run",{title:"Run a restricted query against a model",description:"Compile `query` against the published `model` in restricted mode and execute it against the operator's configured connections. Returns the generated SQL and rows (default 10000, set row_limit to override). Supply values for any `$NAME` givens the model declares via the `givens` map. Same restrictions as `compile`.",inputSchema:{model:Fyr,query:syi,row_limit:Wyr,givens:Hyr}},async({model:r,query:n,row_limit:i,givens:s})=>{let o=await ZCi(e,r,n,{rowLimit:i,givens:s});return await Aq(),TI(o)})}async function oyi(t={}){let e=t.restricted?eyi(t.projectDir):void 0,r=new $dt({name:"malloy-cli",version:M3a.version??"development"},{instructions:t.restricted?R3a:O3a});e!==void 0?T3a(r,e):w3a(r),S3a(r);let n=new Ydt;await r.connect(n)}var M3a,qyr,Uyr,kyr,Gyr,Wyr,Hyr,iyi,Fyr,syi,O3a,R3a,ayi=Ie(()=>{"use strict";RCi();TCi();byr();Dyr();zyr();tyi();Syr();Byr();Lv();Pyr();M3a=nyi(),qyr=xh.enum(["ref","inline"]).optional().describe("How to render joins in the model output. 'ref' (default) references joined sources by name via `source_ref`. 'inline' recursively inlines the joined source schema (larger output, useful when the client cannot cross-reference)."),Uyr=xh.boolean().optional().describe("If true, compile each run: statement to SQL and include it as `model.runs[].sql`. Default false because run SQL is typically large and is not needed while inspecting the schema. Use run_file to execute a run: and get both SQL and rows."),kyr=xh.string().describe("File URI (file://...) or bare filesystem path. Relative paths resolve against the server's working directory."),Gyr=xh.string().describe("Malloy source code."),Wyr=xh.number().int().optional().describe("Maximum number of rows to return. Defaults to 10000."),Hyr=xh.record(xh.string(),xh.unknown()).optional().describe('Per-query given values, keyed by caller-facing surface name (no `$` prefix). Override the runtime\'s defaults for this call only. Use `compile_file` (or `list_runs`) to see which givens a run/query needs \u2014 each entry carries a `givens` array of the names it references. For per-type JS shapes (date as ISO string, naive timestamp as ISO without offset, record as JS object, filter<T> as Malloy filter source string, ...) call `language_help("givens")` \u2014 the "JS shapes for supplied values" subsection is the canonical reference.'),iyi=xh.string().optional().describe("Optional URI used to resolve relative imports in the inline source. Typically the file:// URI of the file the snippet will live next to. If omitted, imports must be absolute."),Fyr=xh.string().describe('Handle of a published model, as returned by `list_models` (a path relative to the server\'s model root, e.g. "sales/orders.malloy"). You cannot name an arbitrary file \u2014 only published models are reachable.'),syi=xh.string().describe("Malloy query text to compile against the chosen model. May contain `source:` / `query:` / `run:` statements and reference anything the model already defines, plus `$NAME` givens it declared. May NOT use `import`, declare `given:`, call `connection.table(...)` / `connection.sql(...)`, use the `name!type(...)` raw-SQL form or the `sql_*` functions, or set `##!` compiler flags \u2014 those are rejected with code `restricted-construct-forbidden`.");O3a=`
4526
+ `).trim();return c.length>0?c:void 0}o.push(e[a])}return}let i=$Ci.exec(e[r]);if(i){let s=i[1].trim();return s.length>0?s:void 0}}}function X0e(t){return{severity:"error",code:"model-not-found",message:`No published model '${t}'. Models are exposed by carrying the \`##|(mcp-description) \u2026 |##\` marker; call list_models to see what is available.`}}function Lyr(t,e){if(eQ.default.isAbsolute(e)||e.includes("\0"))return{problem:X0e(e)};let r=eQ.default.resolve(t,e),n=eQ.default.relative(t,r);if(n.startsWith("..")||eQ.default.isAbsolute(n))return{problem:X0e(e)};if(n.split(eQ.default.sep).some(ZMt))return{problem:X0e(e)};if(!_de(r)||!tpt.default.existsSync(r))return{problem:X0e(e)};let i;try{i=tpt.default.readFileSync(r,"utf8")}catch{return{problem:X0e(e)}}return KCi(i)?{abs:r}:{problem:X0e(e)}}function YCi(t){let e=[];for(let r of xde(t)){let n;try{n=tpt.default.readFileSync(r,"utf8")}catch{continue}if(!KCi(n))continue;let i=eQ.default.relative(t,r).split(eQ.default.sep).join("/"),s=x3a(n);e.push(s?{handle:i,description:s}:{handle:i})}return e.sort((r,n)=>r.handle.localeCompare(n.handle)),e}async function JCi(t,e,r={}){let n=Lyr(t,e);return"problem"in n?{ok:!1,problems:[n.problem]}:CRe({uri:n.abs},r)}async function XCi(t,e,r){let n=Lyr(t,e);if("problem"in n)return{ok:!1,problems:[n.problem]};let i=await uq({uri:n.abs});if(!i.ok||!i.loaded)return{ok:!1,problems:i.problems};let{runtime:s,rootUrl:o}=i.loaded;try{let a=s.loadModel(o).loadRestrictedQuery(r),c=cq(await a.validate());return{ok:!c.some(l=>l.severity==="error"),problems:[...i.problems,...c]}}catch(a){return a instanceof jCi.MalloyError?{ok:!1,problems:[...i.problems,...cq(a.problems)]}:{ok:!1,problems:[...i.problems,bH(a)]}}}async function ZCi(t,e,r,n={}){let i=Lyr(t,e);if("problem"in i)return{ok:!1,problems:[i.problem]};let s=await uq({uri:i.abs});if(!s.ok||!s.loaded)return{ok:!1,problems:s.problems};let{runtime:o,rootUrl:a}=s.loaded,c=o.loadModel(a).loadRestrictedQuery(r);return Qyr(c,n.rowLimit??Pv,n.givens,s.problems)}function eyi(t){if(!t)throw new Error("Restricted MCP mode (--restricted) requires a project directory: pass -p DIR to scope which models are exposed.");return eQ.default.resolve(t)}var tpt,eQ,jCi,VCi,$Ci,tyi=Ie(()=>{"use strict";tpt=ut(require("node:fs")),eQ=ut(require("node:path")),jCi=ut(lc());Zdt();Dyr();zyr();yU();oy();VCi=/^([ \t]*)##\|\(mcp-description\)[ \t]*$/,$Ci=/^[ \t]*##\(mcp-description\)[ \t]?(.*)$/});function yRe(t){let{result:e,errors:r}=(0,ryi.prettify)(t);return{formatted:e,errors:r}}var ryi,Pyr=Ie(()=>{"use strict";ryi=ut(CX())});var nyi=m((e60,B3a)=>{B3a.exports={name:"@malloydata/cli",version:"0.0.55-next.2026.6.9.e247f30",description:"Malloy CLI",bin:{"malloy-cli":"dist/index.js","malloy-packages":"scripts/malloy-packages.ts"},files:["dist/**","scripts/malloy-packages.ts"],engines:{node:">=20"},pkg:{assets:["node_modules/@duckdb/node-bindings-*/libduckdb.*","node_modules/@duckdb/node-bindings-*/duckdb.dll"]},scripts:{lint:"tsc --noEmit && gts lint",test:"NODE_ENV=test jest --projects jest.config.js --runInBand","test-silent":"NODE_ENV=test JEST_SILENT_REPORTER_SHOW_PATHS=true jest --projects jest.config.js --runInBand --reporters jest-silent-reporter","test-e2e":"npm run package-npm test > /dev/null 2>&1 && NODE_ENV=test jest --projects=jest-e2e.config.js --runInBand","test-silent-e2e":"npm run package-npm test > /dev/null 2>&1 && NODE_ENV=test JEST_SILENT_REPORTER_SHOW_PATHS=true jest --projects=jest-e2e.config.js --runInBand --reporters jest-silent-reporter",build:"ts-node scripts/build","build-action":"esbuild --platform=node --bundle ./.github/actions/permission-check/lib/index.ts --outfile=./.github/actions/permission-check/dist/index.js","build-action-dev":"npm run build-action -- --watch",cli:"npx ts-node ./dist/cli.js",watch:"ts-node scripts/build watch",package:"ts-node scripts/package","package-npm":"ts-node scripts/package-npm","npm-publish":"ts-node scripts/npm-publish",postpack:"npm run build","malloy-update-next":"npm install --no-fund --no-audit --save-exact $(./scripts/malloy-packages.ts next) && ts-node scripts/sync-duckdb.ts && npm install --no-fund --no-audit","malloy-update":"npm install --no-fund --no-audit --save-exact $(./scripts/malloy-packages.ts latest) && ts-node scripts/sync-duckdb.ts && npm install --no-fund --no-audit","malloy-link":"npm --no-fund --no-audit link $(./scripts/malloy-packages.ts)","malloy-unlink":"npm --no-fund --no-save --no-audit unlink $(./scripts/malloy-packages.ts) && npm --no-fund --no-audit install --force"},repository:{type:"git",url:"git+https://github.com/malloydata/malloy-cli.git"},author:"Malloy",license:"MIT",bugs:{url:"https://github.com/malloydata/malloy-cli/issues"},homepage:"https://github.com/malloydata/malloy-cli#readme",builtIntoPackageDependencies:["@malloydata/db-bigquery","@malloydata/db-duckdb","@malloydata/db-mysql","@malloydata/db-postgres","@malloydata/db-snowflake","@malloydata/db-presto","@malloydata/db-trino","@malloydata/malloy","@malloydata/malloy-connections","@malloydata/malloy-sql","chalk","commander","logform","winston"],optionalDependencies:{"@duckdb/node-bindings-darwin-arm64":"1.5.3-r.2","@duckdb/node-bindings-darwin-x64":"1.5.3-r.2","@duckdb/node-bindings-linux-arm64":"1.5.3-r.2","@duckdb/node-bindings-linux-arm64-musl":"1.5.3-r.2","@duckdb/node-bindings-linux-x64":"1.5.3-r.2","@duckdb/node-bindings-linux-x64-musl":"1.5.3-r.2","@duckdb/node-bindings-win32-arm64":"1.5.3-r.2","@duckdb/node-bindings-win32-x64":"1.5.3-r.2"},devDependencies:{"@actions/core":"^1.11.1","@actions/github":"^6.0.0","@commander-js/extra-typings":"^12.1.0","@duckdb/node-api":"1.5.3-r.2","@duckdb/node-bindings":"1.5.3-r.2","@malloydata/db-bigquery":"0.0.405","@malloydata/db-duckdb":"0.0.405","@malloydata/db-postgres":"0.0.405","@malloydata/db-snowflake":"0.0.405","@malloydata/db-trino":"0.0.405","@malloydata/malloy":"0.0.405","@malloydata/malloy-connections":"0.0.405","@malloydata/malloy-sql":"0.0.405","@types/jest":"^29.2.5","@types/node":"^20.14.8","@typescript-eslint/eslint-plugin":"^5.48.2","@typescript-eslint/parser":"^5.48.2","@yao-pkg/pkg":"^6.20.0",ajv:"^8.12.0",axios:"^1.4.0",chalk:"^4.0.0",commander:"^12.1.0","csv-stringify":"^6.4.0",esbuild:"0.28.0",eslint:"^8.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^3.4.0",gts:"^3.1.1",jest:"^29.3.1","jest-silent-reporter":"^0.6.0",logform:"^2.5.1","ts-jest":"^29.1.0","ts-node":"^10.9.1",typescript:"^5.9.3",winston:"^3.9.0"},dependencies:{"@modelcontextprotocol/sdk":"^1.29.0",zod:"^4.3.6"}}});function TI(t){let e={...t};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:e}}async function Aq(){await Oc.shutdown("idle")}function S3a(t){t.registerTool("prettify",{title:"Pretty-print Malloy source",description:"Reformat a Malloy source string. Returns the formatted source and any parse errors (lexer + parser only \u2014 semantic errors are not checked here; use `compile` for that). When `errors` is non-empty the formatted output is best-effort and may not round-trip; fix the parse errors first. Useful for cleaning up freshly-authored or machine-generated Malloy before saving.",inputSchema:{source:Gyr}},async({source:r})=>TI(yRe(r))),t.registerTool("language_help",{title:"Malloy language reference (by topic)",description:"Look up a section of the Malloy language reference by topic slug or title. Call this before guessing syntax \u2014 especially for pipelines, reduction vs projection, aggregate locality, calculations/window functions, filtered aggregates, pick expressions, time ranges, tags/annotations. Also call this after any compile error whose fix is not obvious from the message \u2014 problems[] entries carry a `help_topic` field when there's a natural match. Call with no topic to list the available topics.",inputSchema:{topic:xh.string().optional().describe("Topic slug or title to look up (case-insensitive; substrings match). Omit to list all available topics.")}},async({topic:r})=>{if(!r)return TI({topics:Ryr()});let n=QCi(r);return TI(n?{slug:n.slug,title:n.title,body:n.body}:{error:`No topic matches '${r}'.`,topics:Ryr()})});let e=vCi(Jdt());for(let r of e)t.registerPrompt(r.name,{title:r.name,description:r.description},()=>({messages:[{role:"user",content:{type:"text",text:r.body}}]})),t.registerResource(r.name,`malloy-skill://${r.name}`,{title:r.name,description:r.description,mimeType:"text/markdown"},async n=>({contents:[{uri:n.href,mimeType:"text/markdown",text:r.body}]}))}function w3a(t){t.registerTool("compile_file",{title:"Inspect a Malloy file (compile)",description:"PREFER THIS OVER READING A .malloy FILE AS TEXT. Compile a .malloy file at the given URI and return the full structured model: sources (with dimensions, measures, views, joins), named queries, top-level run: statements with their SQL, givens (model-level parameters declared with `given:`), and annotations. Each query/run carries the transitive set of given names it references \u2014 the values a caller must supply to execute it. This is the primary way to understand what is in a .malloy file \u2014 what data sources it defines, what can be queried, what the schema looks like \u2014 whether you are about to edit it, answer a question with it, or just explore it. Reading the file as text shows you syntax; compiling it shows you semantics. Joins to named sources render by reference via `source_ref` (look up the referenced source by name in the same response); pass `expand: 'inline'` to get recursive inlined fields instead.",inputSchema:{uri:kyr,expand:qyr,emit_run_sql:Uyr}},async({uri:e,expand:r,emit_run_sql:n})=>{let i=await CRe({uri:e},{expand:r,emitRunSql:n});return await Aq(),TI(i)}),t.registerTool("compile",{title:"Compile an inline Malloy source string",description:'Compile a Malloy source string (not backed by a file). Same output shape as compile_file. Use this when drafting new Malloy \u2014 the common pattern is `import "file.malloy"` + a new `run: ...`, which you iterate on against the `problems[]` feedback until clean. The compiler is ground truth; do not guess syntax. When in doubt about what fields / measures / views exist in the imported file, call compile_file on it first.',inputSchema:{source:Gyr,base_uri:iyi,expand:qyr,emit_run_sql:Uyr}},async({source:e,base_uri:r,expand:n,emit_run_sql:i})=>{let s=await CRe({source:e,baseUri:r},{expand:n,emitRunSql:i});return await Aq(),TI(s)}),t.registerTool("run_file",{title:"Execute a run: from a Malloy file",description:"Execute one run: or named query from a .malloy file against the user's configured connections. Selection: `name` wins if provided, else `index` (0-based into run: statements), else the final run:. Returns the generated SQL and rows (default 10000, set row_limit to override). If the run/query references givens (model-level parameters \u2014 see `compile_file` output), supply per-call values via the `givens` map.",inputSchema:{uri:kyr,name:xh.string().optional().describe("Name of a `query:` definition to execute. Wins over `index`."),index:xh.number().int().optional().describe("0-based index into run: statements."),row_limit:Wyr,givens:Hyr}},async({uri:e,name:r,index:n,row_limit:i,givens:s})=>{let o=await Nyr({uri:e},{name:r,index:n,rowLimit:i,givens:s});return await Aq(),TI(o)}),t.registerTool("run",{title:"Execute inline Malloy source",description:"Compile an inline Malloy source and execute its final run: statement against the user's configured connections. Returns the generated SQL and rows (default 10000, set row_limit to override). If the source declares givens (model-level parameters), supply per-call values via the `givens` map. Use this after compile is clean to see the answer.",inputSchema:{source:Gyr,base_uri:iyi,row_limit:Wyr,givens:Hyr}},async({source:e,base_uri:r,row_limit:n,givens:i})=>{let s=await Nyr({source:e,baseUri:r},{rowLimit:n,givens:i});return await Aq(),TI(s)}),t.registerTool("list_runs",{title:"List runnable queries in a Malloy file",description:"Lightweight discovery: return the runnable run: statements (with optional names and indexes) and named `query:` definitions in a file, without serializing the full model. Each entry also carries the transitive set of given names it references \u2014 the parameters a caller must supply to execute it. Use this when you only need to know what can be executed; if you need the full givens schema (types, defaults, annotations) or any source/field detail, use compile_file instead.",inputSchema:{uri:kyr}},async({uri:e})=>{let r=await GCi({uri:e});return await Aq(),TI(r)})}function T3a(t,e){t.registerTool("list_models",{title:"List published Malloy models",description:"List the models this server exposes. Each entry has a `handle` (pass it as `model` to describe_model / compile / run) and a `description` written by the model author. These are the only models you can query \u2014 you cannot open files by path or import anything else.",inputSchema:{}},async()=>TI({models:YCi(e)})),t.registerTool("describe_model",{title:"Inspect a published model",description:"Return the curated semantic surface of a published model: sources (with dimensions, measures, views, joins), named queries, and givens. Pick `model` from `list_models`. This is how you learn what is queryable before writing a restricted query \u2014 prefer it over guessing field names.",inputSchema:{model:Fyr,expand:qyr,emit_run_sql:Uyr}},async({model:r,expand:n,emit_run_sql:i})=>{let s=await JCi(e,r,{expand:n,emitRunSql:i});return await Aq(),TI(s)}),t.registerTool("compile",{title:"Validate a restricted query against a model",description:"Compile (validate only, no execution) Malloy `query` text against the published `model`. Returns `problems[]`; iterate until clean, then `run`. Forbidden constructs (import, given: declarations, connection.table/sql, name!type(...), the sql_* functions, ##! flags) are rejected with code `restricted-construct-forbidden`.",inputSchema:{model:Fyr,query:syi}},async({model:r,query:n})=>{let i=await XCi(e,r,n);return await Aq(),TI(i)}),t.registerTool("run",{title:"Run a restricted query against a model",description:"Compile `query` against the published `model` in restricted mode and execute it against the operator's configured connections. Returns the generated SQL and rows (default 10000, set row_limit to override). Supply values for any `$NAME` givens the model declares via the `givens` map. Same restrictions as `compile`.",inputSchema:{model:Fyr,query:syi,row_limit:Wyr,givens:Hyr}},async({model:r,query:n,row_limit:i,givens:s})=>{let o=await ZCi(e,r,n,{rowLimit:i,givens:s});return await Aq(),TI(o)})}async function oyi(t={}){let e=t.restricted?eyi(t.projectDir):void 0,r=new $dt({name:"malloy-cli",version:M3a.version??"development"},{instructions:t.restricted?R3a:O3a});e!==void 0?T3a(r,e):w3a(r),S3a(r);let n=new Ydt;await r.connect(n)}var M3a,qyr,Uyr,kyr,Gyr,Wyr,Hyr,iyi,Fyr,syi,O3a,R3a,ayi=Ie(()=>{"use strict";RCi();TCi();byr();Dyr();zyr();tyi();Syr();Byr();Lv();Pyr();M3a=nyi(),qyr=xh.enum(["ref","inline"]).optional().describe("How to render joins in the model output. 'ref' (default) references joined sources by name via `source_ref`. 'inline' recursively inlines the joined source schema (larger output, useful when the client cannot cross-reference)."),Uyr=xh.boolean().optional().describe("If true, compile each run: statement to SQL and include it as `model.runs[].sql`. Default false because run SQL is typically large and is not needed while inspecting the schema. Use run_file to execute a run: and get both SQL and rows."),kyr=xh.string().describe("File URI (file://...) or bare filesystem path. Relative paths resolve against the server's working directory."),Gyr=xh.string().describe("Malloy source code."),Wyr=xh.number().int().optional().describe("Maximum number of rows to return. Defaults to 10000."),Hyr=xh.record(xh.string(),xh.unknown()).optional().describe('Per-query given values, keyed by caller-facing surface name (no `$` prefix). Override the runtime\'s defaults for this call only. Use `compile_file` (or `list_runs`) to see which givens a run/query needs \u2014 each entry carries a `givens` array of the names it references. For per-type JS shapes (date as ISO string, naive timestamp as ISO without offset, record as JS object, filter<T> as Malloy filter source string, ...) call `language_help("givens")` \u2014 the "JS shapes for supplied values" subsection is the canonical reference.'),iyi=xh.string().optional().describe("Optional URI used to resolve relative imports in the inline source. Typically the file:// URI of the file the snippet will live next to. If omitted, imports must be absolute."),Fyr=xh.string().describe('Handle of a published model, as returned by `list_models` (a path relative to the server\'s model root, e.g. "sales/orders.malloy"). You cannot name an arbitrary file \u2014 only published models are reachable.'),syi=xh.string().describe("Malloy query text to compile against the chosen model. May contain `source:` / `query:` / `run:` statements and reference anything the model already defines, plus `$NAME` givens it declared. May NOT use `import`, declare `given:`, call `connection.table(...)` / `connection.sql(...)`, use the `name!type(...)` raw-SQL form or the `sql_*` functions, or set `##!` compiler flags \u2014 those are rejected with code `restricted-construct-forbidden`.");O3a=`
4527
4527
  This server lets an agent inspect, author, and execute Malloy semantic models.
4528
4528
 
4529
4529
  Malloy (.malloy) files are NOT plain text you should read for comprehension.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- process.MALLOY_CLI_VERSION="0.0.55-next.2026.6.9.3c90651";
2
+ process.MALLOY_CLI_VERSION="0.0.55-next.2026.6.9.e247f30";
3
3
  require('./cli.js')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/cli",
3
- "version": "0.0.55-next.2026.6.9.3c90651",
3
+ "version": "0.0.55-next.2026.6.9.e247f30",
4
4
  "description": "Malloy CLI",
5
5
  "bin": {
6
6
  "malloy-cli": "dist/index.js",