xmcp 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2 -2
- package/dist/compiler/compiler-context.d.ts +4 -0
- package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
- package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
- package/dist/compiler/parse-xmcp-config.d.ts +18 -4
- package/dist/runtime/adapter-express.js +1 -1
- package/dist/runtime/adapter-express.js.LICENSE.txt +237 -0
- package/dist/runtime/adapter-nextjs.js +2 -1
- package/dist/runtime/{118.js.LICENSE.txt → adapter-nextjs.js.LICENSE.txt} +2 -0
- package/dist/runtime/headers.js +1 -1
- package/dist/runtime/http.js +1 -1
- package/dist/runtime/http.js.LICENSE.txt +237 -0
- package/dist/runtime/stdio.js +2 -1
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/fs-utils.d.ts +1 -0
- package/dist/utils/path-validation.d.ts +3 -0
- package/package.json +7 -6
- package/dist/runtime/118.js +0 -2
- package/dist/runtime/267.js +0 -1
- package/dist/runtime/382.js +0 -1
- package/dist/runtime/386.js +0 -2
- package/dist/runtime/562.js +0 -2
- package/dist/runtime/562.js.LICENSE.txt +0 -197
- package/dist/runtime/895.js +0 -1
- /package/dist/runtime/{386.js.LICENSE.txt → stdio.js.LICENSE.txt} +0 -0
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* accepts
|
|
3
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
4
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
5
|
-
* MIT Licensed
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/*!
|
|
9
|
-
* body-parser
|
|
10
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
11
|
-
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
12
|
-
* MIT Licensed
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/*!
|
|
16
|
-
* body-parser
|
|
17
|
-
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
18
|
-
* MIT Licensed
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/*!
|
|
22
|
-
* content-disposition
|
|
23
|
-
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
24
|
-
* MIT Licensed
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/*!
|
|
28
|
-
* cookie
|
|
29
|
-
* Copyright(c) 2012-2014 Roman Shtylman
|
|
30
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
31
|
-
* MIT Licensed
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/*!
|
|
35
|
-
* destroy
|
|
36
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
37
|
-
* Copyright(c) 2015-2022 Douglas Christopher Wilson
|
|
38
|
-
* MIT Licensed
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/*!
|
|
42
|
-
* ee-first
|
|
43
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
44
|
-
* MIT Licensed
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/*!
|
|
48
|
-
* encodeurl
|
|
49
|
-
* Copyright(c) 2016 Douglas Christopher Wilson
|
|
50
|
-
* MIT Licensed
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
/*!
|
|
54
|
-
* escape-html
|
|
55
|
-
* Copyright(c) 2012-2013 TJ Holowaychuk
|
|
56
|
-
* Copyright(c) 2015 Andreas Lubbe
|
|
57
|
-
* Copyright(c) 2015 Tiancheng "Timothy" Gu
|
|
58
|
-
* MIT Licensed
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/*!
|
|
62
|
-
* etag
|
|
63
|
-
* Copyright(c) 2014-2016 Douglas Christopher Wilson
|
|
64
|
-
* MIT Licensed
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/*!
|
|
68
|
-
* express
|
|
69
|
-
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
70
|
-
* Copyright(c) 2013 Roman Shtylman
|
|
71
|
-
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
72
|
-
* MIT Licensed
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/*!
|
|
76
|
-
* express
|
|
77
|
-
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
78
|
-
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
79
|
-
* MIT Licensed
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
/*!
|
|
83
|
-
* finalhandler
|
|
84
|
-
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
85
|
-
* MIT Licensed
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
/*!
|
|
89
|
-
* forwarded
|
|
90
|
-
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
91
|
-
* MIT Licensed
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
/*!
|
|
95
|
-
* fresh
|
|
96
|
-
* Copyright(c) 2012 TJ Holowaychuk
|
|
97
|
-
* Copyright(c) 2016-2017 Douglas Christopher Wilson
|
|
98
|
-
* MIT Licensed
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
/*!
|
|
102
|
-
* media-typer
|
|
103
|
-
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
104
|
-
* MIT Licensed
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
/*!
|
|
108
|
-
* merge-descriptors
|
|
109
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
110
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
111
|
-
* MIT Licensed
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
/*!
|
|
115
|
-
* methods
|
|
116
|
-
* Copyright(c) 2013-2014 TJ Holowaychuk
|
|
117
|
-
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
118
|
-
* MIT Licensed
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
/*!
|
|
122
|
-
* mime-db
|
|
123
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
124
|
-
* Copyright(c) 2015-2022 Douglas Christopher Wilson
|
|
125
|
-
* MIT Licensed
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
/*!
|
|
129
|
-
* mime-types
|
|
130
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
131
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
132
|
-
* MIT Licensed
|
|
133
|
-
*/
|
|
134
|
-
|
|
135
|
-
/*!
|
|
136
|
-
* negotiator
|
|
137
|
-
* Copyright(c) 2012 Federico Romero
|
|
138
|
-
* Copyright(c) 2012-2014 Isaac Z. Schlueter
|
|
139
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
140
|
-
* MIT Licensed
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
/*!
|
|
144
|
-
* on-finished
|
|
145
|
-
* Copyright(c) 2013 Jonathan Ong
|
|
146
|
-
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
147
|
-
* MIT Licensed
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
/*!
|
|
151
|
-
* parseurl
|
|
152
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
153
|
-
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
154
|
-
* MIT Licensed
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
|
-
/*!
|
|
158
|
-
* proxy-addr
|
|
159
|
-
* Copyright(c) 2014-2016 Douglas Christopher Wilson
|
|
160
|
-
* MIT Licensed
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
/*!
|
|
164
|
-
* range-parser
|
|
165
|
-
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
166
|
-
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
167
|
-
* MIT Licensed
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
/*!
|
|
171
|
-
* raw-body
|
|
172
|
-
* Copyright(c) 2013-2014 Jonathan Ong
|
|
173
|
-
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
174
|
-
* MIT Licensed
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
/*!
|
|
178
|
-
* send
|
|
179
|
-
* Copyright(c) 2012 TJ Holowaychuk
|
|
180
|
-
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
181
|
-
* MIT Licensed
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
/*!
|
|
185
|
-
* type-is
|
|
186
|
-
* Copyright(c) 2014 Jonathan Ong
|
|
187
|
-
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
188
|
-
* MIT Licensed
|
|
189
|
-
*/
|
|
190
|
-
|
|
191
|
-
/*!
|
|
192
|
-
* vary
|
|
193
|
-
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
194
|
-
* MIT Licensed
|
|
195
|
-
*/
|
|
196
|
-
|
|
197
|
-
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
package/dist/runtime/895.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";exports.id=895,exports.ids=[895],exports.modules={58895:(e,t,s)=>{s.d(t,{sA:()=>n});var r=s(89219);const i=INJECTED_TOOLS,a={name:"MCP Server",version:"0.0.1",capabilities:{tools:{listChanged:!0}}};async function n(){const e=new r._(a),[t,s]=function(){const e=new Map;return[Object.keys(i).map(t=>i[t]().then(s=>{e.set(t,s)})),e]}();return await Promise.all(t),async function(e,t){return new Promise(async s=>{t.forEach(t=>{const{default:s,metadata:r,schema:i}=t;e.tool(r.name,r.description,i,r.annotations,s)}),s(e)})}(e,s)}},89219:(e,t,s)=>{s.d(t,{_:()=>g});var r=s(62843),i=s(86848),a=s(53084);class n extends r.Zs{constructor(e,t){var s;super(t),this._serverInfo=e,this._capabilities=null!==(s=null==t?void 0:t.capabilities)&&void 0!==s?s:{},this._instructions=null==t?void 0:t.instructions,this.setRequestHandler(i.rk,e=>this._oninitialize(e)),this.setNotificationHandler(i.ZC,()=>{var e;return null===(e=this.oninitialized)||void 0===e?void 0:e.call(this)})}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=(0,r.hG)(this._capabilities,e)}assertCapabilityForMethod(e){var t,s,r;switch(e){case"sampling/createMessage":if(!(null===(t=this._clientCapabilities)||void 0===t?void 0:t.sampling))throw new Error(`Client does not support sampling (required for ${e})`);break;case"elicitation/create":if(!(null===(s=this._clientCapabilities)||void 0===s?void 0:s.elicitation))throw new Error(`Client does not support elicitation (required for ${e})`);break;case"roots/list":if(!(null===(r=this._clientCapabilities)||void 0===r?void 0:r.roots))throw new Error(`Client does not support listing roots (required for ${e})`)}}assertNotificationCapability(e){switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`)}}assertRequestHandlerCapability(e){switch(e){case"sampling/createMessage":if(!this._capabilities.sampling)throw new Error(`Server does not support sampling (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`)}}async _oninitialize(e){const t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:i.Iu.includes(t)?t:i.aE,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},i.wR)}async createMessage(e,t){return this.request({method:"sampling/createMessage",params:e},i.K1,t)}async elicitInput(e,t){const s=await this.request({method:"elicitation/create",params:e},i.n_,t);if("accept"===s.action&&s.content)try{const t=new a,r=t.compile(e.requestedSchema);if(!r(s.content))throw new i.Nh(i.O4.InvalidParams,`Elicitation response content does not match requested schema: ${t.errorsText(r.errors)}`)}catch(e){if(e instanceof i.Nh)throw e;throw new i.Nh(i.O4.InternalError,`Error validating elicitation response: ${e}`)}return s}async listRoots(e,t){return this.request({method:"roots/list",params:e},i.Cs,t)}async sendLoggingMessage(e){return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}}s(32985);var o=s(7877),l=s(19313),c=(s(62133),s(4056),s(72663),s(23245),s(90746),s(10571),s(21006),s(54663),s(93473),s(36646),s(45852),s(56201),s(99864),s(30791),s(71244),s(67499),s(2222),s(65359),s(389),s(17698));const d=(e,t)=>{const s=(0,o.t)(t);let r="object"==typeof t&&t.definitions?Object.entries(t.definitions).reduce((e,[t,r])=>({...e,[t]:(0,l.N)(r._def,{...s,currentPath:[...s.basePath,s.definitionPath,t]},!0)??(0,c.X)(s)}),{}):void 0;const i="string"==typeof t?t:"title"===t?.nameStrategy?void 0:t?.name,a=(0,l.N)(e._def,void 0===i?s:{...s,currentPath:[...s.basePath,s.definitionPath,i]},!1)??(0,c.X)(s),n="object"==typeof t&&void 0!==t.name&&"title"===t.nameStrategy?t.name:void 0;void 0!==n&&(a.title=n),s.flags.hasReferencedOpenAiAnyType&&(r||(r={}),r[s.openAiAnyTypeName]||(r[s.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:"relative"===s.$refStrategy?"1":[...s.basePath,s.definitionPath,s.openAiAnyTypeName].join("/")}}));const d=void 0===i?r?{...a,[s.definitionPath]:r}:a:{$ref:[..."relative"===s.$refStrategy?[]:s.basePath,s.definitionPath,i].join("/"),[s.definitionPath]:{...r,[i]:a}};return"jsonSchema7"===s.target?d.$schema="http://json-schema.org/draft-07/schema#":"jsonSchema2019-09"!==s.target&&"openAi"!==s.target||(d.$schema="https://json-schema.org/draft/2019-09/schema#"),"openAi"===s.target&&("anyOf"in d||"oneOf"in d||"allOf"in d||"type"in d&&Array.isArray(d.type))&&console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property."),d};var p,h=s(15686);!function(e){e.Completable="McpCompletable"}(p||(p={}));class u extends h.aR{_parse(e){const{ctx:t}=this._processInputParams(e),s=t.data;return this._def.type._parse({data:s,path:t.path,parent:t})}unwrap(){return this._def.type}}function m(e){if(!e)return{};const{errorMap:t,invalid_type_error:s,required_error:r,description:i}=e;if(t&&(s||r))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');return t?{errorMap:t,description:i}:{errorMap:(t,i)=>{var a,n;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:i.defaultError}:void 0===i.data?{message:null!==(a=null!=o?o:r)&&void 0!==a?a:i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:null!==(n=null!=o?o:s)&&void 0!==n?n:i.defaultError}},description:i}}u.create=(e,t)=>new u({type:e,typeName:p.Completable,complete:t.complete,...m(t)});class g{constructor(e,t){this._registeredResources={},this._registeredResourceTemplates={},this._registeredTools={},this._registeredPrompts={},this._toolHandlersInitialized=!1,this._completionHandlerInitialized=!1,this._resourceHandlersInitialized=!1,this._promptHandlersInitialized=!1,this.server=new n(e,t)}async connect(e){return await this.server.connect(e)}async close(){await this.server.close()}setToolRequestHandlers(){this._toolHandlersInitialized||(this.server.assertCanSetRequestHandler(i.gW.shape.method.value),this.server.assertCanSetRequestHandler(i.FT.shape.method.value),this.server.registerCapabilities({tools:{listChanged:!0}}),this.server.setRequestHandler(i.gW,()=>({tools:Object.entries(this._registeredTools).filter(([,e])=>e.enabled).map(([e,t])=>{const s={name:e,title:t.title,description:t.description,inputSchema:t.inputSchema?d(t.inputSchema,{strictUnions:!0}):f,annotations:t.annotations};return t.outputSchema&&(s.outputSchema=d(t.outputSchema,{strictUnions:!0})),s})})),this.server.setRequestHandler(i.FT,async(e,t)=>{const s=this._registeredTools[e.params.name];if(!s)throw new i.Nh(i.O4.InvalidParams,`Tool ${e.params.name} not found`);if(!s.enabled)throw new i.Nh(i.O4.InvalidParams,`Tool ${e.params.name} disabled`);let r;if(s.inputSchema){const a=await s.inputSchema.safeParseAsync(e.params.arguments);if(!a.success)throw new i.Nh(i.O4.InvalidParams,`Invalid arguments for tool ${e.params.name}: ${a.error.message}`);const n=a.data,o=s.callback;try{r=await Promise.resolve(o(n,t))}catch(e){r={content:[{type:"text",text:e instanceof Error?e.message:String(e)}],isError:!0}}}else{const e=s.callback;try{r=await Promise.resolve(e(t))}catch(e){r={content:[{type:"text",text:e instanceof Error?e.message:String(e)}],isError:!0}}}if(s.outputSchema&&!r.isError){if(!r.structuredContent)throw new i.Nh(i.O4.InvalidParams,`Tool ${e.params.name} has an output schema but no structured content was provided`);const t=await s.outputSchema.safeParseAsync(r.structuredContent);if(!t.success)throw new i.Nh(i.O4.InvalidParams,`Invalid structured content for tool ${e.params.name}: ${t.error.message}`)}return r}),this._toolHandlersInitialized=!0)}setCompletionRequestHandler(){this._completionHandlerInitialized||(this.server.assertCanSetRequestHandler(i.iK.shape.method.value),this.server.registerCapabilities({completions:{}}),this.server.setRequestHandler(i.iK,async e=>{switch(e.params.ref.type){case"ref/prompt":return this.handlePromptCompletion(e,e.params.ref);case"ref/resource":return this.handleResourceCompletion(e,e.params.ref);default:throw new i.Nh(i.O4.InvalidParams,`Invalid completion reference: ${e.params.ref}`)}}),this._completionHandlerInitialized=!0)}async handlePromptCompletion(e,t){const s=this._registeredPrompts[t.name];if(!s)throw new i.Nh(i.O4.InvalidParams,`Prompt ${t.name} not found`);if(!s.enabled)throw new i.Nh(i.O4.InvalidParams,`Prompt ${t.name} disabled`);if(!s.argsSchema)return w;const r=s.argsSchema.shape[e.params.argument.name];if(!(r instanceof u))return w;const a=r._def;return _(await a.complete(e.params.argument.value,e.params.context))}async handleResourceCompletion(e,t){const s=Object.values(this._registeredResourceTemplates).find(e=>e.resourceTemplate.uriTemplate.toString()===t.uri);if(!s){if(this._registeredResources[t.uri])return w;throw new i.Nh(i.O4.InvalidParams,`Resource template ${e.params.ref.uri} not found`)}const r=s.resourceTemplate.completeCallback(e.params.argument.name);return r?_(await r(e.params.argument.value,e.params.context)):w}setResourceRequestHandlers(){this._resourceHandlersInitialized||(this.server.assertCanSetRequestHandler(i.OI.shape.method.value),this.server.assertCanSetRequestHandler(i.s.shape.method.value),this.server.assertCanSetRequestHandler(i.R6.shape.method.value),this.server.registerCapabilities({resources:{listChanged:!0}}),this.server.setRequestHandler(i.OI,async(e,t)=>{const s=Object.entries(this._registeredResources).filter(([e,t])=>t.enabled).map(([e,t])=>({uri:e,name:t.name,...t.metadata})),r=[];for(const e of Object.values(this._registeredResourceTemplates)){if(!e.resourceTemplate.listCallback)continue;const s=await e.resourceTemplate.listCallback(t);for(const t of s.resources)r.push({...e.metadata,...t})}return{resources:[...s,...r]}}),this.server.setRequestHandler(i.s,async()=>({resourceTemplates:Object.entries(this._registeredResourceTemplates).map(([e,t])=>({name:e,uriTemplate:t.resourceTemplate.uriTemplate.toString(),...t.metadata}))})),this.server.setRequestHandler(i.R6,async(e,t)=>{const s=new URL(e.params.uri),r=this._registeredResources[s.toString()];if(r){if(!r.enabled)throw new i.Nh(i.O4.InvalidParams,`Resource ${s} disabled`);return r.readCallback(s,t)}for(const e of Object.values(this._registeredResourceTemplates)){const r=e.resourceTemplate.uriTemplate.match(s.toString());if(r)return e.readCallback(s,r,t)}throw new i.Nh(i.O4.InvalidParams,`Resource ${s} not found`)}),this.setCompletionRequestHandler(),this._resourceHandlersInitialized=!0)}setPromptRequestHandlers(){this._promptHandlersInitialized||(this.server.assertCanSetRequestHandler(i.Qq.shape.method.value),this.server.assertCanSetRequestHandler(i.$p.shape.method.value),this.server.registerCapabilities({prompts:{listChanged:!0}}),this.server.setRequestHandler(i.Qq,()=>({prompts:Object.entries(this._registeredPrompts).filter(([,e])=>e.enabled).map(([e,t])=>{return{name:e,title:t.title,description:t.description,arguments:t.argsSchema?(s=t.argsSchema,Object.entries(s.shape).map(([e,t])=>({name:e,description:t.description,required:!t.isOptional()}))):void 0};var s})})),this.server.setRequestHandler(i.$p,async(e,t)=>{const s=this._registeredPrompts[e.params.name];if(!s)throw new i.Nh(i.O4.InvalidParams,`Prompt ${e.params.name} not found`);if(!s.enabled)throw new i.Nh(i.O4.InvalidParams,`Prompt ${e.params.name} disabled`);if(s.argsSchema){const r=await s.argsSchema.safeParseAsync(e.params.arguments);if(!r.success)throw new i.Nh(i.O4.InvalidParams,`Invalid arguments for prompt ${e.params.name}: ${r.error.message}`);const a=r.data,n=s.callback;return await Promise.resolve(n(a,t))}{const e=s.callback;return await Promise.resolve(e(t))}}),this.setCompletionRequestHandler(),this._promptHandlersInitialized=!0)}resource(e,t,...s){let r;"object"==typeof s[0]&&(r=s.shift());const i=s[0];if("string"==typeof t){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);const s=this._createRegisteredResource(e,void 0,t,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),s}{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const s=this._createRegisteredResourceTemplate(e,void 0,t,r,i);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),s}}registerResource(e,t,s,r){if("string"==typeof t){if(this._registeredResources[t])throw new Error(`Resource ${t} is already registered`);const i=this._createRegisteredResource(e,s.title,t,s,r);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}{if(this._registeredResourceTemplates[e])throw new Error(`Resource template ${e} is already registered`);const i=this._createRegisteredResourceTemplate(e,s.title,t,s,r);return this.setResourceRequestHandlers(),this.sendResourceListChanged(),i}}_createRegisteredResource(e,t,s,r,i){const a={name:e,title:t,metadata:r,readCallback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({uri:null}),update:e=>{void 0!==e.uri&&e.uri!==s&&(delete this._registeredResources[s],e.uri&&(this._registeredResources[e.uri]=a)),void 0!==e.name&&(a.name=e.name),void 0!==e.title&&(a.title=e.title),void 0!==e.metadata&&(a.metadata=e.metadata),void 0!==e.callback&&(a.readCallback=e.callback),void 0!==e.enabled&&(a.enabled=e.enabled),this.sendResourceListChanged()}};return this._registeredResources[s]=a,a}_createRegisteredResourceTemplate(e,t,s,r,i){const a={resourceTemplate:s,title:t,metadata:r,readCallback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredResourceTemplates[e],t.name&&(this._registeredResourceTemplates[t.name]=a)),void 0!==t.title&&(a.title=t.title),void 0!==t.template&&(a.resourceTemplate=t.template),void 0!==t.metadata&&(a.metadata=t.metadata),void 0!==t.callback&&(a.readCallback=t.callback),void 0!==t.enabled&&(a.enabled=t.enabled),this.sendResourceListChanged()}};return this._registeredResourceTemplates[e]=a,a}_createRegisteredPrompt(e,t,s,r,i){const a={title:t,description:s,argsSchema:void 0===r?void 0:h.Ik(r),callback:i,enabled:!0,disable:()=>a.update({enabled:!1}),enable:()=>a.update({enabled:!0}),remove:()=>a.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredPrompts[e],t.name&&(this._registeredPrompts[t.name]=a)),void 0!==t.title&&(a.title=t.title),void 0!==t.description&&(a.description=t.description),void 0!==t.argsSchema&&(a.argsSchema=h.Ik(t.argsSchema)),void 0!==t.callback&&(a.callback=t.callback),void 0!==t.enabled&&(a.enabled=t.enabled),this.sendPromptListChanged()}};return this._registeredPrompts[e]=a,a}_createRegisteredTool(e,t,s,r,i,a,n){const o={title:t,description:s,inputSchema:void 0===r?void 0:h.Ik(r),outputSchema:void 0===i?void 0:h.Ik(i),annotations:a,callback:n,enabled:!0,disable:()=>o.update({enabled:!1}),enable:()=>o.update({enabled:!0}),remove:()=>o.update({name:null}),update:t=>{void 0!==t.name&&t.name!==e&&(delete this._registeredTools[e],t.name&&(this._registeredTools[t.name]=o)),void 0!==t.title&&(o.title=t.title),void 0!==t.description&&(o.description=t.description),void 0!==t.paramsSchema&&(o.inputSchema=h.Ik(t.paramsSchema)),void 0!==t.callback&&(o.callback=t.callback),void 0!==t.annotations&&(o.annotations=t.annotations),void 0!==t.enabled&&(o.enabled=t.enabled),this.sendToolListChanged()}};return this._registeredTools[e]=o,this.setToolRequestHandlers(),this.sendToolListChanged(),o}tool(e,...t){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);let s,r,i;if("string"==typeof t[0]&&(s=t.shift()),t.length>1){const e=t[0];v(e)?(r=t.shift(),t.length>1&&"object"==typeof t[0]&&null!==t[0]&&!v(t[0])&&(i=t.shift())):"object"==typeof e&&null!==e&&(i=t.shift())}const a=t[0];return this._createRegisteredTool(e,void 0,s,r,void 0,i,a)}registerTool(e,t,s){if(this._registeredTools[e])throw new Error(`Tool ${e} is already registered`);const{title:r,description:i,inputSchema:a,outputSchema:n,annotations:o}=t;return this._createRegisteredTool(e,r,i,a,n,o,s)}prompt(e,...t){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);let s,r;"string"==typeof t[0]&&(s=t.shift()),t.length>1&&(r=t.shift());const i=t[0],a=this._createRegisteredPrompt(e,void 0,s,r,i);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),a}registerPrompt(e,t,s){if(this._registeredPrompts[e])throw new Error(`Prompt ${e} is already registered`);const{title:r,description:i,argsSchema:a}=t,n=this._createRegisteredPrompt(e,r,i,a,s);return this.setPromptRequestHandlers(),this.sendPromptListChanged(),n}isConnected(){return void 0!==this.server.transport}sendResourceListChanged(){this.isConnected()&&this.server.sendResourceListChanged()}sendToolListChanged(){this.isConnected()&&this.server.sendToolListChanged()}sendPromptListChanged(){this.isConnected()&&this.server.sendPromptListChanged()}}const f={type:"object"};function v(e){return"object"==typeof e&&null!==e&&(0===Object.keys(e).length||Object.values(e).some(b))}function b(e){return null!==e&&"object"==typeof e&&"parse"in e&&"function"==typeof e.parse&&"safeParse"in e&&"function"==typeof e.safeParse}function _(e){return{completion:{values:e.slice(0,100),total:e.length,hasMore:e.length>100}}}const w={completion:{values:[],hasMore:!1}}}};
|
|
File without changes
|