@malloydata/cli 0.0.56-next.2026.6.13.b2270c2 → 0.0.56
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4521,7 +4521,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
4521
4521
|
`+t}async function qF(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?xza(t.source):void 0,r=t.uri?iyi(t.uri):bza(t.baseUri),{urlReader:n,readSource:i}=_za(r,e),s=new lut.Runtime({config:c0,urlReader:n});try{let o=await wE(()=>s.loadModel(r).getModel());return{ok:!0,loaded:{model:o,rootUrl:r,runtime:s,readSource:i},problems:FF(o.problems)}}catch(o){return o instanceof lut.MalloyError?{ok:!1,problems:FF(o.problems)}:{ok:!1,problems:[oj(o,r.href)]}}}var rEr,ryi,nyi,lut,Iza,Aut=X(()=>{"use strict";rEr=vr(require("node:url")),ryi=vr(require("node:fs")),nyi=vr(require("node:path")),lut=vr(jc());Rv();Sy();tEr();Iza="memory://mcp/"});function aj(t){if(t)return[t.range.start.line,t.range.start.character]}function UF(t){return t?t.forRoute().map(e=>({route:e.route,text:e.content})):[]}function Xxe(t,e){return!!t&&t.url===e}function iEr(t,e){if(!t||!e)return;let r=t.split(`
|
|
4522
4522
|
`),{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(`
|
|
4523
4523
|
`)}function Mza(t){let e=t.structDef.join;return e==="one"||e==="many"||e==="cross"?e:"one"}function syi(t){let e=t.structDef;return e.type==="array"&&e.elementTypeDef?.type!=="record_element"}function Oza(t){let e=t.structDef;return e.type==="array"&&e.elementTypeDef?.type==="record_element"}function wza(t){return t.structDef.type==="record"}function Rza(t,e){return syi(t)?e.filter(r=>r.name!=="value"):e}function Sza(t,e){let n=e.find(i=>i.name===t.name)?.expressionType;return n&&((0,dut.expressionIsAggregate)(n)||(0,dut.expressionIsAnalytic)(n))?"measure":"dimension"}function Tza(t,e){if(syi(t)||Oza(t)||wza(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 oyi(t,e,r,n){let i=UF(t.annotations),s=t.location,o=Xxe(s,n.rootUri),a={name:t.name,kind:"dimension"};if(i.length>0&&(a.annotations=i),o){let l=aj(s);l&&(a.location=l)}if(t.isExploreField()){let l=t,A=Tza(l,n.knownSources);if(a.kind="join",a.relationship=Mza(l),A&&(a.source_ref=A),(n.opts.expand==="inline"||!A)&&r<Bza){let f=l.structDef.fields??[],h=[];for(let g of l.allFields)h.push(oyi(g,f,r+1,n));a.fields=Rza(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=iEr(p,s);f&&(a.body=f)}return a}let c=t;a.kind=Sza(c,e),a.type=c.type;let u=c.expression||void 0;return u&&u!==t.name&&(a.expression=u),a}function vza(t,e){let r=[],n=[],i=[],s=[],o=t.structDef.fields??[];for(let l of t.allFields){let A=oyi(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=UF(t.annotations),c={name:t.name,dimensions:r,measures:n,views:i,joins:s};a.length>0&&(c.annotations=a);let u=aj(t.location);return u&&(c.location=u),t.primaryKey&&(c.primaryKey=t.primaryKey),c}function ayi(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[]":`${ayi(e)}[]`:"array"}return t.type}function Dza(t,e,r){let n={name:e,type:ayi(t.type),hasDefault:t.default!==void 0},i=UF(t.annotations);i.length>0&&(n.annotations=i);let s=t.location;if(s&&Xxe(s,r.rootUri)){let o=aj(s);o&&(n.location=o);let a=iEr(r.readSource(s.url),s);a&&(n.body=a)}return n}function nEr(t){try{return[...t().givens.keys()]}catch{return[]}}async function Nza(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)Xxe(f.location,e)&&a.push(vza(f,o));let c=[];for(let f of i.named){let h=t.getPreparedQueryByName(f),g=h.location;if(!Xxe(g,e))continue;let E={name:f},y=UF(h.annotations);y.length>0&&(E.annotations=y);let I=aj(g);I&&(E.location=I);let _=iEr(r(e),g);_&&(E.body=_);let R=nEr(()=>h);R.length>0&&(E.givens=R),c.push(E)}let u=[];for(let f=0;f<i.unnamed;f++){let h=t.getPreparedQueryByIndex(f),g={index:f},E=UF(h.annotations);E.length>0&&(g.annotations=E);let y=aj(h.location);y&&(g.location=y);try{let I=[...h.givens.keys()];I.length>0&&(g.givens=I),n.emitRunSql&&(g.sql=h.preparedResult.sql.trim())}catch(I){n.emitRunSql&&(g.error=I instanceof Error?I.message:String(I))}u.push(g)}let l=[];for(let[f,h]of t.givens)l.push(Dza(h,f,o));let A=UF(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 Zxe(t,e={}){let r=await qF(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 Nza(n,i.href,s,{expand:e.expand??"ref",emitRunSql:e.emitRunSql??!1}),problems:r.problems}}catch(o){return{ok:!1,problems:[...r.problems,oj(o,i.href)]}}}async function cyi(t){let e=await qF(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=aj(u.location);A&&(l.location=A);let p=UF(u.annotations);p.length>0&&(l.annotations=p);let f=nEr(()=>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})=>Xxe(a,n.href)).map(({pq:a,queryName:c,loc:u})=>{let l={name:c},A=aj(u);A&&(l.location=A);let p=UF(a.annotations);p.length>0&&(l.annotations=p);let f=nEr(()=>a);return f.length>0&&(l.givens=f),l});return{ok:!0,rootUri:n.href,runs:s,queries:o,problems:e.problems}}var dut,Bza,sEr=X(()=>{"use strict";dut=vr(jc());Aut();Bza=4});async function oEr(t,e={}){let r=await qF(t);if(!r.ok||!r.loaded)return{ok:!1,problems:r.problems.map(u=>uyi(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 aEr(c,e.rowLimit??Sv,e.givens,r.problems,{nudge:u=>uyi(u,t),uri:i.href})}async function aEr(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 wE(()=>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 lyi.MalloyError?{ok:!1,problems:[...n,...FF(o.problems).map(a)]}:{ok:!1,problems:[...n,oj(o,i.uri)]}}}function uyi(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 lyi,cEr=X(()=>{"use strict";lyi=vr(jc());Aut();Z8();Sy()});function fyi(t){return t.split(/\r?\n/).some(e=>dyi.test(e)||pyi.test(e))}function Qza(t){let e=t.split(/\r?\n/);for(let r=0;r<e.length;r++){let n=dyi.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(`
|
|
4524
|
-
`).trim();return c.length>0?c:void 0}o.push(e[a])}return}let i=pyi.exec(e[r]);if(i){let s=i[1].trim();return s.length>0?s:void 0}}}function Rae(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 uEr(t,e){if(P4.default.isAbsolute(e)||e.includes("\0"))return{problem:Rae(e)};let r=P4.default.resolve(t,e),n=P4.default.relative(t,r);if(n.startsWith("..")||P4.default.isAbsolute(n))return{problem:Rae(e)};if(n.split(P4.default.sep).some(Abt))return{problem:Rae(e)};if(!t1e(r)||!put.default.existsSync(r))return{problem:Rae(e)};let i;try{i=put.default.readFileSync(r,"utf8")}catch{return{problem:Rae(e)}}return fyi(i)?{abs:r}:{problem:Rae(e)}}function hyi(t){let e=[];for(let r of r1e(t)){let n;try{n=put.default.readFileSync(r,"utf8")}catch{continue}if(!fyi(n))continue;let i=P4.default.relative(t,r).split(P4.default.sep).join("/"),s=Qza(n);e.push(s?{handle:i,description:s}:{handle:i})}return e.sort((r,n)=>r.handle.localeCompare(n.handle)),e}async function gyi(t,e,r={}){let n=uEr(t,e);return"problem"in n?{ok:!1,problems:[n.problem]}:Zxe({uri:n.abs},r)}async function myi(t,e,r){let n=uEr(t,e);if("problem"in n)return{ok:!1,problems:[n.problem]};let i=await qF({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=FF(await a.validate());return{ok:!c.some(l=>l.severity==="error"),problems:[...i.problems,...c]}}catch(a){return a instanceof Ayi.MalloyError?{ok:!1,problems:[...i.problems,...FF(a.problems)]}:{ok:!1,problems:[...i.problems,oj(a)]}}}async function Eyi(t,e,r,n={}){let i=uEr(t,e);if("problem"in i)return{ok:!1,problems:[i.problem]};let s=await qF({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 aEr(c,n.rowLimit??Sv,n.givens,s.problems)}function yyi(t){if(!t)throw new Error("Restricted MCP mode (--restricted) requires a project directory: pass -p DIR to scope which models are exposed.");return P4.default.resolve(t)}var put,P4,Ayi,dyi,pyi,Cyi=X(()=>{"use strict";put=vr(require("node:fs")),P4=vr(require("node:path")),Ayi=vr(jc());Aut();sEr();cEr();Z8();Sy();dyi=/^([ \t]*)##\|\(mcp-description\)[ \t]*$/,pyi=/^[ \t]*##\(mcp-description\)[ \t]?(.*)$/});function eBe(t){let{result:e,errors:r}=(0,Iyi.prettify)(t);return{formatted:e,errors:r}}var Iyi,lEr=X(()=>{"use strict";Iyi=vr(oX())});var byi=m((OZc,zza)=>{zza.exports={name:"@malloydata/cli",version:"0.0.56-next.2026.6.13.b2270c2",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 && eslint .",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":"^3.0.1","@actions/github":"^9.1.1","@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":"^30.0.0","@types/node":"^24.13.1","@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",gts:"^7.0.0",jest:"^30.4.2","jest-silent-reporter":"^0.6.0",logform:"^2.5.1",prettier:"^3.0.3","ts-jest":"^29.1.0","ts-node":"^10.9.1",typescript:"^6.0.3",winston:"^3.9.0"},dependencies:{"@modelcontextprotocol/sdk":"^1.29.0",zod:"^4.3.6"}}});function rI(t){let e={...t};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:e}}async function GF(){await c0.shutdown("idle")}function Fza(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:hEr}},async({source:r})=>rI(eBe(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:jf.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 rI({topics:eEr()});let n=eyi(r);return rI(n?{slug:n.slug,title:n.title,body:n.body}:{error:`No topic matches '${r}'.`,topics:eEr()})});let e=J2i(uut());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 qza(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:AEr,expand:pEr,emit_run_sql:fEr}},async({uri:e,expand:r,emit_run_sql:n})=>{let i=await Zxe({uri:e},{expand:r,emitRunSql:n});return await GF(),rI(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:hEr,base_uri:_yi,expand:pEr,emit_run_sql:fEr}},async({source:e,base_uri:r,expand:n,emit_run_sql:i})=>{let s=await Zxe({source:e,baseUri:r},{expand:n,emitRunSql:i});return await GF(),rI(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:AEr,name:jf.string().optional().describe("Name of a `query:` definition to execute. Wins over `index`."),index:jf.number().int().optional().describe("0-based index into run: statements."),row_limit:gEr,givens:mEr}},async({uri:e,name:r,index:n,row_limit:i,givens:s})=>{let o=await oEr({uri:e},{name:r,index:n,rowLimit:i,givens:s});return await GF(),rI(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:hEr,base_uri:_yi,row_limit:gEr,givens:mEr}},async({source:e,base_uri:r,row_limit:n,givens:i})=>{let s=await oEr({source:e,baseUri:r},{rowLimit:n,givens:i});return await GF(),rI(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:AEr}},async({uri:e})=>{let r=await cyi({uri:e});return await GF(),rI(r)})}function Uza(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()=>rI({models:hyi(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:dEr,expand:pEr,emit_run_sql:fEr}},async({model:r,expand:n,emit_run_sql:i})=>{let s=await gyi(e,r,{expand:n,emitRunSql:i});return await GF(),rI(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:dEr,query:xyi}},async({model:r,query:n})=>{let i=await myi(e,r,n);return await GF(),rI(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:dEr,query:xyi,row_limit:gEr,givens:mEr}},async({model:r,query:n,row_limit:i,givens:s})=>{let o=await Eyi(e,r,n,{rowLimit:i,givens:s});return await GF(),rI(o)})}async function Byi(t={}){let e=t.restricted?yyi(t.projectDir):void 0,r=new out({name:"malloy-cli",version:Lza.version??"development"},{instructions:t.restricted?kza:Pza});e!==void 0?Uza(r,e):qza(r),Fza(r);let n=new cut;await r.connect(n)}var Lza,pEr,fEr,AEr,hEr,gEr,mEr,_yi,dEr,xyi,Pza,kza,Myi=X(()=>{"use strict";V2i();Y2i();$mr();sEr();cEr();Cyi();tEr();Jmr();Rv();lEr();Lza=byi(),pEr=jf.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)."),fEr=jf.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."),AEr=jf.string().describe("File URI (file://...) or bare filesystem path. Relative paths resolve against the server's working directory."),hEr=jf.string().describe("Malloy source code."),gEr=jf.number().int().optional().describe("Maximum number of rows to return. Defaults to 10000."),mEr=jf.record(jf.string(),jf.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.'),_yi=jf.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."),dEr=jf.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.'),xyi=jf.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`.");Pza=`
|
|
4524
|
+
`).trim();return c.length>0?c:void 0}o.push(e[a])}return}let i=pyi.exec(e[r]);if(i){let s=i[1].trim();return s.length>0?s:void 0}}}function Rae(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 uEr(t,e){if(P4.default.isAbsolute(e)||e.includes("\0"))return{problem:Rae(e)};let r=P4.default.resolve(t,e),n=P4.default.relative(t,r);if(n.startsWith("..")||P4.default.isAbsolute(n))return{problem:Rae(e)};if(n.split(P4.default.sep).some(Abt))return{problem:Rae(e)};if(!t1e(r)||!put.default.existsSync(r))return{problem:Rae(e)};let i;try{i=put.default.readFileSync(r,"utf8")}catch{return{problem:Rae(e)}}return fyi(i)?{abs:r}:{problem:Rae(e)}}function hyi(t){let e=[];for(let r of r1e(t)){let n;try{n=put.default.readFileSync(r,"utf8")}catch{continue}if(!fyi(n))continue;let i=P4.default.relative(t,r).split(P4.default.sep).join("/"),s=Qza(n);e.push(s?{handle:i,description:s}:{handle:i})}return e.sort((r,n)=>r.handle.localeCompare(n.handle)),e}async function gyi(t,e,r={}){let n=uEr(t,e);return"problem"in n?{ok:!1,problems:[n.problem]}:Zxe({uri:n.abs},r)}async function myi(t,e,r){let n=uEr(t,e);if("problem"in n)return{ok:!1,problems:[n.problem]};let i=await qF({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=FF(await a.validate());return{ok:!c.some(l=>l.severity==="error"),problems:[...i.problems,...c]}}catch(a){return a instanceof Ayi.MalloyError?{ok:!1,problems:[...i.problems,...FF(a.problems)]}:{ok:!1,problems:[...i.problems,oj(a)]}}}async function Eyi(t,e,r,n={}){let i=uEr(t,e);if("problem"in i)return{ok:!1,problems:[i.problem]};let s=await qF({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 aEr(c,n.rowLimit??Sv,n.givens,s.problems)}function yyi(t){if(!t)throw new Error("Restricted MCP mode (--restricted) requires a project directory: pass -p DIR to scope which models are exposed.");return P4.default.resolve(t)}var put,P4,Ayi,dyi,pyi,Cyi=X(()=>{"use strict";put=vr(require("node:fs")),P4=vr(require("node:path")),Ayi=vr(jc());Aut();sEr();cEr();Z8();Sy();dyi=/^([ \t]*)##\|\(mcp-description\)[ \t]*$/,pyi=/^[ \t]*##\(mcp-description\)[ \t]?(.*)$/});function eBe(t){let{result:e,errors:r}=(0,Iyi.prettify)(t);return{formatted:e,errors:r}}var Iyi,lEr=X(()=>{"use strict";Iyi=vr(oX())});var byi=m((OZc,zza)=>{zza.exports={name:"@malloydata/cli",version:"0.0.56",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 && eslint .",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":"^3.0.1","@actions/github":"^9.1.1","@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":"^30.0.0","@types/node":"^24.13.1","@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",gts:"^7.0.0",jest:"^30.4.2","jest-silent-reporter":"^0.6.0",logform:"^2.5.1",prettier:"^3.0.3","ts-jest":"^29.1.0","ts-node":"^10.9.1",typescript:"^6.0.3",winston:"^3.9.0"},dependencies:{"@modelcontextprotocol/sdk":"^1.29.0",zod:"^4.3.6"}}});function rI(t){let e={...t};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:e}}async function GF(){await c0.shutdown("idle")}function Fza(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:hEr}},async({source:r})=>rI(eBe(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:jf.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 rI({topics:eEr()});let n=eyi(r);return rI(n?{slug:n.slug,title:n.title,body:n.body}:{error:`No topic matches '${r}'.`,topics:eEr()})});let e=J2i(uut());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 qza(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:AEr,expand:pEr,emit_run_sql:fEr}},async({uri:e,expand:r,emit_run_sql:n})=>{let i=await Zxe({uri:e},{expand:r,emitRunSql:n});return await GF(),rI(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:hEr,base_uri:_yi,expand:pEr,emit_run_sql:fEr}},async({source:e,base_uri:r,expand:n,emit_run_sql:i})=>{let s=await Zxe({source:e,baseUri:r},{expand:n,emitRunSql:i});return await GF(),rI(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:AEr,name:jf.string().optional().describe("Name of a `query:` definition to execute. Wins over `index`."),index:jf.number().int().optional().describe("0-based index into run: statements."),row_limit:gEr,givens:mEr}},async({uri:e,name:r,index:n,row_limit:i,givens:s})=>{let o=await oEr({uri:e},{name:r,index:n,rowLimit:i,givens:s});return await GF(),rI(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:hEr,base_uri:_yi,row_limit:gEr,givens:mEr}},async({source:e,base_uri:r,row_limit:n,givens:i})=>{let s=await oEr({source:e,baseUri:r},{rowLimit:n,givens:i});return await GF(),rI(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:AEr}},async({uri:e})=>{let r=await cyi({uri:e});return await GF(),rI(r)})}function Uza(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()=>rI({models:hyi(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:dEr,expand:pEr,emit_run_sql:fEr}},async({model:r,expand:n,emit_run_sql:i})=>{let s=await gyi(e,r,{expand:n,emitRunSql:i});return await GF(),rI(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:dEr,query:xyi}},async({model:r,query:n})=>{let i=await myi(e,r,n);return await GF(),rI(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:dEr,query:xyi,row_limit:gEr,givens:mEr}},async({model:r,query:n,row_limit:i,givens:s})=>{let o=await Eyi(e,r,n,{rowLimit:i,givens:s});return await GF(),rI(o)})}async function Byi(t={}){let e=t.restricted?yyi(t.projectDir):void 0,r=new out({name:"malloy-cli",version:Lza.version??"development"},{instructions:t.restricted?kza:Pza});e!==void 0?Uza(r,e):qza(r),Fza(r);let n=new cut;await r.connect(n)}var Lza,pEr,fEr,AEr,hEr,gEr,mEr,_yi,dEr,xyi,Pza,kza,Myi=X(()=>{"use strict";V2i();Y2i();$mr();sEr();cEr();Cyi();tEr();Jmr();Rv();lEr();Lza=byi(),pEr=jf.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)."),fEr=jf.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."),AEr=jf.string().describe("File URI (file://...) or bare filesystem path. Relative paths resolve against the server's working directory."),hEr=jf.string().describe("Malloy source code."),gEr=jf.number().int().optional().describe("Maximum number of rows to return. Defaults to 10000."),mEr=jf.record(jf.string(),jf.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.'),_yi=jf.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."),dEr=jf.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.'),xyi=jf.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`.");Pza=`
|
|
4525
4525
|
This server lets an agent inspect, author, and execute Malloy semantic models.
|
|
4526
4526
|
|
|
4527
4527
|
Malloy (.malloy) files are NOT plain text you should read for comprehension.
|
package/dist/index.js
CHANGED