xmcp 0.1.0 → 0.1.2-alpha.1
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/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -21,4 +21,4 @@ if (!isNaN(pid)) {
|
|
|
21
21
|
})
|
|
22
22
|
process.on('SIGHUP', bark)
|
|
23
23
|
}
|
|
24
|
-
`,tr=e=>{let t=!1;const r=(0,Qt.spawn)(process.execPath,["-e",er,String(e.pid)],{stdio:"ignore"});return r.on("exit",()=>t=!0),e.on("exit",()=>{t||r.kill("SIGKILL")}),r},rr=dt.bold.green("✔"),ar=dt.bold.black.bgWhite(" XMCP "),nr=dt.bold.yellow("❯");let sr=null;function ir(){const e=(0,Qt.spawn)("node",["dist/http.js"],{stdio:"inherit",shell:!0});return tr(e),e}function or(e){console.log(""),console.log(dt.red.bold(e)),console.log(""),process.exit(1)}async function cr({onBuild:e}={}){const{mode:t,toolPaths:r}=w.getContext(),a=Date.now();let n=!1;const s=await async function(){const e=await async function(){const e=q("xmcp.config.json");if(e)return U(JSON.parse(e));if(q(H))try{return await async function(){const e=m().resolve(process.cwd(),H),t=(0,O.createFsFromVolume)(new O.Volume),r={mode:"production",entry:e,target:"node",output:{path:"/",filename:"config.js",library:{type:"commonjs2"}},resolve:{extensions:[".ts",".js"]},module:{rules:[{test:/\.ts$/,use:{loader:"swc-loader",options:{jsc:{parser:{syntax:"typescript"},target:"es2020"},module:{type:"commonjs"}}},exclude:/node_modules/}]},externals:{webpack:"commonjs2 webpack"}};return new Promise((a,n)=>{const s=(0,f.webpack)(r);s.outputFileSystem=t,s.run((r,s)=>{if(r)n(r);else if(s?.hasErrors())n(new Error(s.toString({colors:!1,errors:!0})));else try{const r=t.readFileSync("/config.js","utf8"),n={exports:{}},s=e=>{if("webpack"===e)return f.webpack;throw new Error(`Cannot resolve module: ${e}`)};new Function("module","exports","require","__filename","__dirname",r)(n,n.exports,s,e,m().dirname(e));const i=n.exports.default||n.exports,o="function"==typeof i?i():i;a(U(o))}catch(e){n(e)}})})}()}catch(e){throw new Error(`Failed to compile xmcp.config.ts:\n${e}`)}return{stdio:!0,http:!0,paths:{tools:C}}}(),{platforms:t}=w.getContext();return t.vercel&&delete e.stdio,e}();w.setContext({xmcpConfig:s});let i=function(e){const t=process.cwd(),{mode:r}=w.getContext(),a=e.experimental?.adapter?_:b,n={mode:r,watch:"development"===r,devtool:"development"===r&&"eval-cheap-module-source-map",output:{filename:e.experimental?.adapter?"index.js":"[name].js",path:a,libraryTarget:"commonjs2"},target:"node",externals:Fe(),resolve:{fallback:{process:!1},alias:{"node:process":"process","xmcp/headers":m().resolve(t,".xmcp/headers.js"),...Te()},extensions:[".tsx",".ts",".jsx",".js",".json"]},plugins:[new Ce,new je],module:{rules:[{test:/\.ts$/,use:"swc-loader"}]},optimization:{minimize:"production"===r,splitChunks:!1}};"development"!==r||e.experimental?.adapter||(n.watchOptions={ignored:[_]});const s={INJECTED_TOOLS:[m().resolve(t,".xmcp/import-map.js"),"tools"],INJECTED_MIDDLEWARE:[m().resolve(t,".xmcp/import-map.js"),"middleware"]};n.entry=function(e){const t={};return e.stdio&&(t.stdio=m().join(v,"stdio.js")),e.http&&(e.experimental?.adapter||(t.http=m().join(v,"http.js")),"express"===e.experimental?.adapter&&(t.adapter=m().join(v,"adapter-express.js")),"nextjs"===e.experimental?.adapter&&(t.adapter=m().join(v,"adapter-nextjs.js"))),t}(e),n.plugins.push(new f.ProvidePlugin(s));const i=function(e){const{mode:t}=w.getContext(),r={};if(e.http){r.HTTP_DEBUG="development"===t;let a={};"object"==typeof e.http?(r.HTTP_PORT=e.http.port,r.HTTP_BODY_SIZE_LIMIT=JSON.stringify(e.http.bodySizeLimit),r.HTTP_ENDPOINT=JSON.stringify(e.http.endpoint),r.HTTP_STATELESS=D,a=e.http.cors||{}):(r.HTTP_PORT=3002,r.HTTP_BODY_SIZE_LIMIT=JSON.stringify(I),r.HTTP_ENDPOINT=JSON.stringify(k),r.HTTP_STATELESS=D,a={}),r.HTTP_CORS_ORIGIN=JSON.stringify(a.origin??""),r.HTTP_CORS_METHODS=JSON.stringify(a.methods??""),r.HTTP_CORS_ALLOWED_HEADERS=JSON.stringify(a.allowedHeaders??""),r.HTTP_CORS_EXPOSED_HEADERS=JSON.stringify(a.exposedHeaders??""),r.HTTP_CORS_CREDENTIALS="boolean"==typeof a.credentials&&a.credentials,r.HTTP_CORS_MAX_AGE="number"==typeof a.maxAge?a.maxAge:0,r.OAUTH_CONFIG=JSON.stringify(e.experimental?.oauth||null)}return r.TOOLS_PATH=JSON.stringify(e.paths?.tools),r}(e);return n.plugins.push(new f.DefinePlugin(i)),e.experimental?.adapter||n.plugins.push(new Oe.k),n}(s);s.webpack&&(i=s.webpack(i));const o=new Jt({persistent:"development"===t,ignored:/(^|[\/\\])\../,ignoreInitial:!1});let c=function(e,t){if(void 0!==e){if(""===e&&or(`${t} path cannot be an empty string`),"string"==typeof(r=e)&&r.length>0)return function(e){return/[*?\[\]{}]/.test(e)}(e)&&or(`If you are using a glob pattern, please use a string for the ${t} path`),function(e){const r=function(e){return e.split(/\\|\//).join("/")}(e),a=m().resolve(g,r);return R().existsSync(a)||or(`The path set in xmcp config for ${t} does not exist: ${a}`),r}(e);var r;or(`${t} path must be a non-empty string`)}}(s.paths?.tools,"tools");o.watch(`${c}/**/*.ts`,{onAdd:e=>{r.add(e),n&&ur()},onUnlink:e=>{r.delete(e),n&&ur()}}),s.experimental?.adapter||o.watch("./src/middleware.ts",{onAdd:()=>{w.setContext({hasMiddleware:!0}),n&&ur()},onUnlink:()=>{w.setContext({hasMiddleware:!1}),n&&ur()}}),o.onReady(()=>{let r=!0;var o;n=!0,function(e,{force:t,dryRun:r,cwd:a=qe.cwd(),...n}={}){n={expandDirectories:!1,onlyFiles:!1,followSymbolicLinks:!1,cwd:a,...n},e=function(e){return(e=Array.isArray(e)?e:[e]).map(e=>"win32"===qe.platform&&!1===Ht(e)?_t(e):e)}(e);const s=qt(e,n).sort((e,t)=>t.localeCompare(e)).map(e=>(e=ht.resolve(a,e),t||function(e,t){if(function(e){let t=qe.cwd();return e=ht.resolve(e),"win32"===qe.platform&&(t=t.toLowerCase(),e=e.toLowerCase()),e===t}(e))throw new Error("Cannot delete the current working directory. Can be overridden with the `force` option.");if(!function(e,t){const r=ht.relative(t,e);return Boolean(r&&".."!==r&&!r.startsWith(`..${ht.sep}`)&&r!==ht.resolve(e))}(e,t))throw new Error("Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.")}(e,a),r||Yt.sync(e,Zt),e));s.sort((e,t)=>e.localeCompare(t))}(v),o=v,R().existsSync(o)||R().mkdirSync(o,{recursive:!0}),ur(),(0,f.webpack)(i,(n,i)=>{if(n&&console.error(n),i?.hasErrors())console.error(i.toString({colors:!0,chunks:!1}));else if(r){r=!1;const t=Date.now()-a;console.log(`${rr} Compiled in ${dt.bold.green(`${t}ms`)}`),function(e,t){const r=[];t.stdio&&r.push(`${rr} Built STDIO server`),t.http&&(t.experimental?.adapter?r.push(`${rr} Built Adapter`):r.push(`${rr} Built HTTP server`)),r.forEach(e=>{console.log(e)})}(0,s),e?.()}else"development"===t&&s.http&&!s.experimental?.adapter&&async function(){sr?(console.log(`${nr} Restarting http server`),await async function(e){e.kill("SIGKILL"),await new Promise(t=>{e.on("exit",t)})}(sr),sr=ir()):(console.log(`${nr} Starting http server`),sr=ir())}()})})}function ur(){const e=function(){const{toolPaths:e,hasMiddleware:t}=w.getContext();return`\nexport const tools = {\n${Array.from(e).map(e
|
|
24
|
+
`,tr=e=>{let t=!1;const r=(0,Qt.spawn)(process.execPath,["-e",er,String(e.pid)],{stdio:"ignore"});return r.on("exit",()=>t=!0),e.on("exit",()=>{t||r.kill("SIGKILL")}),r},rr=dt.bold.green("✔"),ar=dt.bold.black.bgWhite(" XMCP "),nr=dt.bold.yellow("❯");let sr=null;function ir(){const e=(0,Qt.spawn)("node",["dist/http.js"],{stdio:"inherit",shell:!0});return tr(e),e}function or(e){console.log(""),console.log(dt.red.bold(e)),console.log(""),process.exit(1)}async function cr({onBuild:e}={}){const{mode:t,toolPaths:r}=w.getContext(),a=Date.now();let n=!1;const s=await async function(){const e=await async function(){const e=q("xmcp.config.json");if(e)return U(JSON.parse(e));if(q(H))try{return await async function(){const e=m().resolve(process.cwd(),H),t=(0,O.createFsFromVolume)(new O.Volume),r={mode:"production",entry:e,target:"node",output:{path:"/",filename:"config.js",library:{type:"commonjs2"}},resolve:{extensions:[".ts",".js"]},module:{rules:[{test:/\.ts$/,use:{loader:"swc-loader",options:{jsc:{parser:{syntax:"typescript"},target:"es2020"},module:{type:"commonjs"}}},exclude:/node_modules/}]},externals:{webpack:"commonjs2 webpack"}};return new Promise((a,n)=>{const s=(0,f.webpack)(r);s.outputFileSystem=t,s.run((r,s)=>{if(r)n(r);else if(s?.hasErrors())n(new Error(s.toString({colors:!1,errors:!0})));else try{const r=t.readFileSync("/config.js","utf8"),n={exports:{}},s=e=>{if("webpack"===e)return f.webpack;throw new Error(`Cannot resolve module: ${e}`)};new Function("module","exports","require","__filename","__dirname",r)(n,n.exports,s,e,m().dirname(e));const i=n.exports.default||n.exports,o="function"==typeof i?i():i;a(U(o))}catch(e){n(e)}})})}()}catch(e){throw new Error(`Failed to compile xmcp.config.ts:\n${e}`)}return{stdio:!0,http:!0,paths:{tools:C}}}(),{platforms:t}=w.getContext();return t.vercel&&delete e.stdio,e}();w.setContext({xmcpConfig:s});let i=function(e){const t=process.cwd(),{mode:r}=w.getContext(),a=e.experimental?.adapter?_:b,n={mode:r,watch:"development"===r,devtool:"development"===r&&"eval-cheap-module-source-map",output:{filename:e.experimental?.adapter?"index.js":"[name].js",path:a,libraryTarget:"commonjs2"},target:"node",externals:Fe(),resolve:{fallback:{process:!1},alias:{"node:process":"process","xmcp/headers":m().resolve(t,".xmcp/headers.js"),...Te()},extensions:[".tsx",".ts",".jsx",".js",".json"]},plugins:[new Ce,new je],module:{rules:[{test:/\.ts$/,use:"swc-loader"}]},optimization:{minimize:"production"===r,splitChunks:!1}};"development"!==r||e.experimental?.adapter||(n.watchOptions={ignored:[_]});const s={INJECTED_TOOLS:[m().resolve(t,".xmcp/import-map.js"),"tools"],INJECTED_MIDDLEWARE:[m().resolve(t,".xmcp/import-map.js"),"middleware"]};n.entry=function(e){const t={};return e.stdio&&(t.stdio=m().join(v,"stdio.js")),e.http&&(e.experimental?.adapter||(t.http=m().join(v,"http.js")),"express"===e.experimental?.adapter&&(t.adapter=m().join(v,"adapter-express.js")),"nextjs"===e.experimental?.adapter&&(t.adapter=m().join(v,"adapter-nextjs.js"))),t}(e),n.plugins.push(new f.ProvidePlugin(s));const i=function(e){const{mode:t}=w.getContext(),r={};if(e.http){r.HTTP_DEBUG="development"===t;let a={};"object"==typeof e.http?(r.HTTP_PORT=e.http.port,r.HTTP_BODY_SIZE_LIMIT=JSON.stringify(e.http.bodySizeLimit),r.HTTP_ENDPOINT=JSON.stringify(e.http.endpoint),r.HTTP_STATELESS=D,a=e.http.cors||{}):(r.HTTP_PORT=3002,r.HTTP_BODY_SIZE_LIMIT=JSON.stringify(I),r.HTTP_ENDPOINT=JSON.stringify(k),r.HTTP_STATELESS=D,a={}),r.HTTP_CORS_ORIGIN=JSON.stringify(a.origin??""),r.HTTP_CORS_METHODS=JSON.stringify(a.methods??""),r.HTTP_CORS_ALLOWED_HEADERS=JSON.stringify(a.allowedHeaders??""),r.HTTP_CORS_EXPOSED_HEADERS=JSON.stringify(a.exposedHeaders??""),r.HTTP_CORS_CREDENTIALS="boolean"==typeof a.credentials&&a.credentials,r.HTTP_CORS_MAX_AGE="number"==typeof a.maxAge?a.maxAge:0,r.OAUTH_CONFIG=JSON.stringify(e.experimental?.oauth||null)}return r.TOOLS_PATH=JSON.stringify(e.paths?.tools),r}(e);return n.plugins.push(new f.DefinePlugin(i)),e.experimental?.adapter||n.plugins.push(new Oe.k),n}(s);s.webpack&&(i=s.webpack(i));const o=new Jt({persistent:"development"===t,ignored:/(^|[\/\\])\../,ignoreInitial:!1});let c=function(e,t){if(void 0!==e){if(""===e&&or(`${t} path cannot be an empty string`),"string"==typeof(r=e)&&r.length>0)return function(e){return/[*?\[\]{}]/.test(e)}(e)&&or(`If you are using a glob pattern, please use a string for the ${t} path`),function(e){const r=function(e){return e.split(/\\|\//).join("/")}(e),a=m().resolve(g,r);return R().existsSync(a)||or(`The path set in xmcp config for ${t} does not exist: ${a}`),r}(e);var r;or(`${t} path must be a non-empty string`)}}(s.paths?.tools,"tools");o.watch(`${c}/**/*.ts`,{onAdd:e=>{r.add(e),n&&ur()},onUnlink:e=>{r.delete(e),n&&ur()}}),s.experimental?.adapter||o.watch("./src/middleware.ts",{onAdd:()=>{w.setContext({hasMiddleware:!0}),n&&ur()},onUnlink:()=>{w.setContext({hasMiddleware:!1}),n&&ur()}}),o.onReady(()=>{let r=!0;var o;n=!0,function(e,{force:t,dryRun:r,cwd:a=qe.cwd(),...n}={}){n={expandDirectories:!1,onlyFiles:!1,followSymbolicLinks:!1,cwd:a,...n},e=function(e){return(e=Array.isArray(e)?e:[e]).map(e=>"win32"===qe.platform&&!1===Ht(e)?_t(e):e)}(e);const s=qt(e,n).sort((e,t)=>t.localeCompare(e)).map(e=>(e=ht.resolve(a,e),t||function(e,t){if(function(e){let t=qe.cwd();return e=ht.resolve(e),"win32"===qe.platform&&(t=t.toLowerCase(),e=e.toLowerCase()),e===t}(e))throw new Error("Cannot delete the current working directory. Can be overridden with the `force` option.");if(!function(e,t){const r=ht.relative(t,e);return Boolean(r&&".."!==r&&!r.startsWith(`..${ht.sep}`)&&r!==ht.resolve(e))}(e,t))throw new Error("Cannot delete files/directories outside the current working directory. Can be overridden with the `force` option.")}(e,a),r||Yt.sync(e,Zt),e));s.sort((e,t)=>e.localeCompare(t))}(v),o=v,R().existsSync(o)||R().mkdirSync(o,{recursive:!0}),ur(),(0,f.webpack)(i,(n,i)=>{if(n&&console.error(n),i?.hasErrors())console.error(i.toString({colors:!0,chunks:!1}));else if(r){r=!1;const t=Date.now()-a;console.log(`${rr} Compiled in ${dt.bold.green(`${t}ms`)}`),function(e,t){const r=[];t.stdio&&r.push(`${rr} Built STDIO server`),t.http&&(t.experimental?.adapter?r.push(`${rr} Built Adapter`):r.push(`${rr} Built HTTP server`)),r.forEach(e=>{console.log(e)})}(0,s),e?.()}else"development"===t&&s.http&&!s.experimental?.adapter&&async function(){sr?(console.log(`${nr} Restarting http server`),await async function(e){e.kill("SIGKILL"),await new Promise(t=>{e.on("exit",t)})}(sr),sr=ir()):(console.log(`${nr} Starting http server`),sr=ir())}()})})}function ur(){const e=function(){const{toolPaths:e,hasMiddleware:t}=w.getContext();return`\nexport const tools = {\n${Array.from(e).map(e=>{const t=e.replace(/\\/g,"/");return`"${t}": () => import("../${t}"),`}).join("\n")}\n};\n\n${t?'export const middleware = () => import("../src/middleware");':""}\n`}();R().writeFileSync(m().join(v,"import-map.js"),e);const t=m().join(g,"xmcp-env.d.ts");R().existsSync(t)&&R().unlinkSync(t),R().writeFileSync(t,'/// <reference types="xmcp" />\n\n// Do not edit this file')}Xt().config();const lr=process.cwd(),pr=new u;pr.name("xmcp").description("The MCP framework CLI").version("0.0.1"),pr.command("dev").description("Start development mode").action(()=>{console.log(`${ar} Starting development mode...`),S({mode:"development",platforms:{}},()=>{cr()})}),pr.command("build").description("Build for production").option("--vercel","Build for Vercel deployment").action(async e=>{console.log(`${ar} Building for production...`),S({mode:"production",platforms:{vercel:e.vercel}},()=>{cr({onBuild:async()=>{if(e.vercel){console.log(`${ar} Building for Vercel...`);try{await async function(){const e=m().join(lr,".vercel","output"),t=m().join(e,"functions","api","index.func");console.log("🚀 Building Vercel output structure..."),R().mkdirSync(e,{recursive:!0}),R().mkdirSync(t,{recursive:!0});const r=m().join(lr,"dist"),a=m().join(r,"http.js"),n=m().join(t,"index.js");if(!R().existsSync(r))throw new Error("❌ Dist directory not found. Run build first.");if(!R().existsSync(a))throw new Error("❌ Application server file not found in dist/. Run build first.");R().copyFileSync(a,n);const s=R().readdirSync(r);for(const e of s){const a=m().join(r,e),n=m().join(t,e);if("http.js"===e||"stdio.js"===e)continue;const s=R().statSync(a);s.isFile()?R().copyFileSync(a,n):s.isDirectory()&&R().cpSync(a,n,{recursive:!0})}const i=m().join(lr,"package.json"),o=m().join(t,"package.json");R().copyFileSync(i,o),console.log("Server and dependency files copied to function directory"),R().writeFileSync(m().join(t,".vc-config.json"),JSON.stringify({handler:"index.js",runtime:"nodejs22.x",launcherType:"Nodejs",shouldAddHelpers:!0},null,2)),R().writeFileSync(m().join(e,"config.json"),JSON.stringify({version:3,routes:[{src:"^/(.*)$",dest:"/api"},{handle:"filesystem"}]},null,2)),console.log("✅ Vercel output structure created successfully")}()}catch(e){console.error(dt.red("❌ Failed to create Vercel output structure:"),e)}}}})})}),pr.parse()})(),{}})());
|