@malloydata/cli 0.0.58-next.2026.10.23.4f16c9c → 0.0.58
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
|
@@ -4552,7 +4552,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
4552
4552
|
`+t}async function iU(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?ixc(t.source):void 0,r=t.uri?TUi(t.uri):rxc(t.baseUri),{urlReader:n,readSource:i}=nxc(r,e),s=new Bmt.Runtime({config:Hu,urlReader:n});try{let o=await k2(()=>s.loadModel(r).getModel());return{ok:!0,loaded:{model:o,rootUrl:r,runtime:s,readSource:i},problems:nU(o.problems)}}catch(o){return o instanceof Bmt.MalloyError?{ok:!1,problems:nU(o.problems)}:{ok:!1,problems:[f$(o,r.href)]}}}var _3r,wUi,SUi,Bmt,txc,Mmt=Ae(()=>{"use strict";_3r=Gr(require("node:url")),wUi=Gr(require("node:fs")),SUi=Gr(require("node:path")),Bmt=Gr(Xc());IN();VC();b3r();txc="memory://mcp/"});function h$(t){if(t)return[t.range.start.line,t.range.start.character]}function sU(t){return t?t.forRoute().map(e=>({route:e.route,text:e.content})):[]}function wRe(t,e){return!!t&&t.url===e}function B3r(t,e){if(!t||!e)return;let r=t.split(`
|
|
4553
4553
|
`),{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(`
|
|
4554
4554
|
`)}function oxc(t){let e=t.structDef.join;return e==="one"||e==="many"||e==="cross"?e:"one"}function RUi(t){let e=t.structDef;return e.type==="array"&&e.elementTypeDef?.type!=="record_element"}function axc(t){let e=t.structDef;return e.type==="array"&&e.elementTypeDef?.type==="record_element"}function cxc(t){return t.structDef.type==="record"}function uxc(t,e){return RUi(t)?e.filter(r=>r.name!=="value"):e}function lxc(t,e){let n=e.find(i=>i.name===t.name)?.expressionType;return n&&((0,Omt.expressionIsAggregate)(n)||(0,Omt.expressionIsAnalytic)(n))?"measure":"dimension"}function Axc(t,e){if(RUi(t)||axc(t)||cxc(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 vUi(t,e,r,n){let i=sU(t.annotations),s=t.location,o=wRe(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=Axc(l,n.knownSources);if(a.kind="join",a.relationship=oxc(l),A&&(a.source_ref=A),(n.opts.expand==="inline"||!A)&&r<sxc){let f=l.structDef.fields??[],h=[];for(let m of l.allFields)h.push(vUi(m,f,r+1,n));a.fields=uxc(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 d=n.readSource(s.url),f=B3r(d,s);f&&(a.body=f)}return a}let c=t;a.kind=lxc(c,e),a.type=c.type;let u=c.expression||void 0;return u&&u!==t.name&&(a.expression=u),a}function dxc(t,e){let r=[],n=[],i=[],s=[],o=t.structDef.fields??[];for(let l of t.allFields){let A=vUi(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=sU(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 DUi(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[]":`${DUi(e)}[]`:"array"}return t.type}function pxc(t,e,r){let n={name:e,type:DUi(t.type),hasDefault:t.default!==void 0},i=sU(t.annotations);i.length>0&&(n.annotations=i);let s=t.location;if(s&&wRe(s,r.rootUri)){let o=h$(s);o&&(n.location=o);let a=B3r(r.readSource(s.url),s);a&&(n.body=a)}return n}function x3r(t){try{return[...t().givens.keys()]}catch{return[]}}async function fxc(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)wRe(f.location,e)&&a.push(dxc(f,o));let c=[];for(let f of i.named){let h=t.getPreparedQueryByName(f),m=h.location;if(!wRe(m,e))continue;let y={name:f},C=sU(h.annotations);C.length>0&&(y.annotations=C);let I=h$(m);I&&(y.location=I);let b=B3r(r(e),m);b&&(y.body=b);let S=x3r(()=>h);S.length>0&&(y.givens=S),c.push(y)}let u=[];for(let f=0;f<i.unnamed;f++){let h=t.getPreparedQueryByIndex(f),m={index:f},y=sU(h.annotations);y.length>0&&(m.annotations=y);let C=h$(h.location);C&&(m.location=C);try{let I=[...h.givens.keys()];I.length>0&&(m.givens=I),n.emitRunSql&&(m.sql=h.preparedResult.sql.trim())}catch(I){n.emitRunSql&&(m.error=I instanceof Error?I.message:String(I))}u.push(m)}let l=[];for(let[f,h]of t.givens)l.push(pxc(h,f,o));let A=sU(t.annotations),d={rootUri:e,sources:a,queries:c,runs:u};return A.length>0&&(d.annotations=A),l.length>0&&(d.givens=l),d}async function SRe(t,e={}){let r=await iU(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 fxc(n,i.href,s,{expand:e.expand??"ref",emitRunSql:e.emitRunSql??!1}),problems:r.problems}}catch(o){return{ok:!1,problems:[...r.problems,f$(o,i.href)]}}}async function NUi(t){let e=await iU(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 d=sU(u.annotations);d.length>0&&(l.annotations=d);let f=x3r(()=>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})=>wRe(a,n.href)).map(({pq:a,queryName:c,loc:u})=>{let l={name:c},A=h$(u);A&&(l.location=A);let d=sU(a.annotations);d.length>0&&(l.annotations=d);let f=x3r(()=>a);return f.length>0&&(l.givens=f),l});return{ok:!0,rootUri:n.href,runs:s,queries:o,problems:e.problems}}var Omt,sxc,M3r=Ae(()=>{"use strict";Omt=Gr(Xc());Mmt();sxc=4});async function O3r(t,e={}){let r=await iU(t);if(!r.ok||!r.loaded)return{ok:!1,problems:r.problems.map(u=>QUi(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 w3r(c,e.rowLimit??bN,e.givens,r.problems,{nudge:u=>QUi(u,t),uri:i.href})}async function w3r(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 k2(()=>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 LUi.MalloyError?{ok:!1,problems:[...n,...nU(o.problems).map(a)]}:{ok:!1,problems:[...n,f$(o,i.uri)]}}}function QUi(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 LUi,S3r=Ae(()=>{"use strict";LUi=Gr(Xc());Mmt();B7();VC()});function FUi(t){return t.split(/\r?\n/).some(e=>PUi.test(e)||kUi.test(e))}function hxc(t){let e=t.split(/\r?\n/);for(let r=0;r<e.length;r++){let n=PUi.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(`
|
|
4555
|
-
`).trim();return c.length>0?c:void 0}o.push(e[a])}return}let i=kUi.exec(e[r]);if(i){let s=i[1].trim();return s.length>0?s:void 0}}}function XAe(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 T3r(t,e){if(WL.default.isAbsolute(e)||e.includes("\0"))return{problem:XAe(e)};let r=WL.default.resolve(t,e),n=WL.default.relative(t,r);if(n.startsWith("..")||WL.default.isAbsolute(n))return{problem:XAe(e)};if(n.split(WL.default.sep).some(FRt))return{problem:XAe(e)};if(!Rge(r)||!wmt.default.existsSync(r))return{problem:XAe(e)};let i;try{i=wmt.default.readFileSync(r,"utf8")}catch{return{problem:XAe(e)}}return FUi(i)?{abs:r}:{problem:XAe(e)}}function qUi(t){let e=[];for(let r of vge(t)){let n;try{n=wmt.default.readFileSync(r,"utf8")}catch{continue}if(!FUi(n))continue;let i=WL.default.relative(t,r).split(WL.default.sep).join("/"),s=hxc(n);e.push(s?{handle:i,description:s}:{handle:i})}return e.sort((r,n)=>r.handle.localeCompare(n.handle)),e}async function UUi(t,e,r={}){let n=T3r(t,e);return"problem"in n?{ok:!1,problems:[n.problem]}:SRe({uri:n.abs},r)}async function GUi(t,e,r){let n=T3r(t,e);if("problem"in n)return{ok:!1,problems:[n.problem]};let i=await iU({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=nU(await a.validate());return{ok:!c.some(l=>l.severity==="error"),problems:[...i.problems,...c]}}catch(a){return a instanceof zUi.MalloyError?{ok:!1,problems:[...i.problems,...nU(a.problems)]}:{ok:!1,problems:[...i.problems,f$(a)]}}}async function WUi(t,e,r,n={}){let i=T3r(t,e);if("problem"in i)return{ok:!1,problems:[i.problem]};let s=await iU({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 w3r(c,n.rowLimit??bN,n.givens,s.problems)}function jUi(t){if(!t)throw new Error("Restricted MCP mode (--restricted) requires a project directory: pass -p DIR to scope which models are exposed.");return WL.default.resolve(t)}var wmt,WL,zUi,PUi,kUi,HUi=Ae(()=>{"use strict";wmt=Gr(require("node:fs")),WL=Gr(require("node:path")),zUi=Gr(Xc());Mmt();M3r();S3r();B7();VC();PUi=/^([ \t]*)##\|\(mcp-description\)[ \t]*$/,kUi=/^[ \t]*##\(mcp-description\)[ \t]?(.*)$/});function TRe(t){let{result:e,errors:r}=(0,VUi.prettify)(t);return{formatted:e,errors:r}}var VUi,R3r=Ae(()=>{"use strict";VUi=Gr(Vre())});var $Ui=E((yWu,gxc)=>{gxc.exports={name:"@malloydata/cli",version:"0.0.58-next.2026.10.23.4f16c9c",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 .",pretest:"npm run lint",test:"NODE_ENV=test jest --projects jest.config.js --runInBand","pretest-silent":"npm run lint","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 && npm run check-native","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 && npm run check-native","check-native":"ts-node scripts/check-native.ts","approve-native":"ts-node scripts/approve-native.ts","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.5-r.4","@duckdb/node-bindings-darwin-x64":"1.5.5-r.4","@duckdb/node-bindings-linux-arm64":"1.5.5-r.4","@duckdb/node-bindings-linux-arm64-musl":"1.5.5-r.4","@duckdb/node-bindings-linux-x64":"1.5.5-r.4","@duckdb/node-bindings-linux-x64-musl":"1.5.5-r.4","@duckdb/node-bindings-win32-arm64":"1.5.5-r.4","@duckdb/node-bindings-win32-x64":"1.5.5-r.4"},devDependencies:{"@actions/core":"^3.0.1","@actions/github":"^9.1.1","@commander-js/extra-typings":"^12.1.0","@duckdb/node-api":"1.5.5-r.4","@duckdb/node-bindings":"1.5.5-r.4","@malloydata/db-bigquery":"0.0.435","@malloydata/db-duckdb":"0.0.435","@malloydata/db-postgres":"0.0.435","@malloydata/db-snowflake":"0.0.435","@malloydata/db-trino":"0.0.435","@malloydata/malloy":"0.0.435","@malloydata/malloy-connections":"0.0.435","@malloydata/malloy-sql":"0.0.435","@types/jest":"^30.0.0","@types/node":"^24.13.1","@yao-pkg/pkg":"^6.24.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.1",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 _b(t){let e={...t};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:e}}async function oU(){await Hu.shutdown("idle")}function Cxc(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:L3r}},async({source:r})=>_b(TRe(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:jh.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 _b({topics:I3r()});let n=MUi(r);return _b(n?{slug:n.slug,title:n.title,body:n.body}:{error:`No topic matches '${r}'.`,topics:I3r()})});let e=_Ui(xmt());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 Ixc(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:v3r,expand:N3r,emit_run_sql:Q3r}},async({uri:e,expand:r,emit_run_sql:n})=>{let i=await SRe({uri:e},{expand:r,emitRunSql:n});return await oU(),_b(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:L3r,base_uri:YUi,expand:N3r,emit_run_sql:Q3r}},async({source:e,base_uri:r,expand:n,emit_run_sql:i})=>{let s=await SRe({source:e,baseUri:r},{expand:n,emitRunSql:i});return await oU(),_b(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:v3r,name:jh.string().optional().describe("Name of a `query:` definition to execute. Wins over `index`."),index:jh.number().int().optional().describe("0-based index into run: statements."),row_limit:z3r,givens:P3r}},async({uri:e,name:r,index:n,row_limit:i,givens:s})=>{let o=await O3r({uri:e},{name:r,index:n,rowLimit:i,givens:s});return await oU(),_b(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:L3r,base_uri:YUi,row_limit:z3r,givens:P3r}},async({source:e,base_uri:r,row_limit:n,givens:i})=>{let s=await O3r({source:e,baseUri:r},{rowLimit:n,givens:i});return await oU(),_b(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:v3r}},async({uri:e})=>{let r=await NUi({uri:e});return await oU(),_b(r)})}function bxc(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()=>_b({models:qUi(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:D3r,expand:N3r,emit_run_sql:Q3r}},async({model:r,expand:n,emit_run_sql:i})=>{let s=await UUi(e,r,{expand:n,emitRunSql:i});return await oU(),_b(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:D3r,query:KUi}},async({model:r,query:n})=>{let i=await GUi(e,r,n);return await oU(),_b(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:D3r,query:KUi,row_limit:z3r,givens:P3r}},async({model:r,query:n,row_limit:i,givens:s})=>{let o=await WUi(e,r,n,{rowLimit:i,givens:s});return await oU(),_b(o)})}async function JUi(t={}){let e=t.restricted?jUi(t.projectDir):void 0,r=new Imt({name:"malloy-cli",version:mxc.version??"development"},{instructions:t.restricted?yxc:Exc});e!==void 0?bxc(r,e):Ixc(r),Cxc(r);let n=new _mt;await r.connect(n)}var mxc,N3r,Q3r,v3r,L3r,z3r,P3r,YUi,D3r,KUi,Exc,yxc,XUi=Ae(()=>{"use strict";yUi();bUi();h3r();M3r();S3r();HUi();b3r();E3r();IN();R3r();mxc=$Ui(),N3r=jh.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)."),Q3r=jh.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."),v3r=jh.string().describe("File URI (file://...) or bare filesystem path. Relative paths resolve against the server's working directory."),L3r=jh.string().describe("Malloy source code."),z3r=jh.number().int().optional().describe("Maximum number of rows to return. Defaults to 10000."),P3r=jh.record(jh.string(),jh.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.'),YUi=jh.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."),D3r=jh.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.'),KUi=jh.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`.");Exc=`
|
|
4555
|
+
`).trim();return c.length>0?c:void 0}o.push(e[a])}return}let i=kUi.exec(e[r]);if(i){let s=i[1].trim();return s.length>0?s:void 0}}}function XAe(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 T3r(t,e){if(WL.default.isAbsolute(e)||e.includes("\0"))return{problem:XAe(e)};let r=WL.default.resolve(t,e),n=WL.default.relative(t,r);if(n.startsWith("..")||WL.default.isAbsolute(n))return{problem:XAe(e)};if(n.split(WL.default.sep).some(FRt))return{problem:XAe(e)};if(!Rge(r)||!wmt.default.existsSync(r))return{problem:XAe(e)};let i;try{i=wmt.default.readFileSync(r,"utf8")}catch{return{problem:XAe(e)}}return FUi(i)?{abs:r}:{problem:XAe(e)}}function qUi(t){let e=[];for(let r of vge(t)){let n;try{n=wmt.default.readFileSync(r,"utf8")}catch{continue}if(!FUi(n))continue;let i=WL.default.relative(t,r).split(WL.default.sep).join("/"),s=hxc(n);e.push(s?{handle:i,description:s}:{handle:i})}return e.sort((r,n)=>r.handle.localeCompare(n.handle)),e}async function UUi(t,e,r={}){let n=T3r(t,e);return"problem"in n?{ok:!1,problems:[n.problem]}:SRe({uri:n.abs},r)}async function GUi(t,e,r){let n=T3r(t,e);if("problem"in n)return{ok:!1,problems:[n.problem]};let i=await iU({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=nU(await a.validate());return{ok:!c.some(l=>l.severity==="error"),problems:[...i.problems,...c]}}catch(a){return a instanceof zUi.MalloyError?{ok:!1,problems:[...i.problems,...nU(a.problems)]}:{ok:!1,problems:[...i.problems,f$(a)]}}}async function WUi(t,e,r,n={}){let i=T3r(t,e);if("problem"in i)return{ok:!1,problems:[i.problem]};let s=await iU({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 w3r(c,n.rowLimit??bN,n.givens,s.problems)}function jUi(t){if(!t)throw new Error("Restricted MCP mode (--restricted) requires a project directory: pass -p DIR to scope which models are exposed.");return WL.default.resolve(t)}var wmt,WL,zUi,PUi,kUi,HUi=Ae(()=>{"use strict";wmt=Gr(require("node:fs")),WL=Gr(require("node:path")),zUi=Gr(Xc());Mmt();M3r();S3r();B7();VC();PUi=/^([ \t]*)##\|\(mcp-description\)[ \t]*$/,kUi=/^[ \t]*##\(mcp-description\)[ \t]?(.*)$/});function TRe(t){let{result:e,errors:r}=(0,VUi.prettify)(t);return{formatted:e,errors:r}}var VUi,R3r=Ae(()=>{"use strict";VUi=Gr(Vre())});var $Ui=E((yWu,gxc)=>{gxc.exports={name:"@malloydata/cli",version:"0.0.58",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 .",pretest:"npm run lint",test:"NODE_ENV=test jest --projects jest.config.js --runInBand","pretest-silent":"npm run lint","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 && npm run check-native","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 && npm run check-native","check-native":"ts-node scripts/check-native.ts","approve-native":"ts-node scripts/approve-native.ts","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.5-r.4","@duckdb/node-bindings-darwin-x64":"1.5.5-r.4","@duckdb/node-bindings-linux-arm64":"1.5.5-r.4","@duckdb/node-bindings-linux-arm64-musl":"1.5.5-r.4","@duckdb/node-bindings-linux-x64":"1.5.5-r.4","@duckdb/node-bindings-linux-x64-musl":"1.5.5-r.4","@duckdb/node-bindings-win32-arm64":"1.5.5-r.4","@duckdb/node-bindings-win32-x64":"1.5.5-r.4"},devDependencies:{"@actions/core":"^3.0.1","@actions/github":"^9.1.1","@commander-js/extra-typings":"^12.1.0","@duckdb/node-api":"1.5.5-r.4","@duckdb/node-bindings":"1.5.5-r.4","@malloydata/db-bigquery":"0.0.435","@malloydata/db-duckdb":"0.0.435","@malloydata/db-postgres":"0.0.435","@malloydata/db-snowflake":"0.0.435","@malloydata/db-trino":"0.0.435","@malloydata/malloy":"0.0.435","@malloydata/malloy-connections":"0.0.435","@malloydata/malloy-sql":"0.0.435","@types/jest":"^30.0.0","@types/node":"^24.13.1","@yao-pkg/pkg":"^6.24.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.1",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 _b(t){let e={...t};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:e}}async function oU(){await Hu.shutdown("idle")}function Cxc(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:L3r}},async({source:r})=>_b(TRe(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:jh.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 _b({topics:I3r()});let n=MUi(r);return _b(n?{slug:n.slug,title:n.title,body:n.body}:{error:`No topic matches '${r}'.`,topics:I3r()})});let e=_Ui(xmt());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 Ixc(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:v3r,expand:N3r,emit_run_sql:Q3r}},async({uri:e,expand:r,emit_run_sql:n})=>{let i=await SRe({uri:e},{expand:r,emitRunSql:n});return await oU(),_b(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:L3r,base_uri:YUi,expand:N3r,emit_run_sql:Q3r}},async({source:e,base_uri:r,expand:n,emit_run_sql:i})=>{let s=await SRe({source:e,baseUri:r},{expand:n,emitRunSql:i});return await oU(),_b(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:v3r,name:jh.string().optional().describe("Name of a `query:` definition to execute. Wins over `index`."),index:jh.number().int().optional().describe("0-based index into run: statements."),row_limit:z3r,givens:P3r}},async({uri:e,name:r,index:n,row_limit:i,givens:s})=>{let o=await O3r({uri:e},{name:r,index:n,rowLimit:i,givens:s});return await oU(),_b(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:L3r,base_uri:YUi,row_limit:z3r,givens:P3r}},async({source:e,base_uri:r,row_limit:n,givens:i})=>{let s=await O3r({source:e,baseUri:r},{rowLimit:n,givens:i});return await oU(),_b(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:v3r}},async({uri:e})=>{let r=await NUi({uri:e});return await oU(),_b(r)})}function bxc(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()=>_b({models:qUi(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:D3r,expand:N3r,emit_run_sql:Q3r}},async({model:r,expand:n,emit_run_sql:i})=>{let s=await UUi(e,r,{expand:n,emitRunSql:i});return await oU(),_b(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:D3r,query:KUi}},async({model:r,query:n})=>{let i=await GUi(e,r,n);return await oU(),_b(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:D3r,query:KUi,row_limit:z3r,givens:P3r}},async({model:r,query:n,row_limit:i,givens:s})=>{let o=await WUi(e,r,n,{rowLimit:i,givens:s});return await oU(),_b(o)})}async function JUi(t={}){let e=t.restricted?jUi(t.projectDir):void 0,r=new Imt({name:"malloy-cli",version:mxc.version??"development"},{instructions:t.restricted?yxc:Exc});e!==void 0?bxc(r,e):Ixc(r),Cxc(r);let n=new _mt;await r.connect(n)}var mxc,N3r,Q3r,v3r,L3r,z3r,P3r,YUi,D3r,KUi,Exc,yxc,XUi=Ae(()=>{"use strict";yUi();bUi();h3r();M3r();S3r();HUi();b3r();E3r();IN();R3r();mxc=$Ui(),N3r=jh.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)."),Q3r=jh.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."),v3r=jh.string().describe("File URI (file://...) or bare filesystem path. Relative paths resolve against the server's working directory."),L3r=jh.string().describe("Malloy source code."),z3r=jh.number().int().optional().describe("Maximum number of rows to return. Defaults to 10000."),P3r=jh.record(jh.string(),jh.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.'),YUi=jh.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."),D3r=jh.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.'),KUi=jh.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`.");Exc=`
|
|
4556
4556
|
This server lets an agent inspect, author, and execute Malloy semantic models.
|
|
4557
4557
|
|
|
4558
4558
|
Malloy (.malloy) files are NOT plain text you should read for comprehension.
|
package/dist/index.js
CHANGED