xmcp 1.2.0 → 1.4.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.
@@ -69,13 +69,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
69
69
  ]))`;continue}else if("$"===a[e]){i+=`($|(?=[\r
70
70
  ]))`;continue}}if(r.s&&"."===a[e]){i+=o?`${a[e]}\r
71
71
  `:`[${a[e]}\r
72
- ]`;continue}i+=a[e],"\\"===a[e]?n=!0:o&&"]"===a[e]?o=!1:o||"["!==a[e]||(o=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function pz(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===k.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:pL(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??pf(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};let r={type:"object",additionalProperties:pL(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===k.ZodString&&e.keyType._def.checks?.length){let{type:a,...i}=pj(e.keyType._def,t);return{...r,propertyNames:i}}if(e.keyType?._def.typeName===k.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===k.ZodBranded&&e.keyType._def.type._def.typeName===k.ZodString&&e.keyType._def.type._def.checks?.length){let{type:a,...i}=pv(e.keyType._def,t);return{...r,propertyNames:i}}return r}let pA={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},pM=(e,t)=>{let r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,r)=>pL(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return r.length?{anyOf:r}:void 0};function pL(e,t,r=!1){let a=t.seen.get(e);if(t.override){let i=t.override?.(e,t,a,r);if(i!==di)return i}if(a&&!r){let e=pZ(a,t);if(void 0!==e)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let n=((e,t,r)=>{switch(t){case k.ZodString:return pj(e,r);case k.ZodNumber:let a={type:"number"};if(!e.checks)return a;for(let t of e.checks)switch(t.kind){case"int":a.type="integer",pg(a,"type",t.message,r);break;case"min":"jsonSchema7"===r.target?t.inclusive?py(a,"minimum",t.value,t.message,r):py(a,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(a.exclusiveMinimum=!0),py(a,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?py(a,"maximum",t.value,t.message,r):py(a,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(a.exclusiveMaximum=!0),py(a,"maximum",t.value,t.message,r));break;case"multipleOf":py(a,"multipleOf",t.value,t.message,r)}return a;case k.ZodObject:return function(e,t){let r="openAi"===t.target,a={type:"object",properties:{}},i=[],n=e.shape();for(let e in n){let o=n[e];if(void 0===o||void 0===o._def)continue;let s=function(e){try{return e.isOptional()}catch{return!0}}(o);s&&r&&("ZodOptional"===o._def.typeName&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),s=!1);let l=pL(o._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==l&&(a.properties[e]=l,s||i.push(e))}i.length&&(a.required=i);let o=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return pL(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==o&&(a.additionalProperties=o),a}(e,r);case k.ZodBigInt:let i={type:"integer",format:"int64"};if(!e.checks)return i;for(let t of e.checks)switch(t.kind){case"min":"jsonSchema7"===r.target?t.inclusive?py(i,"minimum",t.value,t.message,r):py(i,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(i.exclusiveMinimum=!0),py(i,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?py(i,"maximum",t.value,t.message,r):py(i,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(i.exclusiveMaximum=!0),py(i,"maximum",t.value,t.message,r));break;case"multipleOf":py(i,"multipleOf",t.value,t.message,r)}return i;case k.ZodBoolean:return{type:"boolean"};case k.ZodDate:return function e(t,r,a){let i=a??r.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((a,i)=>e(t,r,a))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var n=t,o=r;let s={type:"integer",format:"unix-time"};if("openApi3"===o.target)return s;for(let e of n.checks)switch(e.kind){case"min":py(s,"minimum",e.value,e.message,o);break;case"max":py(s,"maximum",e.value,e.message,o)}return s}}(e,r);case k.ZodUndefined:return{not:pf(r)};case k.ZodNull:return"openApi3"===r.target?{enum:["null"],nullable:!0}:{type:"null"};case k.ZodArray:let n;return n={type:"array"},e.type?._def&&e.type?._def?.typeName!==k.ZodAny&&(n.items=pL(e.type._def,{...r,currentPath:[...r.currentPath,"items"]})),e.minLength&&py(n,"minItems",e.minLength.value,e.minLength.message,r),e.maxLength&&py(n,"maxItems",e.maxLength.value,e.maxLength.message,r),e.exactLength&&(py(n,"minItems",e.exactLength.value,e.exactLength.message,r),py(n,"maxItems",e.exactLength.value,e.exactLength.message,r)),n;case k.ZodUnion:case k.ZodDiscriminatedUnion:if("openApi3"===r.target)return pM(e,r);let o=e.options instanceof Map?Array.from(e.options.values()):e.options;if(o.every(e=>e._def.typeName in pA&&(!e._def.checks||!e._def.checks.length))){let e=o.reduce((e,t)=>{let r=pA[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e},[]);return{type:e.length>1?e:e[0]}}if(o.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){let e=o.reduce((e,t)=>{let r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===o.length){let t=e.filter((e,t,r)=>r.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:o.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(o.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:o.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return pM(e,r);case k.ZodIntersection:let s,l,c;return s=[pL(e.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),pL(e.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(e=>!!e),l="jsonSchema2019-09"===r.target?{unevaluatedProperties:!1}:void 0,c=[],s.forEach(e=>{if((!("type"in e)||"string"!==e.type)&&"allOf"in e)c.push(...e.allOf),void 0===e.unevaluatedProperties&&(l=void 0);else{let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){let{additionalProperties:r,...a}=e;t=a}else l=void 0;c.push(t)}}),c.length?{allOf:c,...l}:void 0;case k.ZodTuple:return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,t)=>pL(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:pL(e.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,t)=>pL(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])};case k.ZodRecord:return pz(e,r);case k.ZodLiteral:let u;return"bigint"!=(u=typeof e.value)&&"number"!==u&&"boolean"!==u&&"string"!==u?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===r.target?{type:"bigint"===u?"integer":u,enum:[e.value]}:{type:"bigint"===u?"integer":u,const:e.value};case k.ZodEnum:return{type:"string",enum:Array.from(e.values)};case k.ZodNativeEnum:let d,p,m;return d=e.values,{type:1===(m=Array.from(new Set((p=Object.keys(e.values).filter(e=>"number"!=typeof d[d[e]]).map(e=>d[e])).map(e=>typeof e)))).length?"string"===m[0]?"string":"number":["string","number"],enum:p};case k.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===r.target?{type:pA[e.innerType._def.typeName],nullable:!0}:{type:[pA[e.innerType._def.typeName],"null"]};if("openApi3"===r.target){let t=pL(e.innerType._def,{...r,currentPath:[...r.currentPath]});return t&&"$ref"in t?{allOf:[t],nullable:!0}:t&&{...t,nullable:!0}}let h=pL(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return h&&{anyOf:[h,{type:"null"}]};case k.ZodOptional:if(r.currentPath.toString()===r.propertyPath?.toString())return pL(e.innerType._def,r);let f=pL(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return f?{anyOf:[{not:pf(r)},f]}:pf(r);case k.ZodMap:if("record"===r.mapStrategy)return pz(e,r);return{type:"array",maxItems:125,items:{type:"array",items:[pL(e.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||pf(r),pL(e.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||pf(r)],minItems:2,maxItems:2}};case k.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:pL(e.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})},e.minSize&&py(g,"minItems",e.minSize.value,e.minSize.message,r),e.maxSize&&py(g,"maxItems",e.maxSize.value,e.maxSize.message,r),g;case k.ZodLazy:return()=>e.getter()._def;case k.ZodPromise:return pL(e.type._def,r);case k.ZodNaN:case k.ZodNever:return"openAi"===r.target?void 0:{not:pf({...r,currentPath:[...r.currentPath,"not"]})};case k.ZodEffects:return"input"===r.effectStrategy?pL(e.schema._def,r):pf(r);case k.ZodAny:case k.ZodUnknown:return pf(r);case k.ZodDefault:return{...pL(e.innerType._def,r),default:e.defaultValue()};case k.ZodBranded:return pv(e,r);case k.ZodReadonly:case k.ZodCatch:return pL(e.innerType._def,r);case k.ZodPipeline:if("input"===r.pipeStrategy)return pL(e.in._def,r);if("output"===r.pipeStrategy)return pL(e.out._def,r);let y=pL(e.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),v=pL(e.out._def,{...r,currentPath:[...r.currentPath,"allOf",y?"1":"0"]});return{allOf:[y,v].filter(e=>void 0!==e)};case k.ZodFunction:case k.ZodVoid:case k.ZodSymbol:default:return}})(e,e.typeName,t),o="function"==typeof n?pL(n(),t):n;if(o&&pD(e,t,o),t.postProcess){let r=t.postProcess(o,e,t);return i.jsonSchema=o,r}return i.jsonSchema=o,o}let pZ=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:ph(t.currentPath,e.path)};case"none":case"seen":if(e.path.length<t.currentPath.length&&e.path.every((e,r)=>t.currentPath[r]===e))return console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),pf(t);return"seen"===t.$refStrategy?pf(t):void 0}},pD=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r);function pV(e,t={}){let{strict:r=!1}=t,a=Object.entries(e),i=e=>({target:t})=>{let i={},n=[];for(let[r,o]of a)i[r]=function(e,t,r){let a=e["~standard"];if(a.jsonSchema)return a.jsonSchema[r]({target:t});if("zod"===e["~standard"].vendor&&!("_zod"in e)&&"_def"in e){let r=((e,t)=>{let r,a,i=(a=void 0!==(r="string"==typeof t?{...dn,name:t}:{...dn,...t}).name?[...r.basePath,r.definitionPath,r.name]:r.basePath,{...r,flags:{hasReferencedOpenAiAnyType:!1},currentPath:a,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([e,t])=>[t._def,{def:t._def,path:[...r.basePath,r.definitionPath,e],jsonSchema:void 0}]))}),n="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:pL(r._def,{...i,currentPath:[...i.basePath,i.definitionPath,t]},!0)??pf(i)}),{}):void 0,o="string"==typeof t?t:t?.nameStrategy==="title"?void 0:t?.name,s=pL(e._def,void 0===o?i:{...i,currentPath:[...i.basePath,i.definitionPath,o]},!1)??pf(i),l="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==l&&(s.title=l),i.flags.hasReferencedOpenAiAnyType&&(n||(n={}),n[i.openAiAnyTypeName]||(n[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let c=void 0===o?n?{...s,[i.definitionPath]:n}:s:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,o].join("/"),[i.definitionPath]:{...n,[o]:s}};return"jsonSchema7"===i.target?c.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.target&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c})(e,{$refStrategy:"none",target:"openapi-3.0"===t?"openApi3":"jsonSchema7"});return delete r.$schema,r}if("zod"===a.vendor&&"_zod"in e)try{let t=rQ(e);return delete t.$schema,t}catch(e){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${e instanceof Error?e.message:String(e)}`)}throw Error(`Schema library "${a.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(o,t,e),!function(e,t){if("function"!=typeof e.safeParse)return!1;try{let r=e.safeParse(void 0);return r.success&&("input"===t||void 0===r.data)}catch{return!1}}(o,e)&&n.push(r);let o={type:"object",properties:i};return n.length>0&&(o.required=n),r&&(o.additionalProperties=!1),o},n=async t=>{if("object"!=typeof t||null===t||Array.isArray(t))return{issues:[{message:"Expected an object."}]};let i={},n=[];for(let[e,r]of a){let a=await r["~standard"].validate(t[e]);if(a.issues)for(let t of a.issues)n.push({message:t.message,path:[e,...t.path??[]]});else(e in t||void 0!==a.value)&&(i[e]=a.value)}if(r)for(let r of Object.keys(t))r in e||n.push({message:`Unrecognized key: "${r}"`,path:[r]});return n.length>0?{issues:n}:{value:i}};return{shape:e,"~standard":{version:1,vendor:"xmcp",validate:n,jsonSchema:{input:i("input"),output:i("output")}}}}let pU=require("async_hooks"),pF=(e,t)=>{globalThis[e]=t},pH=e=>globalThis[e];function pJ({name:e,fallback:t=!0}){let r=Symbol.for(`xmcp-context-${e}`),a=Symbol.for(`xmcp-context-${e}-fallback-store`);if(pH(r))return pH(r);let i=new pU.AsyncLocalStorage,n=globalThis[a]??{current:null};pF(a,n);let o={provider:(e,r)=>(t&&(n.current=e),i.run(e,r)),getContext:()=>{let r=i.getStore();if(r)return r;if(t&&n.current)return n.current;throw Error(`getContext() can only be used within the ${e} context.`)},setContext:r=>{let a=i.getStore()??(t?n.current:null);if(!a)throw Error(`setContext() can only be used within the ${e} context.`);Object.assign(a,r)}};return pF(r,o),o}let pK=pJ({name:"http-request-context"});pK.setContext;let pB=pK.getContext;pK.provider;let pG=pJ({name:"client-info-context"}),pW=pG.setContext,pY=pG.getContext,pX=pG.provider,pQ=e=>{if(!("object"==typeof e&&null!==e&&!Array.isArray(e))||"string"!=typeof e.name||"string"!=typeof e.version)return;let t={name:e.name,version:e.version};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.websiteUrl&&(t.websiteUrl=e.websiteUrl),"string"==typeof e.description&&(t.description=e.description),t},p0=(e,t)=>{let r=t.toLowerCase();for(let[t,a]of Object.entries(e)){if(t.toLowerCase()!==r)continue;let e=Array.isArray(a)?a[0]:a;if("string"!=typeof e)break;let i=e.trim();return i.length>0?i:void 0}},p1=new Set(["message","mode","requestedSchema"]),p2=new Set(["elicitationId","message","mode","url"]),p9=new Set(["properties","required","type"]),p4=new Set(["default","description","format","maxLength","minLength","title","type"]),p6=new Set(["default","description","enum","enumNames","title","type"]),p5=new Set(["default","description","title","type"]),p3=new Set(["default","description","maximum","minimum","title","type"]),p8=new Set(["date","date-time","email","uri"]);async function p7(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mt(e,"Elicitation request must be a plain object."),me(e,p2,"URL elicitation"),mr(e.message,"URL elicitation requires a string message."),ma(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),ma(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){mt(e,"Elicitation request must be a plain object."),me(e,p1,"Form elicitation"),mr(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mt(t,"Form elicitation requires a flat object schema."),me(t,p9,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mt(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mt(t,`Form elicitation field "${e}" must be a plain object.`),mi(t.title,`Form elicitation field "${e}" title must be a string.`),mi(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(me(t,p6,`Form elicitation field "${e}"`),mo(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&&mo(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(mi(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)){me(t,p4,`Form elicitation field "${e}"`),mn(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mn(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mi(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mi(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!p8.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(p8).join(", ")}.`);return}if("boolean"===t.type){if(me(t,p5,`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){me(t,p3,`Form elicitation field "${e}"`),mn(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mn(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mn(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 sS&&e.code===sb.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}}function me(e,t,r){let a=Object.keys(e).filter(e=>!t.has(e));if(0!==a.length)throw Error(`${r} includes unsupported key(s): ${a.join(", ")}.`)}function mt(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}function mr(e,t){if("string"!=typeof e)throw Error(t)}function ma(e,t){if("string"!=typeof e||0===e.trim().length)throw Error(t)}function mi(e,t){if(void 0!==e&&"string"!=typeof e)throw Error(t)}function mn(e,t){if(void 0!==e&&"number"!=typeof e)throw Error(t)}function mo(e,t){if(!Array.isArray(e)||e.some(e=>"string"!=typeof e))throw Error(t)}let ms=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),ml=new Set(["task","toolChoice","tools"]),mc=new Set(["text","image","audio"]);async function mu(e,t,r){let a=function(e){md(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>ml.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!ms.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(md(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;md(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mc.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 sS&&e.code===sb.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}}function md(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}let mp={text:e=>"string"!=typeof e.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:e=>"string"!=typeof e.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:e=>"string"!=typeof e.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:e=>"string"!=typeof e.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof e.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==e.title&&"string"!=typeof e.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==e.description&&"string"!=typeof e.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==e.mimeType&&"string"!=typeof e.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mm(e){if(!e||"object"!=typeof e)return{valid:!1,error:"Content must be an object"};if("string"!=typeof e.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==e._meta&&(null===e._meta||"object"!=typeof e._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let t=mp[e.type];return t?t(e):{valid:!0}}function mh(e,t,r,a){if(null===e||"object"!=typeof e||Array.isArray(e))throw Error(`Tool "${r}" ${a}: expected a plain object.`);let i=new Set(Object.keys(t)),n=Object.keys(e).filter(e=>!i.has(e));if(n.length>0)throw Error(`Tool "${r}" ${a}: unrecognized key(s): ${n.join(", ")}`);for(let[i,n]of Object.entries(t))try{n.parse(e[i])}catch(e){throw Error(`Tool "${r}" ${a}: ${e?.message??`invalid field "${i}"`}`)}}function mf(e){return!!(e&&"object"==typeof e&&Object.keys(e).some(e=>e.startsWith("ui/")))}function mg(e){let t=e.mcpReq.envelope,r=pQ(t?.[ik]);if(!r)try{let e,t=pB();r=t.clientInfo??(e=t.headers,pQ({name:p0(e,"x-mcp-client-name"),version:p0(e,"x-mcp-client-version"),title:p0(e,"x-mcp-client-title"),websiteUrl:p0(e,"x-mcp-client-website-url"),description:p0(e,"x-mcp-client-description")}))}catch{}if(!r)try{r=pY().clientInfo}catch{}return r}function my(e){return e.endsWith(".tsx")}let mv=new class{add(e,t){this.resources.set(e,t)}getAll(){return this.resources}clear(){this.resources.clear()}has(e){return this.resources.has(e)}constructor(){!function(e,t,r){t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}(this,"resources",new Map)}};function m_(e){let t={};return!function e(r,a=""){if(r&&"object"==typeof r)for(let[i,n]of Object.entries(r)){let r=a?`${a}/${i}`:i;!n||"object"!=typeof n||Array.isArray(n)||n instanceof Date||n instanceof RegExp?t[r]=n:e(n,r)}}(e),t}let mb=["ui/resourceUri","resourceUri","visibility"],mS=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"],m$=pJ({name:"request-context",fallback:!1});function mw(e){let t=[...e];return(e,r,a)=>(function(e,t,r){let a,i=new Map;if(e.http){let e=pB(),t=Object.fromEntries(Object.entries(e.headers).map(([e,t])=>[e,Array.isArray(t)?Object.freeze([...t]):t]));a=Object.freeze({id:e.id,headers:Object.freeze(t)})}return m$.provider(Object.freeze({clientInfo:t?Object.freeze({...t}):void 0,http:a,signal:e.mcpReq.signal,set(e,t){i.set(e,t)},get:e=>i.get(e),async progress(t,r){let a=e.mcpReq._meta?.progressToken;void 0!==a&&await e.mcpReq.notify({method:"notifications/progress",params:{progressToken:a,progress:t,...void 0===r?{}:{total:r}}})},log:(t,r)=>e.mcpReq.log(t,r)}),r)})(r,mg(r),async()=>{if(0===t.length)return a();let r=Object.freeze({...function(){try{return m$.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),method:e.method,params:Object.freeze({...e.params})}),i=-1,n=async e=>{if(e<=i)throw Error("MCP middleware next() can only be called once");i=e;let o=t[e];return o?o(r,()=>n(e+1)):a()};return n(0)})}let mk=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mR(e){return"object"==typeof e&&null!==e&&Object.entries(e).every(([e,t])=>"string"==typeof e&&"object"==typeof t&&null!==t&&"parse"in t&&"function"==typeof t.parse)}function mx(e){return(e.split("/").pop()||e).replace(/\.[^/.]+$/,"")}function mP(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=[],l=[],c=n.map(e=>{if(!e.match(/^\[.+\]$/))return l.push(e),e;{let t=e.slice(1,-1);return s.push(t),`{${t}}`}}),u=`${i}://${c.join("/")}`,d=s.length>0?"template":"direct";return{filePath:e,uriTemplate:u,scheme:i,parameters:s,pathSegments:l,type:d}}function mE(e){let t=e.replace(/\\/g,"/");if(!t)throw Error("Invalid tool path: path is empty");let r=t.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:t,baseName:r}}function mT(e){return Error(`[xmcp] Invalid prompt file: ${e}
73
- -> Default export must be a prompt handler function.`)}async function mj(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 mT(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 mT(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}}let mO=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 prompt file: ${t}
74
- -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function mC(e){return Error(`[xmcp] Invalid resource file: ${e}
75
- -> Default export must be a resource handler function.`)}async function mN(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 mC(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 mC(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}}let mI=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}
76
- -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function mq(e){return Error(`[xmcp] Invalid tool file: ${e}
77
- -> Default export must be a tool handler function.`)}async function mz(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 mq(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 mq(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}}let mA=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}
78
- -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),mM=INJECTED_TOOLS,mL=INJECTED_PROMPTS,mZ=INJECTED_RESOURCES,mD=SERVER_INFO;async function mV(e,t,a,i){let n=await INJECTED_MIDDLEWARE?.(),o=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}(n?.mcp);return mv.clear(),!function(e,t,r){let a=e.server,i=a.setRequestHandler,n=mw(t);a.setRequestHandler=(e,...t)=>{if(mk.has(e)&&1===t.length&&"function"==typeof t[0]){let e=t[0];t[0]=(t,r)=>n({method:t.method,params:t.params??{}},r,()=>e(t,r))}Reflect.apply(i,a,[e,...t])};try{r()}finally{a.setRequestHandler=i}}(e,o,()=>{!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,l,c={name:mx(a),description:"No description provided"},{default:u,metadata:d,schema:p,outputSchema:m}=t;if("object"==typeof d&&null!==d&&Object.assign(c,d),"function"==typeof u&&"__x402"in u){let e=global.__XMCP_X402_REGISTRY;e&&e.set(c.name,u.__x402)}let h={};if(mR(p)?h=p:null!=p&&console.warn(`Invalid schema for tool "${c.name}" at ${a}. Expected Record<string, z.ZodType>`),null!=m)if(mR(m))o=m;else throw Error(`Invalid outputSchema for tool "${c.name}" at ${a}. Expected Record<string, z.ZodType>`);c.annotations={...c.annotations??{}},void 0===c.annotations.title&&(c.annotations.title=c.name),void 0===c._meta&&(c._meta={});let f=my(a),g=!!(i=c._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||f,y=c._meta;if(g){let e=`ui://app/${c.name}.html`;c._meta.ui||(c._meta.ui={}),c._meta.ui.resourceUri||(c._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))mb.includes(e)?i[e]=t:mS.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"),mv.add(c.name,{name:c.name,uri:e,handler:u,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:f?a:void 0})}let v=m_(y),_=g?v:void 0;s=my(a)&&g?async(e,t)=>({content:[{type:"text",text:""}],_meta:_,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,l=e(i,(o=mg(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)=>p7(n,e,t),sample:(e,t)=>mu(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),l$(l))return l;if("string"==typeof l||"number"==typeof l){if(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 mf(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)||"structuredContent"in l||"content"in l&&Array.isArray(l.content)||"_meta"in l||"isError"in l||(mh(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(mf(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}
72
+ ]`;continue}i+=a[e],"\\"===a[e]?n=!0:o&&"]"===a[e]?o=!1:o||"["!==a[e]||(o=!0)}try{new RegExp(i)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return i}function pz(e,t){if("openAi"===t.target&&console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead."),"openApi3"===t.target&&e.keyType?._def.typeName===k.ZodEnum)return{type:"object",required:e.keyType._def.values,properties:e.keyType._def.values.reduce((r,a)=>({...r,[a]:pL(e.valueType._def,{...t,currentPath:[...t.currentPath,"properties",a]})??pf(t)}),{}),additionalProperties:t.rejectedAdditionalProperties};let r={type:"object",additionalProperties:pL(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]})??t.allowedAdditionalProperties};if("openApi3"===t.target)return r;if(e.keyType?._def.typeName===k.ZodString&&e.keyType._def.checks?.length){let{type:a,...i}=pj(e.keyType._def,t);return{...r,propertyNames:i}}if(e.keyType?._def.typeName===k.ZodEnum)return{...r,propertyNames:{enum:e.keyType._def.values}};if(e.keyType?._def.typeName===k.ZodBranded&&e.keyType._def.type._def.typeName===k.ZodString&&e.keyType._def.type._def.checks?.length){let{type:a,...i}=pv(e.keyType._def,t);return{...r,propertyNames:i}}return r}let pA={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"},pM=(e,t)=>{let r=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((e,r)=>pL(e._def,{...t,currentPath:[...t.currentPath,"anyOf",`${r}`]})).filter(e=>!!e&&(!t.strictUnions||"object"==typeof e&&Object.keys(e).length>0));return r.length?{anyOf:r}:void 0};function pL(e,t,r=!1){let a=t.seen.get(e);if(t.override){let i=t.override?.(e,t,a,r);if(i!==di)return i}if(a&&!r){let e=pZ(a,t);if(void 0!==e)return e}let i={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,i);let n=((e,t,r)=>{switch(t){case k.ZodString:return pj(e,r);case k.ZodNumber:let a={type:"number"};if(!e.checks)return a;for(let t of e.checks)switch(t.kind){case"int":a.type="integer",pg(a,"type",t.message,r);break;case"min":"jsonSchema7"===r.target?t.inclusive?py(a,"minimum",t.value,t.message,r):py(a,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(a.exclusiveMinimum=!0),py(a,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?py(a,"maximum",t.value,t.message,r):py(a,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(a.exclusiveMaximum=!0),py(a,"maximum",t.value,t.message,r));break;case"multipleOf":py(a,"multipleOf",t.value,t.message,r)}return a;case k.ZodObject:return function(e,t){let r="openAi"===t.target,a={type:"object",properties:{}},i=[],n=e.shape();for(let e in n){let o=n[e];if(void 0===o||void 0===o._def)continue;let s=function(e){try{return e.isOptional()}catch{return!0}}(o);s&&r&&("ZodOptional"===o._def.typeName&&(o=o._def.innerType),o.isNullable()||(o=o.nullable()),s=!1);let l=pL(o._def,{...t,currentPath:[...t.currentPath,"properties",e],propertyPath:[...t.currentPath,"properties",e]});void 0!==l&&(a.properties[e]=l,s||i.push(e))}i.length&&(a.required=i);let o=function(e,t){if("ZodNever"!==e.catchall._def.typeName)return pL(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return"strict"===t.removeAdditionalStrategy?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}(e,t);return void 0!==o&&(a.additionalProperties=o),a}(e,r);case k.ZodBigInt:let i={type:"integer",format:"int64"};if(!e.checks)return i;for(let t of e.checks)switch(t.kind){case"min":"jsonSchema7"===r.target?t.inclusive?py(i,"minimum",t.value,t.message,r):py(i,"exclusiveMinimum",t.value,t.message,r):(t.inclusive||(i.exclusiveMinimum=!0),py(i,"minimum",t.value,t.message,r));break;case"max":"jsonSchema7"===r.target?t.inclusive?py(i,"maximum",t.value,t.message,r):py(i,"exclusiveMaximum",t.value,t.message,r):(t.inclusive||(i.exclusiveMaximum=!0),py(i,"maximum",t.value,t.message,r));break;case"multipleOf":py(i,"multipleOf",t.value,t.message,r)}return i;case k.ZodBoolean:return{type:"boolean"};case k.ZodDate:return function e(t,r,a){let i=a??r.dateStrategy;if(Array.isArray(i))return{anyOf:i.map((a,i)=>e(t,r,a))};switch(i){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var n=t,o=r;let s={type:"integer",format:"unix-time"};if("openApi3"===o.target)return s;for(let e of n.checks)switch(e.kind){case"min":py(s,"minimum",e.value,e.message,o);break;case"max":py(s,"maximum",e.value,e.message,o)}return s}}(e,r);case k.ZodUndefined:return{not:pf(r)};case k.ZodNull:return"openApi3"===r.target?{enum:["null"],nullable:!0}:{type:"null"};case k.ZodArray:let n;return n={type:"array"},e.type?._def&&e.type?._def?.typeName!==k.ZodAny&&(n.items=pL(e.type._def,{...r,currentPath:[...r.currentPath,"items"]})),e.minLength&&py(n,"minItems",e.minLength.value,e.minLength.message,r),e.maxLength&&py(n,"maxItems",e.maxLength.value,e.maxLength.message,r),e.exactLength&&(py(n,"minItems",e.exactLength.value,e.exactLength.message,r),py(n,"maxItems",e.exactLength.value,e.exactLength.message,r)),n;case k.ZodUnion:case k.ZodDiscriminatedUnion:if("openApi3"===r.target)return pM(e,r);let o=e.options instanceof Map?Array.from(e.options.values()):e.options;if(o.every(e=>e._def.typeName in pA&&(!e._def.checks||!e._def.checks.length))){let e=o.reduce((e,t)=>{let r=pA[t._def.typeName];return r&&!e.includes(r)?[...e,r]:e},[]);return{type:e.length>1?e:e[0]}}if(o.every(e=>"ZodLiteral"===e._def.typeName&&!e.description)){let e=o.reduce((e,t)=>{let r=typeof t._def.value;switch(r){case"string":case"number":case"boolean":return[...e,r];case"bigint":return[...e,"integer"];case"object":if(null===t._def.value)return[...e,"null"];default:return e}},[]);if(e.length===o.length){let t=e.filter((e,t,r)=>r.indexOf(e)===t);return{type:t.length>1?t:t[0],enum:o.reduce((e,t)=>e.includes(t._def.value)?e:[...e,t._def.value],[])}}}else if(o.every(e=>"ZodEnum"===e._def.typeName))return{type:"string",enum:o.reduce((e,t)=>[...e,...t._def.values.filter(t=>!e.includes(t))],[])};return pM(e,r);case k.ZodIntersection:let s,l,c;return s=[pL(e.left._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),pL(e.right._def,{...r,currentPath:[...r.currentPath,"allOf","1"]})].filter(e=>!!e),l="jsonSchema2019-09"===r.target?{unevaluatedProperties:!1}:void 0,c=[],s.forEach(e=>{if((!("type"in e)||"string"!==e.type)&&"allOf"in e)c.push(...e.allOf),void 0===e.unevaluatedProperties&&(l=void 0);else{let t=e;if("additionalProperties"in e&&!1===e.additionalProperties){let{additionalProperties:r,...a}=e;t=a}else l=void 0;c.push(t)}}),c.length?{allOf:c,...l}:void 0;case k.ZodTuple:return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((e,t)=>pL(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[]),additionalItems:pL(e.rest._def,{...r,currentPath:[...r.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((e,t)=>pL(e._def,{...r,currentPath:[...r.currentPath,"items",`${t}`]})).reduce((e,t)=>void 0===t?e:[...e,t],[])};case k.ZodRecord:return pz(e,r);case k.ZodLiteral:let u;return"bigint"!=(u=typeof e.value)&&"number"!==u&&"boolean"!==u&&"string"!==u?{type:Array.isArray(e.value)?"array":"object"}:"openApi3"===r.target?{type:"bigint"===u?"integer":u,enum:[e.value]}:{type:"bigint"===u?"integer":u,const:e.value};case k.ZodEnum:return{type:"string",enum:Array.from(e.values)};case k.ZodNativeEnum:let d,p,m;return d=e.values,{type:1===(m=Array.from(new Set((p=Object.keys(e.values).filter(e=>"number"!=typeof d[d[e]]).map(e=>d[e])).map(e=>typeof e)))).length?"string"===m[0]?"string":"number":["string","number"],enum:p};case k.ZodNullable:if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return"openApi3"===r.target?{type:pA[e.innerType._def.typeName],nullable:!0}:{type:[pA[e.innerType._def.typeName],"null"]};if("openApi3"===r.target){let t=pL(e.innerType._def,{...r,currentPath:[...r.currentPath]});return t&&"$ref"in t?{allOf:[t],nullable:!0}:t&&{...t,nullable:!0}}let h=pL(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","0"]});return h&&{anyOf:[h,{type:"null"}]};case k.ZodOptional:if(r.currentPath.toString()===r.propertyPath?.toString())return pL(e.innerType._def,r);let f=pL(e.innerType._def,{...r,currentPath:[...r.currentPath,"anyOf","1"]});return f?{anyOf:[{not:pf(r)},f]}:pf(r);case k.ZodMap:if("record"===r.mapStrategy)return pz(e,r);return{type:"array",maxItems:125,items:{type:"array",items:[pL(e.keyType._def,{...r,currentPath:[...r.currentPath,"items","items","0"]})||pf(r),pL(e.valueType._def,{...r,currentPath:[...r.currentPath,"items","items","1"]})||pf(r)],minItems:2,maxItems:2}};case k.ZodSet:let g;return g={type:"array",uniqueItems:!0,items:pL(e.valueType._def,{...r,currentPath:[...r.currentPath,"items"]})},e.minSize&&py(g,"minItems",e.minSize.value,e.minSize.message,r),e.maxSize&&py(g,"maxItems",e.maxSize.value,e.maxSize.message,r),g;case k.ZodLazy:return()=>e.getter()._def;case k.ZodPromise:return pL(e.type._def,r);case k.ZodNaN:case k.ZodNever:return"openAi"===r.target?void 0:{not:pf({...r,currentPath:[...r.currentPath,"not"]})};case k.ZodEffects:return"input"===r.effectStrategy?pL(e.schema._def,r):pf(r);case k.ZodAny:case k.ZodUnknown:return pf(r);case k.ZodDefault:return{...pL(e.innerType._def,r),default:e.defaultValue()};case k.ZodBranded:return pv(e,r);case k.ZodReadonly:case k.ZodCatch:return pL(e.innerType._def,r);case k.ZodPipeline:if("input"===r.pipeStrategy)return pL(e.in._def,r);if("output"===r.pipeStrategy)return pL(e.out._def,r);let y=pL(e.in._def,{...r,currentPath:[...r.currentPath,"allOf","0"]}),v=pL(e.out._def,{...r,currentPath:[...r.currentPath,"allOf",y?"1":"0"]});return{allOf:[y,v].filter(e=>void 0!==e)};case k.ZodFunction:case k.ZodVoid:case k.ZodSymbol:default:return}})(e,e.typeName,t),o="function"==typeof n?pL(n(),t):n;if(o&&pD(e,t,o),t.postProcess){let r=t.postProcess(o,e,t);return i.jsonSchema=o,r}return i.jsonSchema=o,o}let pZ=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:ph(t.currentPath,e.path)};case"none":case"seen":if(e.path.length<t.currentPath.length&&e.path.every((e,r)=>t.currentPath[r]===e))return console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),pf(t);return"seen"===t.$refStrategy?pf(t):void 0}},pD=(e,t,r)=>(e.description&&(r.description=e.description,t.markdownDescription&&(r.markdownDescription=e.description)),r);function pV(e,t={}){let{strict:r=!1}=t,a=Object.entries(e),i=e=>({target:t})=>{let i={},n=[];for(let[r,o]of a)i[r]=function(e,t,r){let a=e["~standard"];if(a.jsonSchema)return a.jsonSchema[r]({target:t});if("zod"===e["~standard"].vendor&&!("_zod"in e)&&"_def"in e){let r=((e,t)=>{let r,a,i=(a=void 0!==(r="string"==typeof t?{...dn,name:t}:{...dn,...t}).name?[...r.basePath,r.definitionPath,r.name]:r.basePath,{...r,flags:{hasReferencedOpenAiAnyType:!1},currentPath:a,propertyPath:void 0,seen:new Map(Object.entries(r.definitions).map(([e,t])=>[t._def,{def:t._def,path:[...r.basePath,r.definitionPath,e],jsonSchema:void 0}]))}),n="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:pL(r._def,{...i,currentPath:[...i.basePath,i.definitionPath,t]},!0)??pf(i)}),{}):void 0,o="string"==typeof t?t:t?.nameStrategy==="title"?void 0:t?.name,s=pL(e._def,void 0===o?i:{...i,currentPath:[...i.basePath,i.definitionPath,o]},!1)??pf(i),l="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==l&&(s.title=l),i.flags.hasReferencedOpenAiAnyType&&(n||(n={}),n[i.openAiAnyTypeName]||(n[i.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===i.$refStrategy?"1":[...i.basePath,i.definitionPath,i.openAiAnyTypeName].join("/")}}));let c=void 0===o?n?{...s,[i.definitionPath]:n}:s:{$ref:[..."relative"===i.$refStrategy?[]:i.basePath,i.definitionPath,o].join("/"),[i.definitionPath]:{...n,[o]:s}};return"jsonSchema7"===i.target?c.$schema="http://json-schema.org/draft-07/schema#":("jsonSchema2019-09"===i.target||"openAi"===i.target)&&(c.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===i.target&&("anyOf"in c||"oneOf"in c||"allOf"in c||"type"in c&&Array.isArray(c.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),c})(e,{$refStrategy:"none",target:"openapi-3.0"===t?"openApi3":"jsonSchema7"});return delete r.$schema,r}if("zod"===a.vendor&&"_zod"in e)try{let t=rQ(e);return delete t.$schema,t}catch(e){throw Error(`Failed to convert a zod schema to JSON Schema (zod v4 without "~standard.jsonSchema"). Upgrade to zod >= 4.2.0. Original error: ${e instanceof Error?e.message:String(e)}`)}throw Error(`Schema library "${a.vendor}" cannot be converted to JSON Schema. Use zod v3 (>= 3.25.76), zod >= 4.2.0, or a Standard Schema library implementing "~standard.jsonSchema".`)}(o,t,e),!function(e,t){if("function"!=typeof e.safeParse)return!1;try{let r=e.safeParse(void 0);return r.success&&("input"===t||void 0===r.data)}catch{return!1}}(o,e)&&n.push(r);let o={type:"object",properties:i};return n.length>0&&(o.required=n),r&&(o.additionalProperties=!1),o},n=async t=>{if("object"!=typeof t||null===t||Array.isArray(t))return{issues:[{message:"Expected an object."}]};let i={},n=[];for(let[e,r]of a){let a=await r["~standard"].validate(t[e]);if(a.issues)for(let t of a.issues)n.push({message:t.message,path:[e,...t.path??[]]});else(e in t||void 0!==a.value)&&(i[e]=a.value)}if(r)for(let r of Object.keys(t))r in e||n.push({message:`Unrecognized key: "${r}"`,path:[r]});return n.length>0?{issues:n}:{value:i}};return{shape:e,"~standard":{version:1,vendor:"xmcp",validate:n,jsonSchema:{input:i("input"),output:i("output")}}}}let pU=require("async_hooks"),pF=(e,t)=>{globalThis[e]=t},pH=e=>globalThis[e];function pJ({name:e,fallback:t=!0}){let r=Symbol.for(`xmcp-context-${e}`),a=Symbol.for(`xmcp-context-${e}-fallback-store`);if(pH(r))return pH(r);let i=new pU.AsyncLocalStorage,n=globalThis[a]??{current:null};pF(a,n);let o={provider:(e,r)=>(t&&(n.current=e),i.run(e,r)),getContext:()=>{let r=i.getStore();if(r)return r;if(t&&n.current)return n.current;throw Error(`getContext() can only be used within the ${e} context.`)},setContext:r=>{let a=i.getStore()??(t?n.current:null);if(!a)throw Error(`setContext() can only be used within the ${e} context.`);Object.assign(a,r)}};return pF(r,o),o}let pK=pJ({name:"http-request-context"});pK.setContext;let pB=pK.getContext;pK.provider;let pG=pJ({name:"client-info-context"}),pW=pG.setContext,pY=pG.getContext,pX=pG.provider,pQ=e=>{if(!("object"==typeof e&&null!==e&&!Array.isArray(e))||"string"!=typeof e.name||"string"!=typeof e.version)return;let t={name:e.name,version:e.version};return"string"==typeof e.title&&(t.title=e.title),"string"==typeof e.websiteUrl&&(t.websiteUrl=e.websiteUrl),"string"==typeof e.description&&(t.description=e.description),t},p0=(e,t)=>{let r=t.toLowerCase();for(let[t,a]of Object.entries(e)){if(t.toLowerCase()!==r)continue;let e=Array.isArray(a)?a[0]:a;if("string"!=typeof e)break;let i=e.trim();return i.length>0?i:void 0}},p1=new Set(["message","mode","requestedSchema"]),p2=new Set(["elicitationId","message","mode","url"]),p9=new Set(["properties","required","type"]),p4=new Set(["default","description","format","maxLength","minLength","title","type"]),p6=new Set(["default","description","enum","enumNames","title","type"]),p5=new Set(["default","description","title","type"]),p3=new Set(["default","description","maximum","minimum","title","type"]),p8=new Set(["date","date-time","email","uri"]);async function p7(e,t,r){let a=function(e){let t=e.mode??"form";if("url"===t)return function(e){let t;mt(e,"Elicitation request must be a plain object."),me(e,p2,"URL elicitation"),mr(e.message,"URL elicitation requires a string message."),ma(e.elicitationId,"URL elicitation requires a non-empty elicitationId."),ma(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){mt(e,"Elicitation request must be a plain object."),me(e,p1,"Form elicitation"),mr(e.message,"Form elicitation requires a string message.");let t=e.requestedSchema;if(mt(t,"Form elicitation requires a flat object schema."),me(t,p9,"Form elicitation schema"),"object"!==t.type)throw Error('Form elicitation schema must use type "object".');for(let[e,r]of(mt(t.properties,"Form elicitation schema requires a properties object."),Object.entries(t.properties)))!function(e,t){if(mt(t,`Form elicitation field "${e}" must be a plain object.`),mi(t.title,`Form elicitation field "${e}" title must be a string.`),mi(t.description,`Form elicitation field "${e}" description must be a string.`),"string"===t.type&&"enum"in t){var r,a;if(me(t,p6,`Form elicitation field "${e}"`),mo(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&&mo(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(mi(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)){me(t,p4,`Form elicitation field "${e}"`),mn(t.minLength,`Form elicitation field "${e}" minLength must be a number.`),mn(t.maxLength,`Form elicitation field "${e}" maxLength must be a number.`),mi(t.default,`Form elicitation field "${e}" default must be a string.`);let r=t.format;if(mi(r,`Form elicitation field "${e}" format must be a string.`),void 0!==r&&!p8.has(r))throw Error(`Form elicitation field "${e}" format must be one of: ${Array.from(p8).join(", ")}.`);return}if("boolean"===t.type){if(me(t,p5,`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){me(t,p3,`Form elicitation field "${e}"`),mn(t.minimum,`Form elicitation field "${e}" minimum must be a number.`),mn(t.maximum,`Form elicitation field "${e}" maximum must be a number.`),mn(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 sS&&e.code===sb.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}}function me(e,t,r){let a=Object.keys(e).filter(e=>!t.has(e));if(0!==a.length)throw Error(`${r} includes unsupported key(s): ${a.join(", ")}.`)}function mt(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}function mr(e,t){if("string"!=typeof e)throw Error(t)}function ma(e,t){if("string"!=typeof e||0===e.trim().length)throw Error(t)}function mi(e,t){if(void 0!==e&&"string"!=typeof e)throw Error(t)}function mn(e,t){if(void 0!==e&&"number"!=typeof e)throw Error(t)}function mo(e,t){if(!Array.isArray(e)||e.some(e=>"string"!=typeof e))throw Error(t)}let ms=new Set(["_meta","includeContext","maxTokens","messages","metadata","modelPreferences","stopSequences","systemPrompt","temperature"]),ml=new Set(["task","toolChoice","tools"]),mc=new Set(["text","image","audio"]);async function mu(e,t,r){let a=function(e){md(e,"Sampling request must be a plain object.");let t=Object.keys(e),r=t.filter(e=>ml.has(e));if(r.length>0)throw Error(`Sampling request key(s) not supported by xmcp yet: ${r.join(", ")}.`);let a=t.filter(e=>!ms.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(md(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;md(r,`Sampling message at index ${e} requires a content object.`);let a=r.type;if("string"!=typeof a||!mc.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 sS&&e.code===sb.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}}function md(e,t){if("object"!=typeof e||null===e||Array.isArray(e))throw Error(t)}let mp={text:e=>"string"!=typeof e.text?{valid:!1,error:'Text content must have a "text" property of type string'}:{valid:!0},image:e=>"string"!=typeof e.data?{valid:!1,error:'Image content must have a "data" property of type string (base64-encoded image)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Image content must have a "mimeType" property of type string'}:{valid:!0},audio:e=>"string"!=typeof e.data?{valid:!1,error:'Audio content must have a "data" property of type string (base64-encoded audio)'}:"string"!=typeof e.mimeType?{valid:!1,error:'Audio content must have a "mimeType" property of type string'}:{valid:!0},resource_link:e=>"string"!=typeof e.name?{valid:!1,error:'Resource link content must have a "name" property of type string'}:"string"!=typeof e.uri?{valid:!1,error:'Resource link content must have a "uri" property of type string'}:void 0!==e.title&&"string"!=typeof e.title?{valid:!1,error:'Resource link "title" property must be a string if provided'}:void 0!==e.description&&"string"!=typeof e.description?{valid:!1,error:'Resource link "description" property must be a string if provided'}:void 0!==e.mimeType&&"string"!=typeof e.mimeType?{valid:!1,error:'Resource link "mimeType" property must be a string if provided'}:{valid:!0}};function mm(e){if(!e||"object"!=typeof e)return{valid:!1,error:"Content must be an object"};if("string"!=typeof e.type)return{valid:!1,error:'Content must have a "type" property of type string'};if(void 0!==e._meta&&(null===e._meta||"object"!=typeof e._meta))return{valid:!1,error:'Content "_meta" property must be an object if provided'};let t=mp[e.type];return t?t(e):{valid:!0}}function mh(e,t,r,a){if(null===e||"object"!=typeof e||Array.isArray(e))throw Error(`Tool "${r}" ${a}: expected a plain object.`);let i=new Set(Object.keys(t)),n=Object.keys(e).filter(e=>!i.has(e));if(n.length>0)throw Error(`Tool "${r}" ${a}: unrecognized key(s): ${n.join(", ")}`);for(let[i,n]of Object.entries(t))try{n.parse(e[i])}catch(e){throw Error(`Tool "${r}" ${a}: ${e?.message??`invalid field "${i}"`}`)}}function mf(e){return!!(e&&"object"==typeof e&&Object.keys(e).some(e=>e.startsWith("ui/")))}function mg(e){let t=e.mcpReq.envelope,r=pQ(t?.[ik]);if(!r)try{let e,t=pB();r=t.clientInfo??(e=t.headers,pQ({name:p0(e,"x-mcp-client-name"),version:p0(e,"x-mcp-client-version"),title:p0(e,"x-mcp-client-title"),websiteUrl:p0(e,"x-mcp-client-website-url"),description:p0(e,"x-mcp-client-description")}))}catch{}if(!r)try{r=pY().clientInfo}catch{}return r}function my(e){return e.endsWith(".tsx")}let mv=new class{add(e,t){this.resources.set(e,t)}getAll(){return this.resources}clear(){this.resources.clear()}has(e){return this.resources.has(e)}constructor(){!function(e,t,r){t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}(this,"resources",new Map)}};function m_(e){let t={};return!function e(r,a=""){if(r&&"object"==typeof r)for(let[i,n]of Object.entries(r)){let r=a?`${a}/${i}`:i;!n||"object"!=typeof n||Array.isArray(n)||n instanceof Date||n instanceof RegExp?t[r]=n:e(n,r)}}(e),t}let mb=["ui/resourceUri","resourceUri","visibility"],mS=["prefersBorder","domain","csp","permissions","connectDomains","resourceDomains","frameDomains","baseUriDomains"],m$=pJ({name:"request-context",fallback:!1});function mw(e){let t=[...e];return(e,r,a)=>(function(e,t,r){let a,i=new Map;if(e.http){let e=pB(),t=Object.fromEntries(Object.entries(e.headers).map(([e,t])=>[e,Array.isArray(t)?Object.freeze([...t]):t]));a=Object.freeze({id:e.id,headers:Object.freeze(t)})}return m$.provider(Object.freeze({clientInfo:t?Object.freeze({...t}):void 0,http:a,signal:e.mcpReq.signal,set(e,t){i.set(e,t)},get:e=>i.get(e),async progress(t,r){let a=e.mcpReq._meta?.progressToken;void 0!==a&&await e.mcpReq.notify({method:"notifications/progress",params:{progressToken:a,progress:t,...void 0===r?{}:{total:r}}})},log:(t,r)=>e.mcpReq.log(t,r)}),r)})(r,mg(r),async()=>{if(0===t.length)return a();let r=Object.freeze({...function(){try{return m$.getContext()}catch{throw Error("getRequestContext() can only be used while handling an MCP request.")}}(),method:e.method,params:Object.freeze({...e.params})}),i=-1,n=async e=>{if(e<=i)throw Error("MCP middleware next() can only be called once");i=e;let o=t[e];return o?o(r,()=>n(e+1)):a()};return n(0)})}let mk=new Set(["tools/list","prompts/get","prompts/list","resources/read","resources/list","resources/templates/list","completion/complete"]);function mR(e){let{tags:t,enabled:r,...a}=e;return{...a,_meta:void 0===t?a._meta:{...a._meta,"xmcp/tags":t}}}function mx(e){return"object"==typeof e&&null!==e&&Object.entries(e).every(([e,t])=>"string"==typeof e&&"object"==typeof t&&null!==t&&"parse"in t&&"function"==typeof t.parse)}function mP(e){return(e.split("/").pop()||e).replace(/\.[^/.]+$/,"")}function mE(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=[],l=[],c=n.map(e=>{if(!e.match(/^\[.+\]$/))return l.push(e),e;{let t=e.slice(1,-1);return s.push(t),`{${t}}`}}),u=`${i}://${c.join("/")}`,d=s.length>0?"template":"direct";return{filePath:e,uriTemplate:u,scheme:i,parameters:s,pathSegments:l,type:d}}function mT(e){let t=e.replace(/\\/g,"/");if(!t)throw Error("Invalid tool path: path is empty");let r=t.replace(/\.[^/.]+$/,"").replace(/\//g,"_");return{normalizedPath:t,baseName:r}}function mj(e){return Error(`[xmcp] Invalid prompt file: ${e}
73
+ -> Default export must be a prompt handler function.`)}async function mO(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 mj(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 mj(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}}let mC=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 prompt file: ${t}
74
+ -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} prompt${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function mN(e){return Error(`[xmcp] Invalid resource file: ${e}
75
+ -> Default export must be a resource handler function.`)}async function mI(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 mN(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 mN(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}}let mq=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}
76
+ -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} resource${1===i?"":"s"} skipped due to empty files or missing default exports`)}}();function mz(e){return Error(`[xmcp] Invalid tool file: ${e}
77
+ -> Default export must be a tool handler function.`)}async function mA(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 mz(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 mz(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}}let mM=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}
78
+ -> ${r}`)});let i=r.length;e.warn(`[xmcp] ${i} tool${1===i?"":"s"} skipped due to empty files or missing default exports`)}}(),mL=INJECTED_TOOLS,mZ=INJECTED_PROMPTS,mD=INJECTED_RESOURCES,mV=SERVER_INFO;async function mU(e,t,a,i){let n=await INJECTED_MIDDLEWARE?.(),o=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}(n?.mcp);return mv.clear(),!function(e,t,r){let a=e.server,i=a.setRequestHandler,n=mw(t);a.setRequestHandler=(e,...t)=>{if(mk.has(e)&&1===t.length&&"function"==typeof t[0]){let e=t[0];t[0]=(t,r)=>n({method:t.method,params:t.params??{}},r,()=>e(t,r))}Reflect.apply(i,a,[e,...t])};try{r()}finally{a.setRequestHandler=i}}(e,o,()=>{!function(e,t,r=[]){t.forEach((t,a)=>{var i,n;let o,s,l,c={name:mP(a),description:"No description provided"},{default:u,metadata:d,schema:p,outputSchema:m}=t;if("object"==typeof d&&null!==d&&Object.assign(c,d),!1===c.enabled)return;if("function"==typeof u&&"__x402"in u){let e=global.__XMCP_X402_REGISTRY;e&&e.set(c.name,u.__x402)}let h={};if(mx(p)?h=p:null!=p&&console.warn(`Invalid schema for tool "${c.name}" at ${a}. Expected Record<string, z.ZodType>`),null!=m)if(mx(m))o=m;else throw Error(`Invalid outputSchema for tool "${c.name}" at ${a}. Expected Record<string, z.ZodType>`);c.annotations={...c.annotations??{}},void 0===c.annotations.title&&(c.annotations.title=c.name),c._meta={...mR(c)._meta};let f=my(a),g=!!(i=c._meta)&&"object"==typeof i&&"ui"in i&&"object"==typeof i.ui||f,y=c._meta;if(g){let e=`ui://app/${c.name}.html`;c._meta.ui||(c._meta.ui={}),c._meta.ui.resourceUri||(c._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))mb.includes(e)?i[e]=t:mS.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"),mv.add(c.name,{name:c.name,uri:e,handler:u,mimeType:"text/html;profile=mcp-app",_meta:r,toolPath:f?a:void 0})}let v=m_(y),_=g?v:void 0;s=my(a)&&g?async(e,t)=>({content:[{type:"text",text:""}],_meta:_,structuredContent:{args:e}}):function(e,t,r,a="unknown-tool"){return async(i,n)=>{let o,s,l=e(i,(o=mg(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)=>p7(n,e,t),sample:(e,t)=>mu(n,e,t),inputResponses:n.mcpReq.inputResponses,requestState:n.mcpReq.requestState}));if(l instanceof Promise&&(l=await l),l$(l))return l;if("string"==typeof l||"number"==typeof l){if(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 mf(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)||"structuredContent"in l||"content"in l&&Array.isArray(l.content)||"_meta"in l||"isError"in l||(mh(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(mf(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}
79
79
 
80
80
  Expected CallToolResult format:
81
81
  {
@@ -142,7 +142,7 @@ Expected format:
142
142
  key: "value",
143
143
  nested: { data: "here" }
144
144
  }
145
- }`)}}return l}}(u,_,o,c.name);let b={title:c.annotations?.title,description:c.description,inputSchema:pV(h),outputSchema:o?pV(o,{strict:!0}):void 0,annotations:c.annotations,_meta:v};e.registerTool(c.name,b,(n=c.name,l=mw(r),(e,t)=>l({method:"tools/call",params:{name:n,arguments:e}},t,()=>s(e,t))))})}(e,t,o),a.forEach((t,r)=>{let a=mx(r),i={name:a,title:a,description:"No description provided"},n={},{default:o,metadata:s,schema:l}=t;"object"==typeof s&&null!==s&&Object.assign(i,s);let c=function(e,t="assistant"){return async(r,a)=>{let i,n=e(r,a);if(n instanceof Promise&&(n=await n),Array.isArray(n)||null!==n&&"object"==typeof n&&"messages"in n){let e=Array.isArray(n)?{messages:n}:n,t=await lK.GetPromptResult["~standard"].validate(e);if(t.issues){let e=t.issues.map(e=>{let t=e.path?.map(e=>"object"==typeof e?e.key:e).join(".");return`${t||"result"}: ${e.message}`});throw Error(`Invalid prompt result: ${e.join("; ")}`)}return e}if("string"==typeof n||"number"==typeof n)i={type:"text",text:"number"==typeof n?`${n}`:n};else{let e=mm(n);if(e.valid)i=n;else{let t=null===n?"null":typeof n,r=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${t}: ${r}
145
+ }`)}}return l}}(u,_,o,c.name);let b={title:c.annotations?.title,description:c.description,inputSchema:pV(h),outputSchema:o?pV(o,{strict:!0}):void 0,annotations:c.annotations,icons:c.icons,_meta:v};e.registerTool(c.name,b,(n=c.name,l=mw(r),(e,t)=>l({method:"tools/call",params:{name:n,arguments:e}},t,()=>s(e,t))))})}(e,t,o),a.forEach((t,r)=>{let a=mP(r),i={name:a,title:a,description:"No description provided"},n={},{default:o,metadata:s,schema:l}=t;if("object"==typeof s&&null!==s&&Object.assign(i,s),!1===i.enabled)return;let c=function(e,t="assistant"){return async(r,a)=>{let i,n=e(r,a);if(n instanceof Promise&&(n=await n),Array.isArray(n)||null!==n&&"object"==typeof n&&"messages"in n){let e=Array.isArray(n)?{messages:n}:n,t=await lK.GetPromptResult["~standard"].validate(e);if(t.issues){let e=t.issues.map(e=>{let t=e.path?.map(e=>"object"==typeof e?e.key:e).join(".");return`${t||"result"}: ${e.message}`});throw Error(`Invalid prompt result: ${e.join("; ")}`)}return e}if("string"==typeof n||"number"==typeof n)i={type:"text",text:"number"==typeof n?`${n}`:n};else{let e=mm(n);if(e.valid)i=n;else{let t=null===n?"null":typeof n,r=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Prompt handler must return a PromptContent object, string, number, PromptMessage[], or GetPromptResult. Got ${t}: ${r}
146
146
 
147
147
  Validation error: ${e.error}
148
148
 
@@ -155,7 +155,7 @@ Expected formats:
155
155
  - Image content: { type: "image", data: "base64data", mimeType: "image/jpeg" }
156
156
  - Audio content: { type: "audio", data: "base64data", mimeType: "audio/mpeg" }
157
157
  - Resource link: { type: "resource_link", name: "resource name", uri: "resource://uri" }
158
- - All content types support an optional "_meta" object property`)}}if("user"!==t&&"assistant"!==t)throw Error(`Invalid role: ${t}`);return{messages:[{role:t,content:i}]}}}(o,i.role||"assistant");mR(l)?Object.assign(n,l):null!=l&&console.warn(`Invalid schema for prompt "${i.name}" at ${r}. Expected Record<string, z.ZodType>`),e.registerPrompt(i.name,{title:i.title,description:i.description,argsSchema:pV(n)},c)}),[...mv.getAll()].forEach(([t,a])=>{let i=a.mimeType||"text/html;profile=mcp-app",n=a?._meta?m_(a._meta):void 0,o={name:a.name,description:`Auto-generated resource for ${a.name} tool`,mimeType:a.mimeType,_meta:n},s=async(e,t)=>{if(a.mimeType&&a.toolPath)try{var n;let e,t,o=(n=a.toolPath,IS_CLOUDFLARE?function(e){let{normalizedPath:t,baseName:r}=mE(e),a=5381;for(let e=0;e<t.length;e++)a=Math.imul(a,33)+t.charCodeAt(e)>>>0;let i=a.toString(16).slice(0,6).padStart(6,"0");return`${r}_${i}`}(n):function(e){let{normalizedPath:t,baseName:a}=mE(e),i=r(6982).createHash("md5").update(t).digest("hex").slice(0,6);return`${a}_${i}`}(n)),s=function(e){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[e]||null;if(!IS_CLOUDFLARE)try{let t=r(9896),a=r(6928);for(let r of[a.join(process.cwd(),"dist","client"),a.join(process.cwd(),"client")]){let i=a.join(r,`${e}.bundle.js`),n=a.join(r,`${e}.bundle.css`);if(t.existsSync(i)){let e,r=t.readFileSync(i,"utf-8");return t.existsSync(n)&&(e=t.readFileSync(n,"utf-8")),{js:r,css:e}}}}catch{}return null}(o);if(!s)throw Error(`React client bundle not found for "${a.name}" (bundle: "${o}").
158
+ - All content types support an optional "_meta" object property`)}}if("user"!==t&&"assistant"!==t)throw Error(`Invalid role: ${t}`);return{messages:[{role:t,content:i}]}}}(o,i.role||"assistant");mx(l)?Object.assign(n,l):null!=l&&console.warn(`Invalid schema for prompt "${i.name}" at ${r}. Expected Record<string, z.ZodType>`),e.registerPrompt(i.name,{title:i.title,description:i.description,icons:i.icons,_meta:mR(i)._meta,argsSchema:pV(n)},c)}),[...mv.getAll()].forEach(([t,a])=>{let i=a.mimeType||"text/html;profile=mcp-app",n=a?._meta?m_(a._meta):void 0,o={name:a.name,description:`Auto-generated resource for ${a.name} tool`,mimeType:a.mimeType,_meta:n},s=async(e,t)=>{if(a.mimeType&&a.toolPath)try{var n;let e,t,o=(n=a.toolPath,IS_CLOUDFLARE?function(e){let{normalizedPath:t,baseName:r}=mT(e),a=5381;for(let e=0;e<t.length;e++)a=Math.imul(a,33)+t.charCodeAt(e)>>>0;let i=a.toString(16).slice(0,6).padStart(6,"0");return`${r}_${i}`}(n):function(e){let{normalizedPath:t,baseName:a}=mT(e),i=r(6982).createHash("md5").update(t).digest("hex").slice(0,6);return`${a}_${i}`}(n)),s=function(e){if(INJECTED_CLIENT_BUNDLES)return INJECTED_CLIENT_BUNDLES[e]||null;if(!IS_CLOUDFLARE)try{let t=r(9896),a=r(6928);for(let r of[a.join(process.cwd(),"dist","client"),a.join(process.cwd(),"client")]){let i=a.join(r,`${e}.bundle.js`),n=a.join(r,`${e}.bundle.css`);if(t.existsSync(i)){let e,r=t.readFileSync(i,"utf-8");return t.existsSync(n)&&(e=t.readFileSync(n,"utf-8")),{js:r,css:e}}}}catch{}return null}(o);if(!s)throw Error(`React client bundle not found for "${a.name}" (bundle: "${o}").
159
159
  React tool bundles are generated automatically when you run "xmcp build" (or "xmcp dev").
160
160
  Please re-run the build so the framework can regenerate the bundle.`);let l=s.js,c=s.css,u=(e=`
161
161
  <script type="module">
@@ -210,7 +210,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let l=s.js
210
210
  <div id="root"></div>
211
211
  ${e}
212
212
  </body>
213
- </html>`);return{contents:[{uri:a.uri,text:u,mimeType:i,_meta:a._meta}]}}catch(e){throw console.error(`React failed for ${a.name}:`,e),e}let o=a.handler({},t);if(o instanceof Promise&&(o=await o),"string"==typeof o)return{contents:[{uri:a.uri,text:o,mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"_meta"in o&&!("content"in o))return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"content"in o&&Array.isArray(o.content)){let e=o.content.find(e=>"text"===e.type);if(e&&"text"===e.type&&"string"==typeof e.text)return{contents:[{uri:a.uri,text:e.text,mimeType:i,_meta:a._meta}]}}return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]}};e.registerResource(a.name,a.uri,o,s)}),i.forEach((t,r)=>{let a={name:mx(r),description:"No description provided"},{default:i,metadata:n,schema:o}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let s={};mR(o)?s=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let l=mP(r);if(!l)return void console.warn(`Skipping resource "${a.name}" at ${r}: Invalid file path format`);let c=l.uriTemplate;a.mimeType&&a.mimeType.includes("html")&&(c=c.endsWith(".html")?c:`${c}.html`);let u=function(e,t,r={}){let a=mP(t);if(!a)throw Error(`Invalid resource file path: ${t}. Must follow (scheme)/path/[param] convention.`);return async(t,i)=>{let n=e(function(e,t,r){let a={},i={};if(0===t.parameters.length)return i;let n=t.uriTemplate.split("://")[1]||"",o=e.split("://")[1]||"",s=n.split("/"),l=o.split("/");for(let e=0;e<s.length&&e<l.length;e++){let t=s[e],r=l[e],i=t.match(/^\{(.+)\}$/);i&&(a[i[1]]=r)}for(let e of t.parameters){let t=a[e],n=r[e];if(void 0===t)throw Error(`Missing required parameter: ${e}`);if(!n){i[e]=t;continue}try{i[e]=n.parse(t)}catch(r){throw Error(`Invalid parameter "${e}": ${t}. Validation error: ${r instanceof Error?r.message:String(r)}`)}}return i}(t.href,a,r),i);if(n instanceof Promise&&(n=await n),"string"==typeof n)return{contents:[{uri:t.href,text:n}]};if(!n||"object"!=typeof n||!Array.isArray(n.contents)){let e=null===n?"null":typeof n,t=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Resource handler must return a ReadResourceResult or string. Got ${e}: ${t}
213
+ </html>`);return{contents:[{uri:a.uri,text:u,mimeType:i,_meta:a._meta}]}}catch(e){throw console.error(`React failed for ${a.name}:`,e),e}let o=a.handler({},t);if(o instanceof Promise&&(o=await o),"string"==typeof o)return{contents:[{uri:a.uri,text:o,mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"_meta"in o&&!("content"in o))return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]};if(o&&"object"==typeof o&&"content"in o&&Array.isArray(o.content)){let e=o.content.find(e=>"text"===e.type);if(e&&"text"===e.type&&"string"==typeof e.text)return{contents:[{uri:a.uri,text:e.text,mimeType:i,_meta:a._meta}]}}return{contents:[{uri:a.uri,text:"",mimeType:i,_meta:a._meta}]}};e.registerResource(a.name,a.uri,o,s)}),i.forEach((t,r)=>{let a={name:mP(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;if("object"==typeof n&&null!==n&&Object.assign(a,n),!1===a.enabled)return;let l={};mx(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let c=mE(r);if(!c)return void console.warn(`Skipping resource "${a.name}" at ${r}: Invalid file path format`);let u=c.uriTemplate;a.mimeType&&a.mimeType.includes("html")&&(u=u.endsWith(".html")?u:`${u}.html`);let d=function(e,t,r={}){let a=mE(t);if(!a)throw Error(`Invalid resource file path: ${t}. Must follow (scheme)/path/[param] convention.`);return async(t,i)=>{let n=e(function(e,t,r){let a={},i={};if(0===t.parameters.length)return i;let n=t.uriTemplate.split("://")[1]||"",o=e.split("://")[1]||"",s=n.split("/"),l=o.split("/");for(let e=0;e<s.length&&e<l.length;e++){let t=s[e],r=l[e],i=t.match(/^\{(.+)\}$/);i&&(a[i[1]]=r)}for(let e of t.parameters){let t=a[e],n=r[e];if(void 0===t)throw Error(`Missing required parameter: ${e}`);if(!n){i[e]=t;continue}try{i[e]=n.parse(t)}catch(r){throw Error(`Invalid parameter "${e}": ${t}. Validation error: ${r instanceof Error?r.message:String(r)}`)}}return i}(t.href,a,r),i);if(n instanceof Promise&&(n=await n),"string"==typeof n)return{contents:[{uri:t.href,text:n}]};if(!n||"object"!=typeof n||!Array.isArray(n.contents)){let e=null===n?"null":typeof n,t=void 0===n?"undefined":null===n?"null":"object"==typeof n?JSON.stringify(n,null,2):String(n);throw Error(`Resource handler must return a ReadResourceResult or string. Got ${e}: ${t}
214
214
 
215
215
  Expected ReadResourceResult format:
216
216
  {
@@ -219,4 +219,4 @@ Expected ReadResourceResult format:
219
219
  { uri: "resource://uri", mimeType: "application/json", text: "json content" },
220
220
  { uri: "resource://uri", blob: base64data }
221
221
  ]
222
- }`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,s);if("direct"===l.type)e.registerResource(a.name,c,a,u);else{let t=new u2(c,{list:void 0}),r=async(e,t,r)=>{let a={};for(let e of l.parameters){let r=t[e],i=s[e];if(void 0===r)throw Error(`Missing required parameter: ${e}. Available variables: ${Object.keys(t)}`);i?a[e]=i.parse(r):a[e]=r}let n=i(a,r);return n instanceof Promise&&(n=await n),"string"==typeof n?{contents:[{uri:e.href,text:n}]}:n};e.registerResource(a.name,t,a,r)}})}),e}async function mU(){let{toolModules:e,skippedTools:t}=await mz(mM);return mA(t),e}async function mF(){let{promptModules:e,skippedPrompts:t}=await mj(mL);return mO(t),e}async function mH(){let{resourceModules:e,skippedResources:t}=await mN(mZ);return mI(t),e}async function mJ(){let{instructions:e,...t}=mD,r=new u1(t,{instructions:e}),a=mU(),i=mF(),n=mH(),[o,s,l]=await Promise.all([a,i,n]);return mV(r,o,s,l)}var mK=r(8583);r.n(mK)().config();let mB=STDIO_CONFIG.debug||!1;if(STDIO_CONFIG.silent){let e=new console.Console(process.stderr,process.stderr);for(let t of["log","debug","info","warn","error","dir","table","trace","assert","time","timeEnd","timeLog","count","countReset","group","groupEnd","groupCollapsed","clear"])console[t]=e[t].bind(e)}pX({clientInfo:void 0},()=>{let e;!function(e,t={}){let r,a=t.legacy??"serve",i=t.transport??new dt,n={phase:"opening"},c=!1,u=()=>c||"closed"===n.phase,d=e=>{try{t.onerror?.(e)}catch{}},p=(e,t,r,a)=>i.send({jsonrpc:"2.0",id:e,error:{code:t,message:r,...void 0!==a&&{data:a}}}).catch(e=>d(da(e))),m=new uG(t.maxSubscriptions??1024),h=e=>{if(!iJ.safeParse(e).success)return;let t=m.routeOutbound(e);if("passthrough"!==t){for(let e of t)i.send({jsonrpc:"2.0",...e}).catch(e=>d(da(e)));return"handled"}},f=async e=>{if(lS(e)&&"subscriptions/listen"===e.method){let t,r=lg(e.params),a=ly(e.params)?(void 0===r?[]:l_(r))[0]:{key:"_meta",problem:"the per-request envelope is required on protocol revision 2026-07-28"},n=lv(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&&sR.includes(n))t=m.serve(e);else{let r=new s9({supported:[...sR],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=>d(da(e))),!0}if(iJ.safeParse(e).success&&"notifications/cancelled"===e.method){let t=e.params?.requestId;if(void 0!==t&&m.cancel(t))return!0}return!1},g=(e,t,r)=>{let a=function(e,t){switch(e.reason){case"http-method":return lT("http-method","modern-only-method-not-allowed",405,new s0(-32e3,"Method not allowed."),!0);case"batch":return lT("jsonrpc-shape","modern-only-batch-not-supported",400,new s0(sQ.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return lT("jsonrpc-shape","modern-only-response-post",400,new s0(sQ.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 lT("era-classification","modern-only-missing-envelope",400,void 0===r?new s0(sQ.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new s9({supported:[...t],requested:r}),!0)}}}({kind:"legacy",reason:t,...void 0!==r&&{requestedVersion:r}},sR);return void 0===a?Promise.resolve():(d(Error(`Rejected 2025-era request on a modern-only stdio connection (${a.cell}): ${a.message}`)),p(e.id,a.code,a.message,a.data))},y=async(t,a)=>{let n=await e({era:t}),u=n instanceof u1?n.server:n;"modern"===t&&(o(u,a),s(u,sR),m.setServerCapabilities(u.getCapabilities(),l(u)));let d=new dr(i,()=>{!c&&d!==r&&k()},"modern"===t?h:void 0);return await n.connect(d),{product:n,channel:d}},v=e=>e.product.close().catch(e=>d(da(e))),_=async e=>{r=e.channel;try{await e.channel.whenRequestsAnswered(3e3)||d(Error("Discarded the probe instance with requests still unanswered after 3000ms; continuing with the fallback")),await e.product.close()}catch(e){d(da(e))}finally{r=void 0}},b=async e=>{if("closed"===n.phase)return;if("pinned"===n.phase)return"modern"===n.era&&lS(e)&&"initialize"===e.method&&!lj(e.params)?void await g(e,"initialize",null!==e.params&&"object"==typeof e.params&&"string"==typeof e.params.protocolVersion?e.params.protocolVersion:void 0):void("modern"===n.era&&await f(e)||n.instance.channel.deliver(e));if(!lS(e)&&!iJ.safeParse(e).success)return void d(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&&!lj(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(!ly(t))return{kind:"legacy",reason:"no-claim"};let r=lg(t),a=(void 0===r?[]:l_(r))[0];if(void 0!==a)return{kind:"invalid-envelope",issue:a};let i=lv(t);return void 0!==i&&sR.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}`;lS(e)?await p(e.id,sQ.InvalidParams,r,{envelope:t.issue}):d(Error(`Discarded a notification with a malformed envelope: ${r}`));return}case"unsupported-revision":if(lS(e)){let r=new s9({supported:[...sR],requested:t.requested});d(r),await p(e.id,r.code,r.message,r.data)}else d(Error(`Discarded a notification claiming unsupported protocol revision ${t.requested}`));return;case"modern":if(lS(e)&&"server/discover"===e.method){if("probe"===n.phase)return void n.instance.channel.deliver(e,{classification:t.classification});let r=await y("modern",t.revision);if(u())return void await v(r);n={phase:"probe",instance:r},r.channel.deliver(e,{classification:t.classification});return}if("probe"===n.phase){if(iJ.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 y("modern",t.revision);if(u())return void await v(e);n={phase:"pinned",era:"modern",instance:e}}if(await f(e))return;n.instance.channel.deliver(e,{classification:t.classification});return;case"legacy":{if("reject"===a){lS(e)&&await g(e,t.reason,t.requestedVersion);return}if("probe"===n.phase){if(await _(n.instance),u())return;n={phase:"opening"}}let r=await y("legacy");if(u())return void await v(r);(n={phase:"pinned",era:"legacy",instance:r}).instance.channel.deliver(e);return}}},S=[],$=!1,w=async()=>{if(!$){$=!0;try{for(;S.length>0;){let e=S.shift();try{await b(e)}catch(t){lS(e)&&await p(e.id,sQ.InternalError,"Internal server error"),d(da(t))}}}finally{$=!1}}},k=async()=>{if(c||"closed"===n.phase)return;c=!0;let e=n;for(let e of(n={phase:"closed"},m.teardownAll()))await i.send(e).catch(e=>d(da(e)));("probe"===e.phase||"pinned"===e.phase)&&await e.instance.product.close().catch(e=>d(da(e))),await i.close().catch(e=>d(da(e)))};i.onmessage=e=>{S.push(e),w()},i.onerror=e=>{d(e),("probe"===n.phase||"pinned"===n.phase)&&n.instance.channel.onerror?.(e)},i.onclose=()=>{if(c||"closed"===n.phase)return;c=!0;let e=n;n={phase:"closed"},("probe"===e.phase||"pinned"===e.phase)&&e.instance.product.close().catch(e=>d(da(e)))},i.start().catch(e=>{throw d(da(e)),e}).catch(()=>{})}(async()=>{let e=await mJ();return e.server.oninitialized=()=>{let t=pQ(e.server.getClientVersion());pW({clientInfo:t}),mB&&t&&console.log(`[STDIO] MCP client initialized: ${t.name}@${t.version}`)},e},{legacy:"serve",onerror:mB?e=>console.error("[STDIO] Error:",e):void 0}),mB&&console.log("[STDIO] MCP Server running with STDIO transport"),e=()=>{mB&&console.log("[STDIO] Shutting down STDIO transport"),process.exit(0)},process.on("SIGINT",e),process.on("SIGTERM",e)})})(),{}})());
222
+ }`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===c.type)e.registerResource(a.name,u,mR(a),d);else{let t=Object.create(null);for(let e of c.parameters)s&&Object.hasOwn(s,e)&&(t[e]=s[e]);let r=new u2(u,{list:void 0,complete:t}),n=async(e,t,r)=>{let a={};for(let e of c.parameters){let r=t[e],i=l[e];if(void 0===r)throw Error(`Missing required parameter: ${e}. Available variables: ${Object.keys(t)}`);i?a[e]=i.parse(r):a[e]=r}let n=i(a,r);return n instanceof Promise&&(n=await n),"string"==typeof n?{contents:[{uri:e.href,text:n}]}:n};e.registerResource(a.name,r,mR(a),n)}})}),e}async function mF(){let{toolModules:e,skippedTools:t}=await mA(mL);return mM(t),e}async function mH(){let{promptModules:e,skippedPrompts:t}=await mO(mZ);return mC(t),e}async function mJ(){let{resourceModules:e,skippedResources:t}=await mI(mD);return mq(t),e}async function mK(){let{instructions:e,...t}=mV,r=new u1(t,{instructions:e}),a=mF(),i=mH(),n=mJ(),[o,s,l]=await Promise.all([a,i,n]);return mU(r,o,s,l)}var mB=r(8583);r.n(mB)().config();let mG=STDIO_CONFIG.debug||!1;if(STDIO_CONFIG.silent){let e=new console.Console(process.stderr,process.stderr);for(let t of["log","debug","info","warn","error","dir","table","trace","assert","time","timeEnd","timeLog","count","countReset","group","groupEnd","groupCollapsed","clear"])console[t]=e[t].bind(e)}pX({clientInfo:void 0},()=>{let e;!function(e,t={}){let r,a=t.legacy??"serve",i=t.transport??new dt,n={phase:"opening"},c=!1,u=()=>c||"closed"===n.phase,d=e=>{try{t.onerror?.(e)}catch{}},p=(e,t,r,a)=>i.send({jsonrpc:"2.0",id:e,error:{code:t,message:r,...void 0!==a&&{data:a}}}).catch(e=>d(da(e))),m=new uG(t.maxSubscriptions??1024),h=e=>{if(!iJ.safeParse(e).success)return;let t=m.routeOutbound(e);if("passthrough"!==t){for(let e of t)i.send({jsonrpc:"2.0",...e}).catch(e=>d(da(e)));return"handled"}},f=async e=>{if(lS(e)&&"subscriptions/listen"===e.method){let t,r=lg(e.params),a=ly(e.params)?(void 0===r?[]:l_(r))[0]:{key:"_meta",problem:"the per-request envelope is required on protocol revision 2026-07-28"},n=lv(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&&sR.includes(n))t=m.serve(e);else{let r=new s9({supported:[...sR],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=>d(da(e))),!0}if(iJ.safeParse(e).success&&"notifications/cancelled"===e.method){let t=e.params?.requestId;if(void 0!==t&&m.cancel(t))return!0}return!1},g=(e,t,r)=>{let a=function(e,t){switch(e.reason){case"http-method":return lT("http-method","modern-only-method-not-allowed",405,new s0(-32e3,"Method not allowed."),!0);case"batch":return lT("jsonrpc-shape","modern-only-batch-not-supported",400,new s0(sQ.InvalidRequest,"Bad Request: JSON-RPC batches are not supported by this endpoint"),!0);case"response":return lT("jsonrpc-shape","modern-only-response-post",400,new s0(sQ.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 lT("era-classification","modern-only-missing-envelope",400,void 0===r?new s0(sQ.UnsupportedProtocolVersion,"Unsupported protocol version: the request did not name a protocol version",{supported:[...t]}):new s9({supported:[...t],requested:r}),!0)}}}({kind:"legacy",reason:t,...void 0!==r&&{requestedVersion:r}},sR);return void 0===a?Promise.resolve():(d(Error(`Rejected 2025-era request on a modern-only stdio connection (${a.cell}): ${a.message}`)),p(e.id,a.code,a.message,a.data))},y=async(t,a)=>{let n=await e({era:t}),u=n instanceof u1?n.server:n;"modern"===t&&(o(u,a),s(u,sR),m.setServerCapabilities(u.getCapabilities(),l(u)));let d=new dr(i,()=>{!c&&d!==r&&k()},"modern"===t?h:void 0);return await n.connect(d),{product:n,channel:d}},v=e=>e.product.close().catch(e=>d(da(e))),_=async e=>{r=e.channel;try{await e.channel.whenRequestsAnswered(3e3)||d(Error("Discarded the probe instance with requests still unanswered after 3000ms; continuing with the fallback")),await e.product.close()}catch(e){d(da(e))}finally{r=void 0}},b=async e=>{if("closed"===n.phase)return;if("pinned"===n.phase)return"modern"===n.era&&lS(e)&&"initialize"===e.method&&!lj(e.params)?void await g(e,"initialize",null!==e.params&&"object"==typeof e.params&&"string"==typeof e.params.protocolVersion?e.params.protocolVersion:void 0):void("modern"===n.era&&await f(e)||n.instance.channel.deliver(e));if(!lS(e)&&!iJ.safeParse(e).success)return void d(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&&!lj(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(!ly(t))return{kind:"legacy",reason:"no-claim"};let r=lg(t),a=(void 0===r?[]:l_(r))[0];if(void 0!==a)return{kind:"invalid-envelope",issue:a};let i=lv(t);return void 0!==i&&sR.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}`;lS(e)?await p(e.id,sQ.InvalidParams,r,{envelope:t.issue}):d(Error(`Discarded a notification with a malformed envelope: ${r}`));return}case"unsupported-revision":if(lS(e)){let r=new s9({supported:[...sR],requested:t.requested});d(r),await p(e.id,r.code,r.message,r.data)}else d(Error(`Discarded a notification claiming unsupported protocol revision ${t.requested}`));return;case"modern":if(lS(e)&&"server/discover"===e.method){if("probe"===n.phase)return void n.instance.channel.deliver(e,{classification:t.classification});let r=await y("modern",t.revision);if(u())return void await v(r);n={phase:"probe",instance:r},r.channel.deliver(e,{classification:t.classification});return}if("probe"===n.phase){if(iJ.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 y("modern",t.revision);if(u())return void await v(e);n={phase:"pinned",era:"modern",instance:e}}if(await f(e))return;n.instance.channel.deliver(e,{classification:t.classification});return;case"legacy":{if("reject"===a){lS(e)&&await g(e,t.reason,t.requestedVersion);return}if("probe"===n.phase){if(await _(n.instance),u())return;n={phase:"opening"}}let r=await y("legacy");if(u())return void await v(r);(n={phase:"pinned",era:"legacy",instance:r}).instance.channel.deliver(e);return}}},S=[],$=!1,w=async()=>{if(!$){$=!0;try{for(;S.length>0;){let e=S.shift();try{await b(e)}catch(t){lS(e)&&await p(e.id,sQ.InternalError,"Internal server error"),d(da(t))}}}finally{$=!1}}},k=async()=>{if(c||"closed"===n.phase)return;c=!0;let e=n;for(let e of(n={phase:"closed"},m.teardownAll()))await i.send(e).catch(e=>d(da(e)));("probe"===e.phase||"pinned"===e.phase)&&await e.instance.product.close().catch(e=>d(da(e))),await i.close().catch(e=>d(da(e)))};i.onmessage=e=>{S.push(e),w()},i.onerror=e=>{d(e),("probe"===n.phase||"pinned"===n.phase)&&n.instance.channel.onerror?.(e)},i.onclose=()=>{if(c||"closed"===n.phase)return;c=!0;let e=n;n={phase:"closed"},("probe"===e.phase||"pinned"===e.phase)&&e.instance.product.close().catch(e=>d(da(e)))},i.start().catch(e=>{throw d(da(e)),e}).catch(()=>{})}(async()=>{let e=await mK();return e.server.oninitialized=()=>{let t=pQ(e.server.getClientVersion());pW({clientInfo:t}),mG&&t&&console.log(`[STDIO] MCP client initialized: ${t.name}@${t.version}`)},e},{legacy:"serve",onerror:mG?e=>console.error("[STDIO] Error:",e):void 0}),mG&&console.log("[STDIO] MCP Server running with STDIO transport"),e=()=>{mG&&console.log("[STDIO] Shutting down STDIO transport"),process.exit(0)},process.on("SIGINT",e),process.on("SIGTERM",e)})})(),{}})());
@@ -0,0 +1,9 @@
1
+ import type { ComponentMetadata } from "@/types/component";
2
+ /** Keep framework options off the wire and put tags in the MCP metadata map. */
3
+ export declare function toMcpMetadata<T extends ComponentMetadata & {
4
+ _meta?: Record<string, unknown>;
5
+ }>(metadata: T): Omit<T, "tags" | "enabled"> & {
6
+ _meta: T["_meta"] | {
7
+ "xmcp/tags": string[];
8
+ } | undefined;
9
+ };
@@ -0,0 +1,7 @@
1
+ import type { AudioContent, EmbeddedResource, ImageContent } from "@modelcontextprotocol/server";
2
+ /** Create an MCP image content block from raw bytes. */
3
+ export declare function image(bytes: Uint8Array | ArrayBuffer, mimeType: string): ImageContent;
4
+ /** Create an MCP audio content block from raw bytes. */
5
+ export declare function audio(bytes: Uint8Array | ArrayBuffer, mimeType: string): AudioContent;
6
+ /** Embed text or binary resource contents without registering a resource. */
7
+ export declare function embeddedResource(uri: string, content: string | Uint8Array | ArrayBuffer, mimeType?: string): EmbeddedResource;
@@ -6,7 +6,7 @@ import { UserToolHandler } from "./transformers/tool";
6
6
  import { UserPromptHandler } from "./transformers/prompt";
7
7
  import { UserResourceHandler } from "./transformers/resource";
8
8
  import { ZodRawShape } from "zod/v3";
9
- import { ResourceMetadata } from "@/types/resource";
9
+ import { ResourceMetadata, ResourceCompletions } from "@/types/resource";
10
10
  export type ToolFile = {
11
11
  metadata: ToolMetadata;
12
12
  schema: ZodRawShape;
@@ -21,6 +21,7 @@ export type PromptFile = {
21
21
  export type ResourceFile = {
22
22
  metadata: ResourceMetadata;
23
23
  schema: ZodRawShape;
24
+ complete?: ResourceCompletions;
24
25
  default: UserResourceHandler;
25
26
  };
26
27
  export declare const injectedTools: Record<string, () => Promise<ToolFile>>;