@svgt/mcp 0.0.0 → 0.1.0
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/LICENSE +21 -0
- package/dist/http.js +2 -2
- package/dist/stdio.js +1 -1
- package/package.json +12 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pablo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/http.js
CHANGED
|
@@ -89,7 +89,7 @@ data:
|
|
|
89
89
|
-> Default export must be a resource handler function.`)}let hz=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load resource file: ${t}
|
|
90
90
|
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function hM(e){let t=e.split("/").filter(e=>""!==e),r=t.findIndex(e=>e.match(/^\(.+\)$/));if(-1===r)return null;let a=t[t.length-1];if(a&&a.match(/^\[.+\]\.ts$/))return null;let i=t[r].slice(1,-1),n=t.slice(r+1),o=n[n.length-1];if(o&&o.includes(".")){let e=o.split(".")[0];"index"!==e?n[n.length-1]=e:n.pop()}let s=[],c=[],l=n.map(e=>{if(!e.match(/^\[.+\]$/))return c.push(e),e;{let t=e.slice(1,-1);return s.push(t),`{${t}}`}}),p=`${i}://${l.join("/")}`,u=s.length>0?"template":"direct";return{filePath:e,uriTemplate:p,scheme:i,parameters:s,pathSegments:c,type:u}}let hL={ttlMs:0,cacheScope:"private"},hF=fW({cursor:fK().optional()}).passthrough().optional(),hD=fW({uri:fK()}).passthrough();function hU({uri:e,frontmatter:t,files:r}){return{uri:e,frontmatter:t,resources:r.map(({uri:e,digest:t,size:r})=>({uri:e,digest:t,size:r}))}}function hH(e){return Error(`[xmcp] Invalid tool file: ${e}
|
|
91
91
|
-> Default export must be a tool handler function.`)}let hZ=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load tool file: ${t}
|
|
92
|
-
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),hV="u"<typeof o?[]:o??[],hB={name:"svgt",version:"0.0.0",description:"Transform SVG into frontend components.",icons:[]};async function hJ(){let e=function(){let{instructions:e,...t}=hB;return new dJ(t,{instructions:e,cacheHints:{}})}(),t=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw hH(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw hH(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(a);return hZ(t),e}(),r=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw hI(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw hI(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(i);return hq(t),e}(),o=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw hN(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw hN(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(n);return hz(t),e}(),[l,p,u]=await Promise.all([t,r,o]);return async function(e,t,r,a){let i=await s?.(),n=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(i?.mcp),o=function(e){if(void 0!==e){if("function"!=typeof e)throw Error("src/middleware.ts must export authorize as a function");return e}}(i?.authorize),l;mc.clear();let p={};return!function(e,t,r,a){let i=e.server,n=i.setRequestHandler,o=a?{tools:new Map,prompts:new Map,resources:new Map,templates:new Map,uiOwners:new Map}:void 0,s=a&&o?function(e,t){let r=async(t,r,a)=>!r||await e(t,r,a)===!0;async function a(e,t,a){if(!Array.isArray(t))return t;let i=await Promise.all(t.map(t=>r(e,a(t),"list")));return t.filter((e,t)=>i[t])}return async(e,i)=>{switch(e.method){case"tools/call":{let{name:a}=e.params;if(!await r(e,t.tools.get(a),"call"))throw new l$(lk.InvalidParams,`Tool ${a} not found`);return i()}case"prompts/get":{let{name:a}=e.params;if(!await r(e,t.prompts.get(a),"get"))throw new l$(lk.InvalidParams,`Prompt ${a} not found`);return i()}case"resources/read":{let{uri:a}=e.params;if(!await r(e,mv(t,a),"read"))throw new lj(a);return i()}case"completion/complete":{let{ref:a}=e.params,n="ref/prompt"===a.type?t.prompts.get(a.name):[...t.templates.values()].find(({component:e})=>e.uriTemplate===a.uri)?.component??t.uiOwners.get(a.uri)??t.resources.get(a.uri);if(!await r(e,n,"complete"))throw new l$(lk.InvalidParams,"ref/prompt"===a.type?`Prompt ${a.name} not found`:`Resource template ${a.uri} not found`);return i()}case"tools/list":{let r=await i();return{...r,tools:await a(e,r.tools,e=>t.tools.get(e.name))}}case"prompts/list":{let r=await i();return{...r,prompts:await a(e,r.prompts,e=>t.prompts.get(e.name))}}case"resources/list":{let r=await i();return{...r,resources:await a(e,r.resources,e=>mv(t,e.uri,!0))}}case"resources/templates/list":{let r=await i();return{...r,resourceTemplates:await a(e,r.resourceTemplates,e=>t.templates.get(e.name)?.component)}}default:return i()}}}(a,o):void 0,c=hS(s?[s,...t]:t),l=s?hS([s]):void 0;i.setRequestHandler=(e,...t)=>{if(1===t.length&&"function"==typeof t[0]){let r=t[0];h$.has(e)?t[0]=(e,t)=>c({method:e.method,params:e.params??{}},t,()=>r(e,t)):"tools/call"===e&&l&&o&&(t[0]=(e,t)=>{let a=o.tools.get(e.params.name);return a?l({method:"tools/call",params:{name:e.params.name,arguments:e.params.arguments??{}},tool:{metadata:a.metadata}},t,()=>r(e,t)):r(e,t)})}Reflect.apply(n,i,[e,...t])};try{if(o){let t={registerTool:e.registerTool,registerPrompt:e.registerPrompt,registerResource:e.registerResource};e.registerTool=(r,a,...i)=>{let n=hk({name:r,description:a.description??"",annotations:a.annotations,icons:a.icons,tags:mg(a._meta),_meta:a._meta});return o.tools.set(r,Object.freeze({type:"tool",name:r,metadata:n})),Reflect.apply(t.registerTool,e,[r,a,...i])},e.registerPrompt=(r,a,...i)=>{let n=hk({name:r,title:a.title,description:a.description,icons:a.icons,tags:mg(a._meta),_meta:a._meta});return o.prompts.set(r,Object.freeze({type:"prompt",name:r,metadata:n})),Reflect.apply(t.registerPrompt,e,[r,a,...i])},e.registerResource=(r,a,i,...n)=>{let s=hk({name:r,title:i.title,description:i.description,icons:i.icons,mimeType:i.mimeType,tags:mg(i._meta),_meta:i._meta});if("string"==typeof a)o.resources.set(a,Object.freeze({type:"resource",name:r,uri:a,metadata:s}));else{let e=a.uriTemplate.toString();o.templates.set(r,{component:Object.freeze({type:"resourceTemplate",name:r,uriTemplate:e,metadata:s}),template:a})}return Reflect.apply(t.registerResource,e,[r,a,i,...n])};try{r(async(e,t,r)=>{let i=o.resources.get(t);return!i||await a(e,i,r)===!0})}finally{Object.assign(e,t)}for(let[e,t]of mc.getAll()){let r=o.tools.get(e);r&&o.uiOwners.set(t.uri,r)}}else r()}finally{i.setRequestHandler=n}}(e,n,i=>{var o,s;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,c,l,p={name:hO(a),description:"No description provided"},{default:u,metadata:d,schema:m,outputSchema:f}=t;if("object"==typeof d&&null!==d&&Object.assign(p,d),!1===p.enabled)return;if("function"==typeof u&&"__x402"in u){let e=global.__XMCP_X402_REGISTRY;e&&e.set(p.name,u.__x402)}let h={};if(hh(m)?(!function(e,t){let{type:r}=hg(e,"draft-2020-12","input");if(void 0!==r&&"object"!==r)throw Error(`Invalid schema for tool "${t}": tool input schemas must describe an object, got JSON Schema type ${JSON.stringify(r)}.`)}(m,p.name),h=m):hP(m)?h=m:null!=m&&console.warn(`Invalid schema for tool "${p.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`),null!=f)if(hh(f))o=f;else if(hP(f))o=f;else throw Error(`Invalid outputSchema for tool "${p.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`);p.annotations={...p.annotations??{}},void 0===p.annotations.title&&(p.annotations.title=p.name),p._meta={...ms(p)._meta};let g=hj(a),v=!!(i=p._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,y=p._meta;if(v){let e=`ui://app/${p.name}.html`;p._meta.ui||(p._meta.ui={}),p._meta.ui.resourceUri||(p._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))hE.includes(e)?i[e]=t:hR.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(y);y=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),mc.add(p.name,{name:p.name,uri:e,handler:u,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let b=hC(y),x=v?b:void 0;s=hj(a)&&v?async(e,t)=>({content:[{type:"text",text:""}],_meta:x,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,c=e(i,(o=hw(n),s=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:s?{headers:s}:void 0,clientInfo:o,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mA(e,"Elicitation request must be a plain object."),mT(e,m$,"URL elicitation"),mI(e.message,"URL elicitation requires a string message."),mq(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),mq(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){mA(e,"Elicitation request must be a plain object."),mT(e,mk,"Form elicitation"),mI(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mA(t,"Form elicitation requires a flat object schema."),mT(t,mj,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mA(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mA(t,`Form elicitation field "${e}" must be a plain object.`),mN(t.title,`Form elicitation field "${e}" title must be a string.`),mN(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(mT(t,mE,`Form elicitation field "${e}"`),mM(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&mM(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(mN(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){mT(t,mC,`Form elicitation field "${e}"`),mz(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mz(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mN(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mN(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!mO.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(mO).join(", ")}.`);return}if("boolean"===t.type){if(mT(t,mR,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){mT(t,mP,`Form elicitation field "${e}"`),mz(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mz(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mz(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof c1&&e.code===c0.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mU(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>mF.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!mL.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mU(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mU(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mD.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof c1&&e.code===c0.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),l6(c))return c;if(r&&hh(r)&&void 0!==c&&!hx(c)){if(await hb(c,r,a,"returned data that does not match outputSchema"),"string"==typeof c||"number"==typeof c)return{content:[{type:"text",text:`${c}`}],structuredContent:c};c={structuredContent:c}}if("string"==typeof c||"number"==typeof c){if(r&&!hh(r)){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[t]:c}}}catch{}}}return h_(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof c?`${c}`:c}]}}if(r&&c&&"object"==typeof c&&!Array.isArray(c)&&!hx(c)&&(await hb(c,r,a,"returned data that does not match outputSchema"),c={structuredContent:c}),c&&"object"==typeof c&&"_meta"in c&&!("content"in c)&&!("structuredContent"in c)){let e=c._meta;if(h_(e))return{content:[{type:"text",text:""}],_meta:e}}if(!c||"object"!=typeof c){let e=null===c?"null":typeof c,t=void 0===c?"undefined":null===c?"null":"object"==typeof c?JSON.stringify(c,null,2):String(c);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
|
|
92
|
+
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),hV="u"<typeof o?[]:o??[],hB={name:"svgt",version:"0.1.0",description:"Transform SVG into frontend components.",icons:[]};async function hJ(){let e=function(){let{instructions:e,...t}=hB;return new dJ(t,{instructions:e,cacheHints:{}})}(),t=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw hH(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw hH(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(a);return hZ(t),e}(),r=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw hI(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw hI(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(i);return hq(t),e}(),o=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw hN(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw hN(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(n);return hz(t),e}(),[l,p,u]=await Promise.all([t,r,o]);return async function(e,t,r,a){let i=await s?.(),n=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(i?.mcp),o=function(e){if(void 0!==e){if("function"!=typeof e)throw Error("src/middleware.ts must export authorize as a function");return e}}(i?.authorize),l;mc.clear();let p={};return!function(e,t,r,a){let i=e.server,n=i.setRequestHandler,o=a?{tools:new Map,prompts:new Map,resources:new Map,templates:new Map,uiOwners:new Map}:void 0,s=a&&o?function(e,t){let r=async(t,r,a)=>!r||await e(t,r,a)===!0;async function a(e,t,a){if(!Array.isArray(t))return t;let i=await Promise.all(t.map(t=>r(e,a(t),"list")));return t.filter((e,t)=>i[t])}return async(e,i)=>{switch(e.method){case"tools/call":{let{name:a}=e.params;if(!await r(e,t.tools.get(a),"call"))throw new l$(lk.InvalidParams,`Tool ${a} not found`);return i()}case"prompts/get":{let{name:a}=e.params;if(!await r(e,t.prompts.get(a),"get"))throw new l$(lk.InvalidParams,`Prompt ${a} not found`);return i()}case"resources/read":{let{uri:a}=e.params;if(!await r(e,mv(t,a),"read"))throw new lj(a);return i()}case"completion/complete":{let{ref:a}=e.params,n="ref/prompt"===a.type?t.prompts.get(a.name):[...t.templates.values()].find(({component:e})=>e.uriTemplate===a.uri)?.component??t.uiOwners.get(a.uri)??t.resources.get(a.uri);if(!await r(e,n,"complete"))throw new l$(lk.InvalidParams,"ref/prompt"===a.type?`Prompt ${a.name} not found`:`Resource template ${a.uri} not found`);return i()}case"tools/list":{let r=await i();return{...r,tools:await a(e,r.tools,e=>t.tools.get(e.name))}}case"prompts/list":{let r=await i();return{...r,prompts:await a(e,r.prompts,e=>t.prompts.get(e.name))}}case"resources/list":{let r=await i();return{...r,resources:await a(e,r.resources,e=>mv(t,e.uri,!0))}}case"resources/templates/list":{let r=await i();return{...r,resourceTemplates:await a(e,r.resourceTemplates,e=>t.templates.get(e.name)?.component)}}default:return i()}}}(a,o):void 0,c=hS(s?[s,...t]:t),l=s?hS([s]):void 0;i.setRequestHandler=(e,...t)=>{if(1===t.length&&"function"==typeof t[0]){let r=t[0];h$.has(e)?t[0]=(e,t)=>c({method:e.method,params:e.params??{}},t,()=>r(e,t)):"tools/call"===e&&l&&o&&(t[0]=(e,t)=>{let a=o.tools.get(e.params.name);return a?l({method:"tools/call",params:{name:e.params.name,arguments:e.params.arguments??{}},tool:{metadata:a.metadata}},t,()=>r(e,t)):r(e,t)})}Reflect.apply(n,i,[e,...t])};try{if(o){let t={registerTool:e.registerTool,registerPrompt:e.registerPrompt,registerResource:e.registerResource};e.registerTool=(r,a,...i)=>{let n=hk({name:r,description:a.description??"",annotations:a.annotations,icons:a.icons,tags:mg(a._meta),_meta:a._meta});return o.tools.set(r,Object.freeze({type:"tool",name:r,metadata:n})),Reflect.apply(t.registerTool,e,[r,a,...i])},e.registerPrompt=(r,a,...i)=>{let n=hk({name:r,title:a.title,description:a.description,icons:a.icons,tags:mg(a._meta),_meta:a._meta});return o.prompts.set(r,Object.freeze({type:"prompt",name:r,metadata:n})),Reflect.apply(t.registerPrompt,e,[r,a,...i])},e.registerResource=(r,a,i,...n)=>{let s=hk({name:r,title:i.title,description:i.description,icons:i.icons,mimeType:i.mimeType,tags:mg(i._meta),_meta:i._meta});if("string"==typeof a)o.resources.set(a,Object.freeze({type:"resource",name:r,uri:a,metadata:s}));else{let e=a.uriTemplate.toString();o.templates.set(r,{component:Object.freeze({type:"resourceTemplate",name:r,uriTemplate:e,metadata:s}),template:a})}return Reflect.apply(t.registerResource,e,[r,a,i,...n])};try{r(async(e,t,r)=>{let i=o.resources.get(t);return!i||await a(e,i,r)===!0})}finally{Object.assign(e,t)}for(let[e,t]of mc.getAll()){let r=o.tools.get(e);r&&o.uiOwners.set(t.uri,r)}}else r()}finally{i.setRequestHandler=n}}(e,n,i=>{var o,s;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,c,l,p={name:hO(a),description:"No description provided"},{default:u,metadata:d,schema:m,outputSchema:f}=t;if("object"==typeof d&&null!==d&&Object.assign(p,d),!1===p.enabled)return;if("function"==typeof u&&"__x402"in u){let e=global.__XMCP_X402_REGISTRY;e&&e.set(p.name,u.__x402)}let h={};if(hh(m)?(!function(e,t){let{type:r}=hg(e,"draft-2020-12","input");if(void 0!==r&&"object"!==r)throw Error(`Invalid schema for tool "${t}": tool input schemas must describe an object, got JSON Schema type ${JSON.stringify(r)}.`)}(m,p.name),h=m):hP(m)?h=m:null!=m&&console.warn(`Invalid schema for tool "${p.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`),null!=f)if(hh(f))o=f;else if(hP(f))o=f;else throw Error(`Invalid outputSchema for tool "${p.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`);p.annotations={...p.annotations??{}},void 0===p.annotations.title&&(p.annotations.title=p.name),p._meta={...ms(p)._meta};let g=hj(a),v=!!(i=p._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,y=p._meta;if(v){let e=`ui://app/${p.name}.html`;p._meta.ui||(p._meta.ui={}),p._meta.ui.resourceUri||(p._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))hE.includes(e)?i[e]=t:hR.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(y);y=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),mc.add(p.name,{name:p.name,uri:e,handler:u,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let b=hC(y),x=v?b:void 0;s=hj(a)&&v?async(e,t)=>({content:[{type:"text",text:""}],_meta:x,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,c=e(i,(o=hw(n),s=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:s?{headers:s}:void 0,clientInfo:o,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mA(e,"Elicitation request must be a plain object."),mT(e,m$,"URL elicitation"),mI(e.message,"URL elicitation requires a string message."),mq(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),mq(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){mA(e,"Elicitation request must be a plain object."),mT(e,mk,"Form elicitation"),mI(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mA(t,"Form elicitation requires a flat object schema."),mT(t,mj,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mA(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mA(t,`Form elicitation field "${e}" must be a plain object.`),mN(t.title,`Form elicitation field "${e}" title must be a string.`),mN(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(mT(t,mE,`Form elicitation field "${e}"`),mM(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&mM(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(mN(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){mT(t,mC,`Form elicitation field "${e}"`),mz(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mz(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mN(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mN(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!mO.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(mO).join(", ")}.`);return}if("boolean"===t.type){if(mT(t,mR,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){mT(t,mP,`Form elicitation field "${e}"`),mz(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mz(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mz(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof c1&&e.code===c0.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mU(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>mF.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!mL.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mU(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mU(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mD.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof c1&&e.code===c0.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(c instanceof Promise&&(c=await c),l6(c))return c;if(r&&hh(r)&&void 0!==c&&!hx(c)){if(await hb(c,r,a,"returned data that does not match outputSchema"),"string"==typeof c||"number"==typeof c)return{content:[{type:"text",text:`${c}`}],structuredContent:c};c={structuredContent:c}}if("string"==typeof c||"number"==typeof c){if(r&&!hh(r)){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(c),{content:[{type:"text",text:"number"==typeof c?`${c}`:c}],structuredContent:{[t]:c}}}catch{}}}return h_(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof c?`${c}`:c}]}}if(r&&c&&"object"==typeof c&&!Array.isArray(c)&&!hx(c)&&(await hb(c,r,a,"returned data that does not match outputSchema"),c={structuredContent:c}),c&&"object"==typeof c&&"_meta"in c&&!("content"in c)&&!("structuredContent"in c)){let e=c._meta;if(h_(e))return{content:[{type:"text",text:""}],_meta:e}}if(!c||"object"!=typeof c){let e=null===c?"null":typeof c,t=void 0===c?"undefined":null===c?"null":"object"==typeof c?JSON.stringify(c,null,2):String(c);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
|
|
93
93
|
|
|
94
94
|
Expected CallToolResult format:
|
|
95
95
|
{
|
|
@@ -942,7 +942,7 @@ args = ["-y", "mcp-remote", "$\{serverUrl}"]\`,
|
|
|
942
942
|
<\/script>
|
|
943
943
|
</body>
|
|
944
944
|
</html>
|
|
945
|
-
`))}),this.setupMcpServerCardRoute(),this.setupOpenAIAppsChallengeRoute(),this.app.use((e,t,r)=>{md({id:(0,hG.randomUUID)(),headers:e.headers},()=>{r()})})}setupMcpServerCardRoute(){this.app.get("/.well-known/mcp/server-card.json",(e,t)=>{var r;let a,i,n=(a=gJ((r={forwardedProto:e.headers["x-forwarded-proto"],protocol:e.protocol,host:e.get("host")}).forwardedProto)??gJ(r.protocol)??"http",i=gG(r.forwardedHost)??gG(r.host)??"localhost",new URL(`${a}://${i}`).origin),o=new URL(n).hostname.split(".").reverse().join("."),s={$schema:"https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",name:`${o}/mcp`,version:"0.
|
|
945
|
+
`))}),this.setupMcpServerCardRoute(),this.setupOpenAIAppsChallengeRoute(),this.app.use((e,t,r)=>{md({id:(0,hG.randomUUID)(),headers:e.headers},()=>{r()})})}setupMcpServerCardRoute(){this.app.get("/.well-known/mcp/server-card.json",(e,t)=>{var r;let a,i,n=(a=gJ((r={forwardedProto:e.headers["x-forwarded-proto"],protocol:e.protocol,host:e.get("host")}).forwardedProto)??gJ(r.protocol)??"http",i=gG(r.forwardedHost)??gG(r.host)??"localhost",new URL(`${a}://${i}`).origin),o=new URL(n).hostname.split(".").reverse().join("."),s={$schema:"https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",name:`${o}/mcp`,version:"0.1.0",description:this.options.template?.description,title:this.options.template?.name,remotes:[{type:"streamable-http",url:`${n}${this.endpoint}`}]};this.options.template?.icons?.length&&(s.icons=this.options.template.icons),t.setHeader("Content-Type","application/mcp-server-card+json").setHeader("Cache-Control","public, max-age=3600, must-revalidate").setHeader("Access-Control-Allow-Origin","*").setHeader("Vary","Host, X-Forwarded-Proto").json(s)})}setupOpenAIAppsChallengeRoute(){let e=process.env.OPENAI_APPS_VERIFICATION_TOKEN;if(!e){this.debug&&this.log("OpenAI Apps verification token not configured; skipping challenge route");return}this.app.get("/.well-known/openai-apps-challenge",(t,r)=>{r.status(200).set("Content-Type","text/plain").send(e)})}setupEndpointRoute(){this.app.use(this.endpoint,async(e,t)=>{this.log(`${e.method} ${e.path}`),this.extractAndStoreToolName(e),await this.handleStatelessRequest(e,t)})}extractAndStoreToolName(e){try{let t=function(e){if(e?.body===void 0||null===e.body)return[];let t=Array.isArray(e.body)?e.body:[e.body],r=[];for(let e of t)if("object"==typeof e&&null!==e&&"method"in e&&"tools/call"===e.method){let t=e.params;t&&"object"==typeof t&&"name"in t&&"string"==typeof t.name&&r.push(t.name)}return r}(e);t.length>0&&(0!==t.length&&(e.headers["x-mcp-tool-name"]=t[0],e.headers["x-mcp-tool-names"]=t.join(",")),global.__XMCP_CURRENT_TOOL_NAME=t[0])}catch(e){}}async handleStatelessRequest(e,t){let r=(e=>{for(let t of Array.isArray(e)?e:[e]){let e=mw(t);if(e)return e}})(e.body);t.on("finish",()=>{global.__XMCP_CURRENT_TOOL_NAME=void 0}),t.on("close",()=>{global.__XMCP_CURRENT_TOOL_NAME=void 0}),mp({clientInfo:r}),await this.nodeMcpHandler(e,t,e.body)}async start(){let e=this.options.host||"127.0.0.1",t=await async function e(t=3001,r="127.0.0.1"){return new Promise(a=>{let i;(i=gH().createServer(),new Promise((e,a)=>{i.once("error",t=>{"code"in t&&"EADDRINUSE"===t.code?e(!1):a(t)}),i.once("listening",()=>{i.close(),e(!0)}),i.listen(t,r)})).then(r=>{r?a(t):(console.log(`\x1b[1m\x1b[33m❯\x1b[39m\x1b[22m Port ${gZ(String(t))} is in use, trying ${gZ(String(t+1))} instead.`),e(t+1).then(a))})})}(this.port,e);this.server.listen(t,e,()=>{console.log(`\x1b[1m\x1b[32m✔\x1b[39m\x1b[22m MCP Server running on http://${e}:${t}${this.endpoint}`),this.setupShutdownHandlers()})}setupShutdownHandlers(){process.on("SIGINT",this.shutdown.bind(this)),process.on("SIGTERM",this.shutdown.bind(this))}shutdown(){this.log("Shutting down server"),this.mcpHandler.close(),this.server.close(),process.exit(0)}constructor(e,t={},r=gX,a){var i,n;let o;gQ(this,"app",void 0),gQ(this,"server",void 0),gQ(this,"port",void 0),gQ(this,"endpoint",void 0),gQ(this,"debug",void 0),gQ(this,"options",void 0),gQ(this,"createServerFn",void 0),gQ(this,"corsConfig",void 0),gQ(this,"providers",void 0),gQ(this,"mcpHandler",void 0),gQ(this,"nodeMcpHandler",void 0),this.options={...t},this.app=gL()(),this.server=gD().createServer(this.app),this.port=t.port??parseInt(process.env.PORT||"3001",10),this.endpoint=t.endpoint??"/mcp",this.debug=t.debug??!1,this.createServerFn=e,this.corsConfig=r,this.providers=a,this.mcpHandler=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t,o=d6(t.maxRequestBodySize);if("function"==typeof a)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let s=new Set,c=!1,l=e=>{try{i?.(e)}catch{}},p=t.bus??new d4(l),u=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,c){let l,p,u,d,m,f,h;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),d8(e.id,-32603,"Subscription limit reached");let g=(m=lV(lZ).validateRequest("subscriptions/listen",e)).ok?m.value.params?.notifications:void 0;if(void 0===g)return d8(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let v=(f={},h=e=>void 0===s||!0===e,!0===g.toolsListChanged&&h(s?.tools?.listChanged)&&(f.toolsListChanged=!0),!0===g.promptsListChanged&&h(s?.prompts?.listChanged)&&(f.promptsListChanged=!0),!0===g.resourcesListChanged&&h(s?.resources?.listChanged)&&(f.resourcesListChanged=!0),void 0!==g.resourceSubscriptions&&g.resourceSubscriptions.length>0&&h(s?.resources?.subscribe)&&(f.resourceSubscriptions=[...g.resourceSubscriptions]),f),y=e.id,b=new TextEncoder,x=!1,_=e=>{if(!x)try{l.enqueue(b.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},w=(e,t)=>{_(`event: message
|
|
946
946
|
data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
947
947
|
|
|
948
948
|
`)},S=e=>{if(!x){e&&_(`event: message
|
package/dist/stdio.js
CHANGED
|
@@ -79,7 +79,7 @@ data: ${JSON.stringify(e)}
|
|
|
79
79
|
-> Default export must be a resource handler function.`)}let h3=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load resource file: ${t}
|
|
80
80
|
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function h8(e){let t=e.split("/").filter(e=>""!==e),r=t.findIndex(e=>e.match(/^\(.+\)$/));if(-1===r)return null;let a=t[t.length-1];if(a&&a.match(/^\[.+\]\.ts$/))return null;let i=t[r].slice(1,-1),n=t.slice(r+1),s=n[n.length-1];if(s&&s.includes(".")){let e=s.split(".")[0];"index"!==e?n[n.length-1]=e:n.pop()}let o=[],l=[],c=n.map(e=>{if(!e.match(/^\[.+\]$/))return l.push(e),e;{let t=e.slice(1,-1);return o.push(t),`{${t}}`}}),u=`${i}://${c.join("/")}`,d=o.length>0?"template":"direct";return{filePath:e,uriTemplate:u,scheme:i,parameters:o,pathSegments:l,type:d}}let h7={ttlMs:0,cacheScope:"private"},fe=hu({cursor:hc().optional()}).passthrough().optional(),ft=hu({uri:hc()}).passthrough();function fr({uri:e,frontmatter:t,files:r}){return{uri:e,frontmatter:t,resources:r.map(({uri:e,digest:t,size:r})=>({uri:e,digest:t,size:r}))}}function fa(e){return Error(`[xmcp] Invalid tool file: ${e}
|
|
81
81
|
-> Default export must be a tool handler function.`)}let fi=function(e=console){let t="";return r=>{let a=r.map(({path:e,message:t})=>`${e}:${t}`).sort().join("|");if(a===t||(t=a,0===r.length))return;r.forEach(({path:t,message:r})=>{e.warn(`[xmcp] Failed to load tool file: ${t}
|
|
82
|
-
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),fn="u"<typeof s?[]:s??[],fs={name:"svgt",version:"0.0.0",description:"Transform SVG into frontend components.",icons:[]};var fo=l(8717);l.n(fo)().config(),pH({clientInfo:void 0},()=>{let e;!function(e,t={}){let r,a=t.legacy??"serve",i=t.transport??new pR,n={phase:"opening"},s=!1,o=()=>s||"closed"===n.phase,l=e=>{try{t.onerror?.(e)}catch{}},c=(e,t,r,a)=>i.send({jsonrpc:"2.0",id:e,error:{code:t,message:r,...void 0!==a&&{data:a}}}).catch(e=>l(pE(e))),u=new pk(t.maxSubscriptions??1024),d=e=>{if(!sr.safeParse(e).success)return;let t=u.routeOutbound(e);if("passthrough"!==t){for(let e of t)i.send({jsonrpc:"2.0",...e}).catch(e=>l(pE(e)));return"handled"}},p=async e=>{if(cV(e)&&"subscriptions/listen"===e.method){let t,r=cz(e.params),a=cM(e.params)?(void 0===r?[]:cZ(r))[0]:{key:"_meta",problem:"the per-request envelope is required on protocol revision 2026-07-28"},n=cL(e.params);if(void 0!==a)t={jsonrpc:"2.0",id:e.id,error:{code:-32602,message:`Invalid _meta envelope: ${a.key}: ${a.problem}`}};else if(void 0!==n&&lH.includes(n))t=u.serve(e);else{let r=new cm({supported:[...lH],requested:n??"unknown"});t={jsonrpc:"2.0",id:e.id,error:{code:r.code,message:r.message,data:r.data}}}return await i.send("error"in t?t:{jsonrpc:"2.0",method:t.method,params:t.params}).catch(e=>l(pE(e))),!0}if(sr.safeParse(e).success&&"notifications/cancelled"===e.method){let t=e.params?.requestId;if(void 0!==t&&u.cancel(t))return!0}return!1},m=(e,t,r)=>{let a=function(e,t){switch(e.reason){case"http-method":return cY("http-method","modern-only-method-not-allowed",405,new cu(-32e3,"Method not allowed."),!0);case"batch":return cY("jsonrpc-shape","modern-only-batch-not-supported",400,new cu(cc.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return cY("jsonrpc-shape","modern-only-response-post",400,new cu(cc.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let r=e.requestedVersion;return cY("era-classification","modern-only-missing-envelope",400,void 0===r?new cu(cc.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new cm({supported:[...t],requested:r}),!0)}}}({kind:"legacy",reason:t,...void 0!==r&&{requestedVersion:r}},lH);return void 0===a?Promise.resolve():(l(Error(`Rejected 2025-era request on a modern-only stdio connection (${a.cell}): ${a.message}`)),c(e.id,a.code,a.message,a.data))},f=async(t,a)=>{let n=await e({era:t}),o=n instanceof pp?n.server:n;"modern"===t&&(h(o,a),g(o,lH),u.setServerCapabilities(o.getCapabilities(),y(o)));let l=new pP(i,()=>{s||l===r||$()},"modern"===t?d:void 0);return await n.connect(l),{product:n,channel:l}},v=e=>e.product.close().catch(e=>l(pE(e))),_=async e=>{if("closed"===n.phase)return;if("pinned"===n.phase)return"modern"===n.era&&cV(e)&&"initialize"===e.method&&!cQ(e.params)?void await m(e,"initialize",null!==e.params&&"object"==typeof e.params&&"string"==typeof e.params.protocolVersion?e.params.protocolVersion:void 0):void("modern"===n.era&&await p(e)||o()||n.instance.channel.deliver(e));if(!cV(e)&&!sr.safeParse(e).success)return void l(Error("Discarded a JSON-RPC response received before the connection negotiated an era"));let t=function(e){let t=e.params;if("initialize"===e.method&&!cQ(t)){let e=null!==t&&"object"==typeof t&&"string"==typeof t.protocolVersion?t.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==e&&{requestedVersion:e}}}if(!cM(t))return{kind:"legacy",reason:"no-claim"};let r=cz(t),a=(void 0===r?[]:cZ(r))[0];if(void 0!==a)return{kind:"invalid-envelope",issue:a};let i=cL(t);return void 0!==i&&lH.includes(i)?{kind:"modern",revision:i,classification:{era:"modern",revision:i}}:{kind:"unsupported-revision",requested:i??"unknown"}}(e);switch(t.kind){case"invalid-envelope":{let r=`Invalid _meta envelope for protocol revision 2026-07-28: ${t.issue.key}: ${t.issue.problem}`;cV(e)?await c(e.id,cc.InvalidParams,r,{envelope:t.issue}):l(Error(`Discarded a notification with a malformed envelope: ${r}`));return}case"unsupported-revision":if(cV(e)){let r=new cm({supported:[...lH],requested:t.requested});l(r),await c(e.id,r.code,r.message,r.data)}else l(Error(`Discarded a notification claiming unsupported protocol revision ${t.requested}`));return;case"modern":if(cV(e)&&"server/discover"===e.method){if("probe"===n.phase)return void n.instance.channel.deliver(e,{classification:t.classification});let r=await f("modern",t.revision);if(o())return void await v(r);n={phase:"probe",instance:r},r.channel.deliver(e,{classification:t.classification});return}if("probe"===n.phase){if(sr.safeParse(e).success)return void n.instance.channel.deliver(e,{classification:t.classification});n={phase:"pinned",era:"modern",instance:n.instance}}else{let e=await f("modern",t.revision);if(o())return void await v(e);n={phase:"pinned",era:"modern",instance:e}}if(await p(e)||o())return;n.instance.channel.deliver(e,{classification:t.classification});return;case"legacy":{if("reject"===a){cV(e)&&await m(e,t.reason,t.requestedVersion);return}if("probe"===n.phase){if(await (async e=>{r=e.channel;try{await e.channel.whenRequestsAnswered(3e3)||l(Error("Discarded the probe instance with requests still unanswered after 3000ms; continuing with the fallback")),await e.product.close()}catch(e){l(pE(e))}finally{r=void 0}})(n.instance),o())return;n={phase:"opening"}}let i=await f("legacy");if(o())return void await v(i);(n={phase:"pinned",era:"legacy",instance:i}).instance.channel.deliver(e);return}}},b=[],S=!1,$=async()=>{if(s||"closed"===n.phase)return;s=!0;let e=n;for(let e of(n={phase:"closed"},u.teardownAll()))await i.send(e).catch(e=>l(pE(e)));("probe"===e.phase||"pinned"===e.phase)&&await e.instance.product.close().catch(e=>l(pE(e))),await i.close().catch(e=>l(pE(e)))};i.onmessage=e=>{b.push(e),(async()=>{if(!S){S=!0;try{for(;b.length>0;){let e=b.shift();try{await _(e)}catch(t){cV(e)&&await c(e.id,cc.InternalError,"Internal server error"),l(pE(t))}}}finally{S=!1}}})()},i.onerror=e=>{l(e),("probe"===n.phase||"pinned"===n.phase)&&n.instance.channel.onerror?.(e)},i.onclose=()=>{if(s||"closed"===n.phase)return;s=!0;let e=n;n={phase:"closed"},("probe"===e.phase||"pinned"===e.phase)&&e.instance.product.close().catch(e=>l(pE(e)))},i.start().catch(e=>{throw l(pE(e)),e}).catch(()=>{})}(async()=>{let e=await async function(){let e=function(){let{instructions:e,...t}=fs;return new pp(t,{instructions:e,cacheHints:{}})}(),t=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fa(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fa(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(a);return fi(t),e}(),r=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw h4(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw h4(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(i);return h6(t),e}(),s=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw h5(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw h5(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(n);return h3(t),e}(),[c,u,d]=await Promise.all([t,r,s]);return async function(e,t,r,a){let i=await o?.(),n=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(i?.mcp),s=function(e){if(void 0!==e){if("function"!=typeof e)throw Error("src/middleware.ts must export authorize as a function");return e}}(i?.authorize),c;pT.clear();let u={};return!function(e,t,r,a){let i=e.server,n=i.setRequestHandler,s=a?{tools:new Map,prompts:new Map,resources:new Map,templates:new Map,uiOwners:new Map}:void 0,o=a&&s?function(e,t){let r=async(t,r,a)=>!r||await e(t,r,a)===!0;async function a(e,t,a){if(!Array.isArray(t))return t;let i=await Promise.all(t.map(t=>r(e,a(t),"list")));return t.filter((e,t)=>i[t])}return async(e,i)=>{switch(e.method){case"tools/call":{let{name:a}=e.params;if(!await r(e,t.tools.get(a),"call"))throw new cu(cc.InvalidParams,`Tool ${a} not found`);return i()}case"prompts/get":{let{name:a}=e.params;if(!await r(e,t.prompts.get(a),"get"))throw new cu(cc.InvalidParams,`Prompt ${a} not found`);return i()}case"resources/read":{let{uri:a}=e.params;if(!await r(e,pD(t,a),"read"))throw new cd(a);return i()}case"completion/complete":{let{ref:a}=e.params,n="ref/prompt"===a.type?t.prompts.get(a.name):[...t.templates.values()].find(({component:e})=>e.uriTemplate===a.uri)?.component??t.uiOwners.get(a.uri)??t.resources.get(a.uri);if(!await r(e,n,"complete"))throw new cu(cc.InvalidParams,"ref/prompt"===a.type?`Prompt ${a.name} not found`:`Resource template ${a.uri} not found`);return i()}case"tools/list":{let r=await i();return{...r,tools:await a(e,r.tools,e=>t.tools.get(e.name))}}case"prompts/list":{let r=await i();return{...r,prompts:await a(e,r.prompts,e=>t.prompts.get(e.name))}}case"resources/list":{let r=await i();return{...r,resources:await a(e,r.resources,e=>pD(t,e.uri,!0))}}case"resources/templates/list":{let r=await i();return{...r,resourceTemplates:await a(e,r.resourceTemplates,e=>t.templates.get(e.name)?.component)}}default:return i()}}}(a,s):void 0,l=hB(o?[o,...t]:t),c=o?hB([o]):void 0;i.setRequestHandler=(e,...t)=>{if(1===t.length&&"function"==typeof t[0]){let r=t[0];hW.has(e)?t[0]=(e,t)=>l({method:e.method,params:e.params??{}},t,()=>r(e,t)):"tools/call"===e&&c&&s&&(t[0]=(e,t)=>{let a=s.tools.get(e.params.name);return a?c({method:"tools/call",params:{name:e.params.name,arguments:e.params.arguments??{}},tool:{metadata:a.metadata}},t,()=>r(e,t)):r(e,t)})}Reflect.apply(n,i,[e,...t])};try{if(s){let t={registerTool:e.registerTool,registerPrompt:e.registerPrompt,registerResource:e.registerResource};e.registerTool=(r,a,...i)=>{let n=hK({name:r,description:a.description??"",annotations:a.annotations,icons:a.icons,tags:pZ(a._meta),_meta:a._meta});return s.tools.set(r,Object.freeze({type:"tool",name:r,metadata:n})),Reflect.apply(t.registerTool,e,[r,a,...i])},e.registerPrompt=(r,a,...i)=>{let n=hK({name:r,title:a.title,description:a.description,icons:a.icons,tags:pZ(a._meta),_meta:a._meta});return s.prompts.set(r,Object.freeze({type:"prompt",name:r,metadata:n})),Reflect.apply(t.registerPrompt,e,[r,a,...i])},e.registerResource=(r,a,i,...n)=>{let o=hK({name:r,title:i.title,description:i.description,icons:i.icons,mimeType:i.mimeType,tags:pZ(i._meta),_meta:i._meta});if("string"==typeof a)s.resources.set(a,Object.freeze({type:"resource",name:r,uri:a,metadata:o}));else{let e=a.uriTemplate.toString();s.templates.set(r,{component:Object.freeze({type:"resourceTemplate",name:r,uriTemplate:e,metadata:o}),template:a})}return Reflect.apply(t.registerResource,e,[r,a,i,...n])};try{r(async(e,t,r)=>{let i=s.resources.get(t);return!i||await a(e,i,r)===!0})}finally{Object.assign(e,t)}for(let[e,t]of pT.getAll()){let r=s.tools.get(e);r&&s.uiOwners.set(t.uri,r)}}else r()}finally{i.setRequestHandler=n}}(e,n,i=>{var s,o;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let s,o,l,c,u={name:h1(a),description:"No description provided"},{default:d,metadata:p,schema:m,outputSchema:h}=t;if("object"==typeof p&&null!==p&&Object.assign(u,p),!1===u.enabled)return;if("function"==typeof d&&"__x402"in d){let e=global.__XMCP_X402_REGISTRY;e&&e.set(u.name,d.__x402)}let f={};if(hL(m)?(!function(e,t){let{type:r}=hZ(e,"draft-2020-12","input");if(void 0!==r&&"object"!==r)throw Error(`Invalid schema for tool "${t}": tool input schemas must describe an object, got JSON Schema type ${JSON.stringify(r)}.`)}(m,u.name),f=m):h0(m)?f=m:null!=m&&console.warn(`Invalid schema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`),null!=h)if(hL(h))s=h;else if(h0(h))s=h;else throw Error(`Invalid outputSchema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`);u.annotations={...u.annotations??{}},void 0===u.annotations.title&&(u.annotations.title=u.name),u._meta={...pj(u)._meta};let g=hG(a),y=!!(i=u._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,v=u._meta;if(y){let e=`ui://app/${u.name}.html`;u._meta.ui||(u._meta.ui={}),u._meta.ui.resourceUri||(u._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))hQ.includes(e)?i[e]=t:hX.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(v);v=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),pT.add(u.name,{name:u.name,uri:e,handler:d,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let _=hY(v),b=y?_:void 0;o=hG(a)&&y?async(e,t)=>({content:[{type:"text",text:""}],_meta:b,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let s,o,l=e(i,(s=hJ(n),o=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:o?{headers:o}:void 0,clientInfo:s,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;p9(e,"Elicitation request must be a plain object."),p2(e,pW,"URL elicitation"),p4(e.message,"URL elicitation requires a string message."),p6(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),p6(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){p9(e,"Elicitation request must be a plain object."),p2(e,pK,"Form elicitation"),p4(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(p9(t,"Form elicitation requires a flat object schema."),p2(t,pG,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(p9(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(p9(t,`Form elicitation field "${e}" must be a plain object.`),p5(t.title,`Form elicitation field "${e}" title must be a string.`),p5(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(p2(t,pQ,`Form elicitation field "${e}"`),p8(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&p8(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(p5(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){p2(t,pY,`Form elicitation field "${e}"`),p3(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),p3(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),p5(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(p5(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!p1.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(p1).join(", ")}.`);return}if("boolean"===t.type){if(p2(t,pX,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){p2(t,p0,`Form elicitation field "${e}"`),p3(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),p3(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),p3(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof lD&&e.code===lZ.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mr(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>me.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!p7.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mr(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mr(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mt.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof lD&&e.code===lZ.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),cF(l))return l;if(r&&hL(r)&&void 0!==l&&!hU(l)){if(await hF(l,r,a,"returned data that does not match outputSchema"),"string"==typeof l||"number"==typeof l)return{content:[{type:"text",text:`${l}`}],structuredContent:l};l={structuredContent:l}}if("string"==typeof l||"number"==typeof l){if(r&&!hL(r)){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(l),{content:[{type:"text",text:"number"==typeof l?`${l}`:l}],structuredContent:{[t]:l}}}catch{}}}return hH(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof l?`${l}`:l}]}}if(r&&l&&"object"==typeof l&&!Array.isArray(l)&&!hU(l)&&(await hF(l,r,a,"returned data that does not match outputSchema"),l={structuredContent:l}),l&&"object"==typeof l&&"_meta"in l&&!("content"in l)&&!("structuredContent"in l)){let e=l._meta;if(hH(e))return{content:[{type:"text",text:""}],_meta:e}}if(!l||"object"!=typeof l){let e=null===l?"null":typeof l,t=void 0===l?"undefined":null===l?"null":"object"==typeof l?JSON.stringify(l,null,2):String(l);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
|
|
82
|
+
-> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),fn="u"<typeof s?[]:s??[],fs={name:"svgt",version:"0.1.0",description:"Transform SVG into frontend components.",icons:[]};var fo=l(8717);l.n(fo)().config(),pH({clientInfo:void 0},()=>{let e;!function(e,t={}){let r,a=t.legacy??"serve",i=t.transport??new pR,n={phase:"opening"},s=!1,o=()=>s||"closed"===n.phase,l=e=>{try{t.onerror?.(e)}catch{}},c=(e,t,r,a)=>i.send({jsonrpc:"2.0",id:e,error:{code:t,message:r,...void 0!==a&&{data:a}}}).catch(e=>l(pE(e))),u=new pk(t.maxSubscriptions??1024),d=e=>{if(!sr.safeParse(e).success)return;let t=u.routeOutbound(e);if("passthrough"!==t){for(let e of t)i.send({jsonrpc:"2.0",...e}).catch(e=>l(pE(e)));return"handled"}},p=async e=>{if(cV(e)&&"subscriptions/listen"===e.method){let t,r=cz(e.params),a=cM(e.params)?(void 0===r?[]:cZ(r))[0]:{key:"_meta",problem:"the per-request envelope is required on protocol revision 2026-07-28"},n=cL(e.params);if(void 0!==a)t={jsonrpc:"2.0",id:e.id,error:{code:-32602,message:`Invalid _meta envelope: ${a.key}: ${a.problem}`}};else if(void 0!==n&&lH.includes(n))t=u.serve(e);else{let r=new cm({supported:[...lH],requested:n??"unknown"});t={jsonrpc:"2.0",id:e.id,error:{code:r.code,message:r.message,data:r.data}}}return await i.send("error"in t?t:{jsonrpc:"2.0",method:t.method,params:t.params}).catch(e=>l(pE(e))),!0}if(sr.safeParse(e).success&&"notifications/cancelled"===e.method){let t=e.params?.requestId;if(void 0!==t&&u.cancel(t))return!0}return!1},m=(e,t,r)=>{let a=function(e,t){switch(e.reason){case"http-method":return cY("http-method","modern-only-method-not-allowed",405,new cu(-32e3,"Method not allowed."),!0);case"batch":return cY("jsonrpc-shape","modern-only-batch-not-supported",400,new cu(cc.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return cY("jsonrpc-shape","modern-only-response-post",400,new cu(cc.InvalidRequest,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"),!0);case"notification":return;case"initialize":case"no-claim":{let r=e.requestedVersion;return cY("era-classification","modern-only-missing-envelope",400,void 0===r?new cu(cc.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new cm({supported:[...t],requested:r}),!0)}}}({kind:"legacy",reason:t,...void 0!==r&&{requestedVersion:r}},lH);return void 0===a?Promise.resolve():(l(Error(`Rejected 2025-era request on a modern-only stdio connection (${a.cell}): ${a.message}`)),c(e.id,a.code,a.message,a.data))},f=async(t,a)=>{let n=await e({era:t}),o=n instanceof pp?n.server:n;"modern"===t&&(h(o,a),g(o,lH),u.setServerCapabilities(o.getCapabilities(),y(o)));let l=new pP(i,()=>{s||l===r||$()},"modern"===t?d:void 0);return await n.connect(l),{product:n,channel:l}},v=e=>e.product.close().catch(e=>l(pE(e))),_=async e=>{if("closed"===n.phase)return;if("pinned"===n.phase)return"modern"===n.era&&cV(e)&&"initialize"===e.method&&!cQ(e.params)?void await m(e,"initialize",null!==e.params&&"object"==typeof e.params&&"string"==typeof e.params.protocolVersion?e.params.protocolVersion:void 0):void("modern"===n.era&&await p(e)||o()||n.instance.channel.deliver(e));if(!cV(e)&&!sr.safeParse(e).success)return void l(Error("Discarded a JSON-RPC response received before the connection negotiated an era"));let t=function(e){let t=e.params;if("initialize"===e.method&&!cQ(t)){let e=null!==t&&"object"==typeof t&&"string"==typeof t.protocolVersion?t.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...void 0!==e&&{requestedVersion:e}}}if(!cM(t))return{kind:"legacy",reason:"no-claim"};let r=cz(t),a=(void 0===r?[]:cZ(r))[0];if(void 0!==a)return{kind:"invalid-envelope",issue:a};let i=cL(t);return void 0!==i&&lH.includes(i)?{kind:"modern",revision:i,classification:{era:"modern",revision:i}}:{kind:"unsupported-revision",requested:i??"unknown"}}(e);switch(t.kind){case"invalid-envelope":{let r=`Invalid _meta envelope for protocol revision 2026-07-28: ${t.issue.key}: ${t.issue.problem}`;cV(e)?await c(e.id,cc.InvalidParams,r,{envelope:t.issue}):l(Error(`Discarded a notification with a malformed envelope: ${r}`));return}case"unsupported-revision":if(cV(e)){let r=new cm({supported:[...lH],requested:t.requested});l(r),await c(e.id,r.code,r.message,r.data)}else l(Error(`Discarded a notification claiming unsupported protocol revision ${t.requested}`));return;case"modern":if(cV(e)&&"server/discover"===e.method){if("probe"===n.phase)return void n.instance.channel.deliver(e,{classification:t.classification});let r=await f("modern",t.revision);if(o())return void await v(r);n={phase:"probe",instance:r},r.channel.deliver(e,{classification:t.classification});return}if("probe"===n.phase){if(sr.safeParse(e).success)return void n.instance.channel.deliver(e,{classification:t.classification});n={phase:"pinned",era:"modern",instance:n.instance}}else{let e=await f("modern",t.revision);if(o())return void await v(e);n={phase:"pinned",era:"modern",instance:e}}if(await p(e)||o())return;n.instance.channel.deliver(e,{classification:t.classification});return;case"legacy":{if("reject"===a){cV(e)&&await m(e,t.reason,t.requestedVersion);return}if("probe"===n.phase){if(await (async e=>{r=e.channel;try{await e.channel.whenRequestsAnswered(3e3)||l(Error("Discarded the probe instance with requests still unanswered after 3000ms; continuing with the fallback")),await e.product.close()}catch(e){l(pE(e))}finally{r=void 0}})(n.instance),o())return;n={phase:"opening"}}let i=await f("legacy");if(o())return void await v(i);(n={phase:"pinned",era:"legacy",instance:i}).instance.channel.deliver(e);return}}},b=[],S=!1,$=async()=>{if(s||"closed"===n.phase)return;s=!0;let e=n;for(let e of(n={phase:"closed"},u.teardownAll()))await i.send(e).catch(e=>l(pE(e)));("probe"===e.phase||"pinned"===e.phase)&&await e.instance.product.close().catch(e=>l(pE(e))),await i.close().catch(e=>l(pE(e)))};i.onmessage=e=>{b.push(e),(async()=>{if(!S){S=!0;try{for(;b.length>0;){let e=b.shift();try{await _(e)}catch(t){cV(e)&&await c(e.id,cc.InternalError,"Internal server error"),l(pE(t))}}}finally{S=!1}}})()},i.onerror=e=>{l(e),("probe"===n.phase||"pinned"===n.phase)&&n.instance.channel.onerror?.(e)},i.onclose=()=>{if(s||"closed"===n.phase)return;s=!0;let e=n;n={phase:"closed"},("probe"===e.phase||"pinned"===e.phase)&&e.instance.product.close().catch(e=>l(pE(e)))},i.start().catch(e=>{throw l(pE(e)),e}).catch(()=>{})}(async()=>{let e=await async function(){let e=function(){let{instructions:e,...t}=fs;return new pp(t,{instructions:e,cacheHints:{}})}(),t=async function(){let{toolModules:e,skippedTools:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw fa(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw fa(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default tool handler."}}:{skipped:!1,path:e,toolModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.toolModule)}return{toolModules:t,skippedTools:r}}(a);return fi(t),e}(),r=async function(){let{promptModules:e,skippedPrompts:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw h4(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw h4(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default prompt handler."}}:{skipped:!1,path:e,promptModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.promptModule)}return{promptModules:t,skippedPrompts:r}}(i);return h6(t),e}(),s=async function(){let{resourceModules:e,skippedResources:t}=await async function(e){let t=new Map,r=[];for(let a of(await Promise.all(Object.entries(e).map(async([e,t])=>{let r=await t(),a=function(e,t){if("object"!=typeof e||null===e)throw h5(t);let r=Object.keys(e),a=e.default,i=r.filter(e=>"__esModule"!==e);if(0===r.length||1===i.length&&"default"===i[0]&&"object"==typeof a&&null!==a&&0===Object.keys(a).length)return"empty";if(!("default"in e)||void 0===e.default)return"missing-default";if("function"!=typeof e.default)throw h5(t);return"valid"}(r,e);return"empty"===a?{skipped:!0,issue:{path:e,message:"File is empty."}}:"missing-default"===a?{skipped:!0,issue:{path:e,message:"File does not export a default resource handler."}}:{skipped:!1,path:e,resourceModule:r}})))){if(a.skipped){r.push(a.issue);continue}t.set(a.path,a.resourceModule)}return{resourceModules:t,skippedResources:r}}(n);return h3(t),e}(),[c,u,d]=await Promise.all([t,r,s]);return async function(e,t,r,a){let i=await o?.(),n=function(e){if(void 0===e)return[];let t=Array.isArray(e)?[...e]:[e];if(!t.every(e=>"function"==typeof e))throw Error("src/middleware.ts must export mcp as a function or an array of functions");return t}(i?.mcp),s=function(e){if(void 0!==e){if("function"!=typeof e)throw Error("src/middleware.ts must export authorize as a function");return e}}(i?.authorize),c;pT.clear();let u={};return!function(e,t,r,a){let i=e.server,n=i.setRequestHandler,s=a?{tools:new Map,prompts:new Map,resources:new Map,templates:new Map,uiOwners:new Map}:void 0,o=a&&s?function(e,t){let r=async(t,r,a)=>!r||await e(t,r,a)===!0;async function a(e,t,a){if(!Array.isArray(t))return t;let i=await Promise.all(t.map(t=>r(e,a(t),"list")));return t.filter((e,t)=>i[t])}return async(e,i)=>{switch(e.method){case"tools/call":{let{name:a}=e.params;if(!await r(e,t.tools.get(a),"call"))throw new cu(cc.InvalidParams,`Tool ${a} not found`);return i()}case"prompts/get":{let{name:a}=e.params;if(!await r(e,t.prompts.get(a),"get"))throw new cu(cc.InvalidParams,`Prompt ${a} not found`);return i()}case"resources/read":{let{uri:a}=e.params;if(!await r(e,pD(t,a),"read"))throw new cd(a);return i()}case"completion/complete":{let{ref:a}=e.params,n="ref/prompt"===a.type?t.prompts.get(a.name):[...t.templates.values()].find(({component:e})=>e.uriTemplate===a.uri)?.component??t.uiOwners.get(a.uri)??t.resources.get(a.uri);if(!await r(e,n,"complete"))throw new cu(cc.InvalidParams,"ref/prompt"===a.type?`Prompt ${a.name} not found`:`Resource template ${a.uri} not found`);return i()}case"tools/list":{let r=await i();return{...r,tools:await a(e,r.tools,e=>t.tools.get(e.name))}}case"prompts/list":{let r=await i();return{...r,prompts:await a(e,r.prompts,e=>t.prompts.get(e.name))}}case"resources/list":{let r=await i();return{...r,resources:await a(e,r.resources,e=>pD(t,e.uri,!0))}}case"resources/templates/list":{let r=await i();return{...r,resourceTemplates:await a(e,r.resourceTemplates,e=>t.templates.get(e.name)?.component)}}default:return i()}}}(a,s):void 0,l=hB(o?[o,...t]:t),c=o?hB([o]):void 0;i.setRequestHandler=(e,...t)=>{if(1===t.length&&"function"==typeof t[0]){let r=t[0];hW.has(e)?t[0]=(e,t)=>l({method:e.method,params:e.params??{}},t,()=>r(e,t)):"tools/call"===e&&c&&s&&(t[0]=(e,t)=>{let a=s.tools.get(e.params.name);return a?c({method:"tools/call",params:{name:e.params.name,arguments:e.params.arguments??{}},tool:{metadata:a.metadata}},t,()=>r(e,t)):r(e,t)})}Reflect.apply(n,i,[e,...t])};try{if(s){let t={registerTool:e.registerTool,registerPrompt:e.registerPrompt,registerResource:e.registerResource};e.registerTool=(r,a,...i)=>{let n=hK({name:r,description:a.description??"",annotations:a.annotations,icons:a.icons,tags:pZ(a._meta),_meta:a._meta});return s.tools.set(r,Object.freeze({type:"tool",name:r,metadata:n})),Reflect.apply(t.registerTool,e,[r,a,...i])},e.registerPrompt=(r,a,...i)=>{let n=hK({name:r,title:a.title,description:a.description,icons:a.icons,tags:pZ(a._meta),_meta:a._meta});return s.prompts.set(r,Object.freeze({type:"prompt",name:r,metadata:n})),Reflect.apply(t.registerPrompt,e,[r,a,...i])},e.registerResource=(r,a,i,...n)=>{let o=hK({name:r,title:i.title,description:i.description,icons:i.icons,mimeType:i.mimeType,tags:pZ(i._meta),_meta:i._meta});if("string"==typeof a)s.resources.set(a,Object.freeze({type:"resource",name:r,uri:a,metadata:o}));else{let e=a.uriTemplate.toString();s.templates.set(r,{component:Object.freeze({type:"resourceTemplate",name:r,uriTemplate:e,metadata:o}),template:a})}return Reflect.apply(t.registerResource,e,[r,a,i,...n])};try{r(async(e,t,r)=>{let i=s.resources.get(t);return!i||await a(e,i,r)===!0})}finally{Object.assign(e,t)}for(let[e,t]of pT.getAll()){let r=s.tools.get(e);r&&s.uiOwners.set(t.uri,r)}}else r()}finally{i.setRequestHandler=n}}(e,n,i=>{var s,o;!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let s,o,l,c,u={name:h1(a),description:"No description provided"},{default:d,metadata:p,schema:m,outputSchema:h}=t;if("object"==typeof p&&null!==p&&Object.assign(u,p),!1===u.enabled)return;if("function"==typeof d&&"__x402"in d){let e=global.__XMCP_X402_REGISTRY;e&&e.set(u.name,d.__x402)}let f={};if(hL(m)?(!function(e,t){let{type:r}=hZ(e,"draft-2020-12","input");if(void 0!==r&&"object"!==r)throw Error(`Invalid schema for tool "${t}": tool input schemas must describe an object, got JSON Schema type ${JSON.stringify(r)}.`)}(m,u.name),f=m):h0(m)?f=m:null!=m&&console.warn(`Invalid schema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`),null!=h)if(hL(h))s=h;else if(h0(h))s=h;else throw Error(`Invalid outputSchema for tool "${u.name}" at ${a}. Expected a zod schema or Record<string, z.ZodType>`);u.annotations={...u.annotations??{}},void 0===u.annotations.title&&(u.annotations.title=u.name),u._meta={...pj(u)._meta};let g=hG(a),y=!!(i=u._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||g,v=u._meta;if(y){let e=`ui://app/${u.name}.html`;u._meta.ui||(u._meta.ui={}),u._meta.ui.resourceUri||(u._meta.ui.resourceUri=e);let t=function(e){let t={},r={};if(e.ui&&"object"==typeof e.ui){let a=e.ui,i={},n={};for(let[e,t]of Object.entries(a))hQ.includes(e)?i[e]=t:hX.includes(e)?n[e]=t:i[e]=t;Object.keys(i).length>0&&(t.ui=i),Object.keys(n).length>0&&(r.ui=n)}for(let[r,a]of Object.entries(e))"ui"!==r&&(t[r]=a);return{toolMeta:t,resourceMeta:r}}(v);v=t.toolMeta;let r=t.resourceMeta;r.ui=r.ui||{},r.ui.csp=r.ui.csp||{},r.ui.csp.resourceDomains=r.ui.csp.resourceDomains||[],r.ui.csp.resourceDomains.includes("https://esm.sh")||r.ui.csp.resourceDomains.push("https://esm.sh"),pT.add(u.name,{name:u.name,uri:e,handler:d,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:g?a:void 0})}let _=hY(v),b=y?_:void 0;o=hG(a)&&y?async(e,t)=>({content:[{type:"text",text:""}],_meta:b,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let s,o,l=e(i,(s=hJ(n),o=function(e){if(!e)return;let t={};return e.headers.forEach((e,r)=>{t[r]=e}),t}(n.http?.req),{signal:n.mcpReq.signal,authInfo:n.http?.authInfo,sessionId:n.sessionId,_meta:n.mcpReq._meta,requestId:n.mcpReq.id,requestInfo:o?{headers:o}:void 0,clientInfo:s,sendNotification:e=>n.mcpReq.notify(e),sendRequest:(e,t,r)=>n.mcpReq.send(e,t,r),elicit:(e,t)=>(async function(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;p9(e,"Elicitation request must be a plain object."),p2(e,pW,"URL elicitation"),p4(e.message,"URL elicitation requires a string message."),p6(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),p6(e.url,"URL elicitation requires a non-empty URL.");try{t=new URL(e.url)}catch{throw Error("URL elicitation requires a valid http or https URL.")}if("http:"!==t.protocol&&"https:"!==t.protocol)throw Error("URL elicitation requires a valid http or https URL.")}(e),e;if("form"!==t)throw Error(`Unsupported elicitation mode "${String(e.mode)}". Expected "form" or "url".`);return function(e){p9(e,"Elicitation request must be a plain object."),p2(e,pK,"Form elicitation"),p4(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(p9(t,"Form elicitation requires a flat object schema."),p2(t,pG,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(p9(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(p9(t,`Form elicitation field "${e}" must be a plain object.`),p5(t.title,`Form elicitation field "${e}" title must be a string.`),p5(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(p2(t,pQ,`Form elicitation field "${e}"`),p8(t.enum,`Form elicitation field "${e}" enum values must be strings.`),r=t.enumNames,a=`Form elicitation field "${e}" enumNames must be strings.`,void 0!==r&&p8(r,a),void 0!==t.enumNames&&t.enumNames.length!==t.enum.length)throw Error(`Form elicitation field "${e}" enumNames length must match enum length.`);if(p5(t.default,`Form elicitation field "${e}" default must be a string.`),void 0!==t.default&&!t.enum.includes(t.default))throw Error(`Form elicitation field "${e}" default must be one of its enum values.`);return}if("string"===t.type&&!("enum"in t)){p2(t,pY,`Form elicitation field "${e}"`),p3(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),p3(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),p5(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(p5(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!p1.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(p1).join(", ")}.`);return}if("boolean"===t.type){if(p2(t,pX,`Form elicitation field "${e}"`),void 0!==t.default&&"boolean"!=typeof t.default)throw Error(`Form elicitation field "${e}" default must be a boolean.`);return}if("number"===t.type||"integer"===t.type){p2(t,p0,`Form elicitation field "${e}"`),p3(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),p3(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),p3(t.default,`Form elicitation field "${e}" default must be a number.`);return}throw Error(`Form elicitation field "${e}" uses unsupported type "${String(t.type)}". Supported types are string, boolean, number, integer, and string enums.`)}(e,r);if(void 0!==t.required){if(!Array.isArray(t.required)||t.required.some(e=>"string"!=typeof e))throw Error("Form elicitation schema required fields must be a string array.");for(let e of t.required)if(!(e in t.properties))throw Error(`Form elicitation schema required field "${e}" is not defined in properties.`)}}(e),{...e,mode:"form"}}(t);try{let t=await e.mcpReq.elicitInput(a,r);return{...t,content:t.content??void 0}}catch(e){if(e instanceof lD&&e.code===lZ.MethodNotSupportedByProtocolVersion)throw Error("extra.elicit() is not available on protocol revision 2026-07-28: server-initiated elicitation was replaced by multi round-trip requests. Return inputRequired({ ... }) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),sample:(e,t)=>(async function(e,t,r){let a=function(e){mr(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>me.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!p7.has(e));if(a.length>0)throw Error(`Sampling request includes unsupported key(s): ${a.join(", ")}.`);if(!Array.isArray(e.messages)||0===e.messages.length)throw Error("Sampling requires at least one message.");for(let[t,r]of e.messages.entries())!function(e,t){if(mr(t,`Sampling message at index ${e} must be a plain object.`),"user"!==t.role&&"assistant"!==t.role)throw Error(`Sampling message at index ${e} requires role "user" or "assistant".`);let r=t.content;mr(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mt.has(a))throw Error(`Sampling message at index ${e} uses unsupported content type "${String(a)}". Supported types are text, image, and audio.`);if("text"===a&&"string"!=typeof r.text)throw Error(`Sampling message at index ${e} requires string text content.`);if(("image"===a||"audio"===a)&&("string"!=typeof r.data||"string"!=typeof r.mimeType))throw Error(`Sampling message at index ${e} requires base64 data and a mimeType.`)}(t,r);if("number"!=typeof e.maxTokens)throw Error("Sampling requires a numeric maxTokens.");return e}(t);try{return await e.mcpReq.requestSampling(a,r)}catch(e){if(e instanceof lD&&e.code===lZ.MethodNotSupportedByProtocolVersion)throw Error("extra.sample() is not available on protocol revision 2026-07-28: server-initiated sampling was replaced by multi round-trip requests. Return inputRequired({ ... }) with inputRequired.createMessage(...) from the tool handler instead (re-exported from xmcp); the client fulfils the embedded requests and retries the tool call.");throw e}})(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),cF(l))return l;if(r&&hL(r)&&void 0!==l&&!hU(l)){if(await hF(l,r,a,"returned data that does not match outputSchema"),"string"==typeof l||"number"==typeof l)return{content:[{type:"text",text:`${l}`}],structuredContent:l};l={structuredContent:l}}if("string"==typeof l||"number"==typeof l){if(r&&!hL(r)){let e=Object.entries(r);if(1===e.length){let[t,r]=e[0];try{return r.parse(l),{content:[{type:"text",text:"number"==typeof l?`${l}`:l}],structuredContent:{[t]:l}}}catch{}}}return hH(t)?{content:[{type:"text",text:""}],structuredContent:{args:i},_meta:t}:{content:[{type:"text",text:"number"==typeof l?`${l}`:l}]}}if(r&&l&&"object"==typeof l&&!Array.isArray(l)&&!hU(l)&&(await hF(l,r,a,"returned data that does not match outputSchema"),l={structuredContent:l}),l&&"object"==typeof l&&"_meta"in l&&!("content"in l)&&!("structuredContent"in l)){let e=l._meta;if(hH(e))return{content:[{type:"text",text:""}],_meta:e}}if(!l||"object"!=typeof l){let e=null===l?"null":typeof l,t=void 0===l?"undefined":null===l?"null":"object"==typeof l?JSON.stringify(l,null,2):String(l);throw Error(`Tool handler must return a CallToolResult, string, or number. Got ${e}: ${t}
|
|
83
83
|
|
|
84
84
|
Expected CallToolResult format:
|
|
85
85
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svgt/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "An MCP server to transform SVG into frontend components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,13 +20,6 @@
|
|
|
20
20
|
"bin": {
|
|
21
21
|
"svgt-mcp": "./dist/stdio.js"
|
|
22
22
|
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "xmcp build",
|
|
25
|
-
"dev": "xmcp dev",
|
|
26
|
-
"start-http": "node dist/http.js",
|
|
27
|
-
"start-stdio": "node dist/stdio.js",
|
|
28
|
-
"check": "tsc --noEmit"
|
|
29
|
-
},
|
|
30
23
|
"keywords": [
|
|
31
24
|
"svg",
|
|
32
25
|
"mcp",
|
|
@@ -34,14 +27,21 @@
|
|
|
34
27
|
"frontend"
|
|
35
28
|
],
|
|
36
29
|
"devDependencies": {
|
|
37
|
-
"@svgt/core": "
|
|
38
|
-
"@types/node": "
|
|
30
|
+
"@svgt/core": "0.2.0",
|
|
31
|
+
"@types/node": "24.19.2",
|
|
39
32
|
"@xmcp-dev/compiler": "1.13.4",
|
|
40
|
-
"typescript": "
|
|
33
|
+
"typescript": "6.0.3",
|
|
41
34
|
"xmcp": "1.13.4",
|
|
42
35
|
"zod": "4.6.7"
|
|
43
36
|
},
|
|
44
37
|
"engines": {
|
|
45
38
|
"node": ">=22.13"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "xmcp build",
|
|
42
|
+
"dev": "xmcp dev",
|
|
43
|
+
"start-http": "node dist/http.js",
|
|
44
|
+
"start-stdio": "node dist/stdio.js",
|
|
45
|
+
"check": "tsc --noEmit"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|