xmcp 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cloudflare.d.ts +1 -0
- package/dist/cloudflare.js +2 -2
- package/dist/config/index.d.ts +5 -5
- package/dist/config/schemas/experimental/index.d.ts +4 -4
- package/dist/config.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +13 -13
- package/dist/node.d.ts +55 -0
- package/dist/node.js +1 -0
- package/dist/runtime/adapter-express.js +2 -2
- package/dist/runtime/adapter-fastify.js +2 -2
- package/dist/runtime/adapter-nestjs.js +2 -2
- package/dist/runtime/adapter-nextjs.js +2 -2
- package/dist/runtime/adapter-tanstack-cloudflare.js +240 -0
- package/dist/runtime/adapter-tanstack.js +244 -0
- package/dist/runtime/cloudflare-worker.js +2 -2
- package/dist/runtime/http.js +2 -2
- package/dist/runtime/stdio.js +2 -2
- package/dist/runtime/utils/content.d.ts +7 -0
- package/dist/runtime/utils/server.d.ts +2 -1
- package/dist/runtime/vercel.js +2 -2
- package/dist/types/declarations.d.ts +3 -0
- package/dist/types/resource.d.ts +3 -0
- package/package.json +9 -2
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Read an image file as an MCP content block. The MIME type is explicit. */
|
|
2
|
+
export declare function imageFromFile(path: string | URL, mimeType: string): Promise<{
|
|
3
|
+
type: "image";
|
|
4
|
+
data: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
annotations?: {
|
|
7
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
8
|
+
priority?: number | undefined;
|
|
9
|
+
lastModified?: string | undefined;
|
|
10
|
+
} | undefined;
|
|
11
|
+
_meta?: {
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
} | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
/** Read an audio file as an MCP content block. The MIME type is explicit. */
|
|
16
|
+
export declare function audioFromFile(path: string | URL, mimeType: string): Promise<{
|
|
17
|
+
type: "audio";
|
|
18
|
+
data: string;
|
|
19
|
+
mimeType: string;
|
|
20
|
+
annotations?: {
|
|
21
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
22
|
+
priority?: number | undefined;
|
|
23
|
+
lastModified?: string | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
_meta?: {
|
|
26
|
+
[x: string]: unknown;
|
|
27
|
+
} | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
/** Read a file into a base64 resource blob with the supplied resource URI. */
|
|
30
|
+
export declare function embeddedResourceFromFile(path: string | URL, uri: string, mimeType?: string): Promise<{
|
|
31
|
+
type: "resource";
|
|
32
|
+
resource: {
|
|
33
|
+
uri: string;
|
|
34
|
+
text: string;
|
|
35
|
+
mimeType?: string | undefined;
|
|
36
|
+
_meta?: {
|
|
37
|
+
[x: string]: unknown;
|
|
38
|
+
} | undefined;
|
|
39
|
+
} | {
|
|
40
|
+
uri: string;
|
|
41
|
+
blob: string;
|
|
42
|
+
mimeType?: string | undefined;
|
|
43
|
+
_meta?: {
|
|
44
|
+
[x: string]: unknown;
|
|
45
|
+
} | undefined;
|
|
46
|
+
};
|
|
47
|
+
annotations?: {
|
|
48
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
49
|
+
priority?: number | undefined;
|
|
50
|
+
lastModified?: string | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
_meta?: {
|
|
53
|
+
[x: string]: unknown;
|
|
54
|
+
} | undefined;
|
|
55
|
+
}>;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={};e.d=(r,o)=>{for(var t in o)e.o(o,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:o[t]})},e.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};e.r(r),e.d(r,{audioFromFile:()=>a,embeddedResourceFromFile:()=>n,imageFromFile:()=>i});let o=require("node:fs/promises");function t(e){let r;if(e instanceof Uint8Array)r=e;else if(e instanceof ArrayBuffer)r=new Uint8Array(e);else throw TypeError("Expected bytes as a Uint8Array or ArrayBuffer");let o="";for(let e=0;e<r.length;e+=32768)o+=String.fromCharCode(...r.subarray(e,e+32768));return btoa(o)}async function i(e,r){var i;return i=await (0,o.readFile)(e),{type:"image",data:t(i),mimeType:r}}async function a(e,r){var i;return i=await (0,o.readFile)(e),{type:"audio",data:t(i),mimeType:r}}async function n(e,r,i){var a;return a=await (0,o.readFile)(e),{type:"resource",resource:{uri:r,...void 0===i?{}:{mimeType:i},..."string"==typeof a?{text:a}:{blob:t(a)}}}}for(var d in exports.audioFromFile=r.audioFromFile,exports.embeddedResourceFromFile=r.embeddedResourceFromFile,exports.imageFromFile=r.imageFromFile,r)-1===["audioFromFile","embeddedResourceFromFile","imageFromFile"].indexOf(d)&&(exports[d]=r[d]);Object.defineProperty(exports,"__esModule",{value:!0})})();
|
|
@@ -226,7 +226,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let l=s.js
|
|
|
226
226
|
<div id="root"></div>
|
|
227
227
|
${e}
|
|
228
228
|
</body>
|
|
229
|
-
</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:hu(r),description:"No description provided"},{default:i,metadata:n,schema:o}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let
|
|
229
|
+
</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:hu(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let l={};hc(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let c=hd(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=hd(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}
|
|
230
230
|
|
|
231
231
|
Expected ReadResourceResult format:
|
|
232
232
|
{
|
|
@@ -235,7 +235,7 @@ Expected ReadResourceResult format:
|
|
|
235
235
|
{ uri: "resource://uri", mimeType: "application/json", text: "json content" },
|
|
236
236
|
{ uri: "resource://uri", blob: base64data }
|
|
237
237
|
]
|
|
238
|
-
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,
|
|
238
|
+
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===c.type)e.registerResource(a.name,u,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 dh(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,a,n)}})}),e}async function hP(){let{toolModules:e,skippedTools:t}=await hb(h$);return hS(t),e}async function hE(){let{promptModules:e,skippedPrompts:t}=await hh(hw);return hf(t),e}async function hT(){let{resourceModules:e,skippedResources:t}=await hg(hR);return hv(t),e}async function hj(){let{instructions:e,...t}=hk,r=new dm(t,{instructions:e}),a=hP(),i=hE(),n=hT(),[o,s,l]=await Promise.all([a,i,n]);return hx(r,o,s,l)}let hC=require("node:crypto"),hO=HTTP_CORS_CONFIG,hI=(_=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t;if("function"==typeof a)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let o=new Set,d=!1,p=e=>{try{i?.(e)}catch{}},m=t.bus??new di(p),h={toolsChanged:()=>m.publish({kind:"tools_list_changed"}),promptsChanged:()=>m.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>m.publish({kind:"resources_list_changed"}),resourceUpdated:e=>m.publish({kind:"resource_updated",uri:e})},f=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,l){var c,u,d;let p,m,h,f,y,g,v;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),dn(e.id,-32603,"Subscription limit reached");let _=(c=e,(y=lf(lh).validateRequest("subscriptions/listen",c)).ok?y.value.params?.notifications:void 0);if(void 0===_)return dn(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let b=(u=_,d=s,g={},v=e=>void 0===d||!0===e,!0===u.toolsListChanged&&v(d?.tools?.listChanged)&&(g.toolsListChanged=!0),!0===u.promptsListChanged&&v(d?.prompts?.listChanged)&&(g.promptsListChanged=!0),!0===u.resourcesListChanged&&v(d?.resources?.listChanged)&&(g.resourcesListChanged=!0),void 0!==u.resourceSubscriptions&&u.resourceSubscriptions.length>0&&v(d?.resources?.subscribe)&&(g.resourceSubscriptions=[...u.resourceSubscriptions]),g),S=e.id,$=new TextEncoder,w=!1,R=e=>{if(!w)try{p.enqueue($.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},k=(e,t)=>{R(`event: message
|
|
239
239
|
data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
240
240
|
|
|
241
241
|
`)},x=e=>{if(!w){e&&R(`event: message
|
|
@@ -226,7 +226,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let l=s.js
|
|
|
226
226
|
<div id="root"></div>
|
|
227
227
|
${e}
|
|
228
228
|
</body>
|
|
229
|
-
</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:hu(r),description:"No description provided"},{default:i,metadata:n,schema:o}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let
|
|
229
|
+
</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:hu(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let l={};hc(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let c=hd(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=hd(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}
|
|
230
230
|
|
|
231
231
|
Expected ReadResourceResult format:
|
|
232
232
|
{
|
|
@@ -235,7 +235,7 @@ Expected ReadResourceResult format:
|
|
|
235
235
|
{ uri: "resource://uri", mimeType: "application/json", text: "json content" },
|
|
236
236
|
{ uri: "resource://uri", blob: base64data }
|
|
237
237
|
]
|
|
238
|
-
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,
|
|
238
|
+
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===c.type)e.registerResource(a.name,u,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 dh(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,a,n)}})}),e}async function hP(){let{toolModules:e,skippedTools:t}=await hb(h$);return hS(t),e}async function hE(){let{promptModules:e,skippedPrompts:t}=await hh(hw);return hf(t),e}async function hT(){let{resourceModules:e,skippedResources:t}=await hg(hR);return hv(t),e}async function hj(){let{instructions:e,...t}=hk,r=new dm(t,{instructions:e}),a=hP(),i=hE(),n=hT(),[o,s,l]=await Promise.all([a,i,n]);return hx(r,o,s,l)}let hC=require("node:crypto"),hO=HTTP_CORS_CONFIG,hI=(_=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t;if("function"==typeof a)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let o=new Set,d=!1,p=e=>{try{i?.(e)}catch{}},m=t.bus??new di(p),h={toolsChanged:()=>m.publish({kind:"tools_list_changed"}),promptsChanged:()=>m.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>m.publish({kind:"resources_list_changed"}),resourceUpdated:e=>m.publish({kind:"resource_updated",uri:e})},f=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,l){var c,u,d;let p,m,h,f,y,g,v;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),dn(e.id,-32603,"Subscription limit reached");let _=(c=e,(y=lf(lh).validateRequest("subscriptions/listen",c)).ok?y.value.params?.notifications:void 0);if(void 0===_)return dn(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let b=(u=_,d=s,g={},v=e=>void 0===d||!0===e,!0===u.toolsListChanged&&v(d?.tools?.listChanged)&&(g.toolsListChanged=!0),!0===u.promptsListChanged&&v(d?.prompts?.listChanged)&&(g.promptsListChanged=!0),!0===u.resourcesListChanged&&v(d?.resources?.listChanged)&&(g.resourcesListChanged=!0),void 0!==u.resourceSubscriptions&&u.resourceSubscriptions.length>0&&v(d?.resources?.subscribe)&&(g.resourceSubscriptions=[...u.resourceSubscriptions]),g),S=e.id,$=new TextEncoder,w=!1,R=e=>{if(!w)try{p.enqueue($.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},k=(e,t)=>{R(`event: message
|
|
239
239
|
data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
240
240
|
|
|
241
241
|
`)},x=e=>{if(!w){e&&R(`event: message
|
|
@@ -226,7 +226,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let c=s.js
|
|
|
226
226
|
<div id="root"></div>
|
|
227
227
|
${e}
|
|
228
228
|
</body>
|
|
229
|
-
</html>`);return{contents:[{uri:a.uri,text:p,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,a)=>{let r={name:fu(a),description:"No description provided"},{default:i,metadata:n,schema:o}=t;"object"==typeof n&&null!==n&&Object.assign(r,n);let
|
|
229
|
+
</html>`);return{contents:[{uri:a.uri,text:p,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,a)=>{let r={name:fu(a),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;"object"==typeof n&&null!==n&&Object.assign(r,n);let c={};fp(o)?c=o:null!=o&&console.warn(`Invalid schema for resource "${r.name}" at ${a}. Expected Record<string, z.ZodType>`);let l=fd(a);if(!l)return void console.warn(`Skipping resource "${r.name}" at ${a}: Invalid file path format`);let p=l.uriTemplate;r.mimeType&&r.mimeType.includes("html")&&(p=p.endsWith(".html")?p:`${p}.html`);let u=function(e,t,a={}){let r=fd(t);if(!r)throw Error(`Invalid resource file path: ${t}. Must follow (scheme)/path/[param] convention.`);return async(t,i)=>{let n=e(function(e,t,a){let r={},i={};if(0===t.parameters.length)return i;let n=t.uriTemplate.split("://")[1]||"",o=e.split("://")[1]||"",s=n.split("/"),c=o.split("/");for(let e=0;e<s.length&&e<c.length;e++){let t=s[e],a=c[e],i=t.match(/^\{(.+)\}$/);i&&(r[i[1]]=a)}for(let e of t.parameters){let t=r[e],n=a[e];if(void 0===t)throw Error(`Missing required parameter: ${e}`);if(!n){i[e]=t;continue}try{i[e]=n.parse(t)}catch(a){throw Error(`Invalid parameter "${e}": ${t}. Validation error: ${a instanceof Error?a.message:String(a)}`)}}return i}(t.href,r,a),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}
|
|
230
230
|
|
|
231
231
|
Expected ReadResourceResult format:
|
|
232
232
|
{
|
|
@@ -235,7 +235,7 @@ Expected ReadResourceResult format:
|
|
|
235
235
|
{ uri: "resource://uri", mimeType: "application/json", text: "json content" },
|
|
236
236
|
{ uri: "resource://uri", blob: base64data }
|
|
237
237
|
]
|
|
238
|
-
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,a,
|
|
238
|
+
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,a,c);if("direct"===l.type)e.registerResource(r.name,p,r,u);else{let t=Object.create(null);for(let e of l.parameters)s&&Object.hasOwn(s,e)&&(t[e]=s[e]);let a=new uf(p,{list:void 0,complete:t}),n=async(e,t,a)=>{let r={};for(let e of l.parameters){let a=t[e],i=c[e];if(void 0===a)throw Error(`Missing required parameter: ${e}. Available variables: ${Object.keys(t)}`);i?r[e]=i.parse(a):r[e]=a}let n=i(r,a);return n instanceof Promise&&(n=await n),"string"==typeof n?{contents:[{uri:e.href,text:n}]}:n};e.registerResource(r.name,a,r,n)}})}),e}async function fR(){let{toolModules:e,skippedTools:t}=await f_(fS);return fw(t),e}async function fT(){let{promptModules:e,skippedPrompts:t}=await fh(fk);return fv(t),e}async function fP(){let{resourceModules:e,skippedResources:t}=await fy(f$);return fb(t),e}async function fO(){let{instructions:e,...t}=fj,a=new um(t,{instructions:e}),r=fR(),i=fT(),n=fP(),[o,s,c]=await Promise.all([r,i,n]);return fE(a,o,s,c)}let fC=require("node:crypto"),fA=HTTP_CORS_CONFIG,fq=(b=function(e,t={}){var a;let{legacy:r,onerror:i,responseMode:n}=t;if("function"==typeof r)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let o=new Set,u=!1,d=e=>{try{i?.(e)}catch{}},m=t.bus??new un(d),f={toolsChanged:()=>m.publish({kind:"tools_list_changed"}),promptsChanged:()=>m.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>m.publish({kind:"resources_list_changed"}),resourceUpdated:e=>m.publish({kind:"resource_updated",uri:e})},h=function(e){let{bus:t,onerror:a}=e,r=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,c){var l,p,u;let d,m,f,h,v,g,y;if(n.size>=r)return a?.(Error(`subscriptions/listen refused: subscription limit reached (${r})`)),uo(e.id,-32603,"Subscription limit reached");let b=(l=e,(v=cv(ch).validateRequest("subscriptions/listen",l)).ok?v.value.params?.notifications:void 0);if(void 0===b)return uo(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let x=(p=b,u=s,g={},y=e=>void 0===u||!0===e,!0===p.toolsListChanged&&y(u?.tools?.listChanged)&&(g.toolsListChanged=!0),!0===p.promptsListChanged&&y(u?.prompts?.listChanged)&&(g.promptsListChanged=!0),!0===p.resourcesListChanged&&y(u?.resources?.listChanged)&&(g.resourcesListChanged=!0),void 0!==p.resourceSubscriptions&&p.resourceSubscriptions.length>0&&y(u?.resources?.subscribe)&&(g.resourceSubscriptions=[...p.resourceSubscriptions]),g),_=e.id,w=new TextEncoder,S=!1,k=e=>{if(!S)try{d.enqueue(w.encode(e))}catch(e){a?.(e instanceof Error?e:Error(String(e)))}},$=(e,t)=>{k(`event: message
|
|
239
239
|
data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
240
240
|
|
|
241
241
|
`)},j=e=>{if(!S){e&&k(`event: message
|
|
@@ -226,7 +226,7 @@ Please re-run the build so the framework can regenerate the bundle.`);let l=s.js
|
|
|
226
226
|
<div id="root"></div>
|
|
227
227
|
${e}
|
|
228
228
|
</body>
|
|
229
|
-
</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:mQ(r),description:"No description provided"},{default:i,metadata:n,schema:o}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let
|
|
229
|
+
</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:mQ(r),description:"No description provided"},{default:i,metadata:n,schema:o,complete:s}=t;"object"==typeof n&&null!==n&&Object.assign(a,n);let l={};mY(o)?l=o:null!=o&&console.warn(`Invalid schema for resource "${a.name}" at ${r}. Expected Record<string, z.ZodType>`);let c=m0(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=m0(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}
|
|
230
230
|
|
|
231
231
|
Expected ReadResourceResult format:
|
|
232
232
|
{
|
|
@@ -235,7 +235,7 @@ Expected ReadResourceResult format:
|
|
|
235
235
|
{ uri: "resource://uri", mimeType: "application/json", text: "json content" },
|
|
236
236
|
{ uri: "resource://uri", blob: base64data }
|
|
237
237
|
]
|
|
238
|
-
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,
|
|
238
|
+
}`)}return n.contents.forEach(e=>{e.uri||(e.uri=t.href)}),n}}(i,r,l);if("direct"===c.type)e.registerResource(a.name,u,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 dp(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,a,n)}})}),e}async function ho(){let{toolModules:e,skippedTools:t}=await m7(ht);return he(t),e}async function hs(){let{promptModules:e,skippedPrompts:t}=await m9(hr);return m4(t),e}async function hl(){let{resourceModules:e,skippedResources:t}=await m6(ha);return m5(t),e}async function hc(){let e=ho(),t=hs(),r=hl(),[a,i,n]=await Promise.all([e,t,r]),{instructions:o,...s}=hi,l=new dd(s,{instructions:o});return await hn(l,a,i,n),l}let hu=require("node:crypto"),hd={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, OPTIONS","Access-Control-Allow-Headers":"*","Access-Control-Max-Age":"86400"};function hp(e,t,r,a,i){let n=new URL(e.url).origin,o=`${n}/.well-known/oauth-protected-resource`;return new Response(JSON.stringify({jsonrpc:"2.0",error:{code:i,message:r},id:null}),{status:a,headers:{"WWW-Authenticate":`Bearer error="${t}", error_description="${r}", resource_metadata="${o}"`,"Content-Type":"application/json"}})}function hm(e,t){return async r=>{var a,i;let n,{verifyToken:o,required:s=!1,requiredScopes:l}=t,c=function(e){let t=e.headers.get("Authorization"),[r,a]=t?.split(" ")||[];return r?.toLowerCase()==="bearer"?a:void 0}(r);try{n=await o(r,c)}catch(e){return console.error("[MCP Auth] Error verifying token:",e),hp(r,"invalid_token","Invalid token",401,-32001)}return s&&!n?hp(r,"invalid_token","No authorization provided",401,-32001):n?void 0!==(a=n).expiresAt&&a.expiresAt<Date.now()/1e3?hp(r,"invalid_token","Token has expired",401,-32001):l?.length&&(i=n,!l.every(e=>i.scopes.includes(e)))?hp(r,"insufficient_scope","Insufficient scope",403,-32002):(r.auth=n,e(r)):e(r)}}function hh(e){return t=>{let r;return new Response(JSON.stringify({resource:((r=new URL(t.url)).pathname=r.pathname.replace(/^\/\.well-known\/[^\/]+/,""),"/"===r.pathname?r.toString().replace(/\/$/,""):r.toString()),authorization_servers:e.authorizationServers}),{headers:{...hd,"Cache-Control":"max-age=3600","Content-Type":"application/json"}})}}function hf(e){return new Response(null,{status:200,headers:hd})}let hg=function(e,t={}){var r;let{legacy:a,onerror:i,responseMode:n}=t;if("function"==typeof a)throw TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");let o=new Set,d=!1,p=e=>{try{i?.(e)}catch{}},m=t.bus??new dr(p),h={toolsChanged:()=>m.publish({kind:"tools_list_changed"}),promptsChanged:()=>m.publish({kind:"prompts_list_changed"}),resourcesChanged:()=>m.publish({kind:"resources_list_changed"}),resourceUpdated:e=>m.publish({kind:"resource_updated",uri:e})},f=function(e){let{bus:t,onerror:r}=e,a=e.maxSubscriptions??1024,i=e.keepAliveMs??15e3,n=new Set;return{serve:function(e,o,s,l){var c,u,d;let p,m,h,f,g,y,v;if(n.size>=a)return r?.(Error(`subscriptions/listen refused: subscription limit reached (${a})`)),da(e.id,-32603,"Subscription limit reached");let _=(c=e,(g=lm(lp).validateRequest("subscriptions/listen",c)).ok?g.value.params?.notifications:void 0);if(void 0===_)return da(e.id,-32602,"Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");let b=(u=_,d=s,y={},v=e=>void 0===d||!0===e,!0===u.toolsListChanged&&v(d?.tools?.listChanged)&&(y.toolsListChanged=!0),!0===u.promptsListChanged&&v(d?.prompts?.listChanged)&&(y.promptsListChanged=!0),!0===u.resourcesListChanged&&v(d?.resources?.listChanged)&&(y.resourcesListChanged=!0),void 0!==u.resourceSubscriptions&&u.resourceSubscriptions.length>0&&v(d?.resources?.subscribe)&&(y.resourceSubscriptions=[...u.resourceSubscriptions]),y),S=e.id,$=new TextEncoder,w=!1,R=e=>{if(!w)try{p.enqueue($.encode(e))}catch(e){r?.(e instanceof Error?e:Error(String(e)))}},k=(e,t)=>{R(`event: message
|
|
239
239
|
data: ${JSON.stringify({jsonrpc:"2.0",method:e,params:t})}
|
|
240
240
|
|
|
241
241
|
`)},x=e=>{if(!w){e&&R(`event: message
|