zion-mcp 2.7.14 → 2.8.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/README.md +4 -4
- package/dist/{chunk-UTNJOYOL.js → chunk-3KE7DBBZ.js} +1 -1
- package/dist/chunk-4RMPLI2R.js +3 -0
- package/dist/chunk-CAF64CO7.js +1492 -0
- package/dist/chunk-OHILD5KP.js +3 -0
- package/dist/{chunk-QPWH6HFY.js → chunk-U2LHS4U2.js} +1 -1
- package/dist/chunk-UNPVTOSR.js +5 -0
- package/dist/cli-BJFYETZJ.js +1593 -0
- package/dist/{corpus-4KLVM7U2.js → corpus-XVQ4ZV2V.js} +440 -246
- package/dist/{index.cjs-VXTJAAU2.js → index.cjs-JL7FJKD6.js} +1 -1
- package/dist/{json-crdt-RZN2Q6JT.js → json-crdt-322RBKNB.js} +1 -1
- package/dist/{json-crdt-patch-AIX55EJV.js → json-crdt-patch-X2W6V7VS.js} +1 -1
- package/dist/server.js +1 -3136
- package/dist/surface-S5OGOVQV.js +3 -0
- package/dist/{ztype-QQQP6HMK.js → ztype-BFQK2PDI.js} +104 -104
- package/package.json +1 -1
- package/dist/chunk-GVWWJW5X.js +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __nodeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __nodeCreateRequire(import.meta.url);
|
|
3
|
+
import{$ as le,A as U,D as F,E as z,F as K,G as Q,H as S,I as G,J as W,K as B,L as J,M as Z,N as X,O as Y,P as ee,Q as l,R as te,S as se,T as re,U as oe,V as ie,W as ae,Y as ne,Z as ce,n as L,o as C,p as O,q as x,r as H,s as d,u as T,v as j,w as I,x as A,y as D,z as N}from"./chunk-CAF64CO7.js";import{c as E,d as $,e as V}from"./chunk-4RMPLI2R.js";import{g as b}from"./chunk-OHILD5KP.js";b();b();b();var y=class{constructor(e){this._client=e}async*callToolStream(e,t=S,s){let r=this._client,n={...s,task:s?.task??(r.isToolTask(e.name)?{}:void 0)},h=r.requestStream({method:"tools/call",params:e},t,n),u=r.getToolOutputValidator(e.name);for await(let o of h){if(o.type==="result"&&u){let m=o.result;if(!m.structuredContent&&!m.isError){yield{type:"error",error:new l(d.InvalidRequest,`Tool ${e.name} has an output schema but did not return structured content`)};return}if(m.structuredContent)try{let a=u(m.structuredContent);if(!a.valid){yield{type:"error",error:new l(d.InvalidParams,`Structured content does not match the tool's output schema: ${a.errorMessage}`)};return}}catch(a){if(a instanceof l){yield{type:"error",error:a};return}yield{type:"error",error:new l(d.InvalidParams,`Failed to validate structured content: ${a instanceof Error?a.message:String(a)}`)};return}}yield o}}async getTask(e,t){return this._client.getTask({taskId:e},t)}async getTaskResult(e,t,s){return this._client.getTaskResult({taskId:e},t,s)}async listTasks(e,t){return this._client.listTasks(e?{cursor:e}:void 0,t)}async cancelTask(e,t){return this._client.cancelTask({taskId:e},t)}requestStream(e,t,s){return this._client.requestStream(e,t,s)}};function k(i,e){if(!(!i||e===null||typeof e!="object")){if(i.type==="object"&&i.properties&&typeof i.properties=="object"){let t=e,s=i.properties;for(let r of Object.keys(s)){let n=s[r];t[r]===void 0&&Object.prototype.hasOwnProperty.call(n,"default")&&(t[r]=n.default),t[r]!==void 0&&k(n,t[r])}}if(Array.isArray(i.anyOf))for(let t of i.anyOf)typeof t!="boolean"&&k(t,e);if(Array.isArray(i.oneOf))for(let t of i.oneOf)typeof t!="boolean"&&k(t,e)}}function he(i){if(!i)return{supportsFormMode:!1,supportsUrlMode:!1};let e=i.form!==void 0,t=i.url!==void 0;return{supportsFormMode:e||!e&&!t,supportsUrlMode:t}}var R=class extends te{constructor(e,t){super(t),this._clientInfo=e,this._cachedToolOutputValidators=new Map,this._cachedKnownTaskTools=new Set,this._cachedRequiredTaskTools=new Set,this._listChangedDebounceTimers=new Map,this._capabilities=t?.capabilities??{},this._jsonSchemaValidator=t?.jsonSchemaValidator??new re,t?.listChanged&&(this._pendingListChangedConfig=t.listChanged)}_setupListChangedHandlers(e){e.tools&&this._serverCapabilities?.tools?.listChanged&&this._setupListChangedHandler("tools",G,e.tools,async()=>(await this.listTools()).tools),e.prompts&&this._serverCapabilities?.prompts?.listChanged&&this._setupListChangedHandler("prompts",K,e.prompts,async()=>(await this.listPrompts()).prompts),e.resources&&this._serverCapabilities?.resources?.listChanged&&this._setupListChangedHandler("resources",U,e.resources,async()=>(await this.listResources()).resources)}get experimental(){return this._experimental||(this._experimental={tasks:new y(this)}),this._experimental}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=se(this._capabilities,e)}setRequestHandler(e,t){let r=O(e)?.method;if(!r)throw new Error("Schema is missing a method literal");let n;if(L(r)){let u=r;n=u._zod?.def?.value??u.value}else{let u=r;n=u._def?.value??u.value}if(typeof n!="string")throw new Error("Schema method literal must be a string");let h=n;if(h==="elicitation/create"){let u=async(o,m)=>{let a=C(X,o);if(!a.success){let g=a.error instanceof Error?a.error.message:String(a.error);throw new l(d.InvalidParams,`Invalid elicitation request: ${g}`)}let{params:c}=a.data;c.mode=c.mode??"form";let{supportsFormMode:w,supportsUrlMode:M}=he(this._capabilities.elicitation);if(c.mode==="form"&&!w)throw new l(d.InvalidParams,"Client does not support form-mode elicitation requests");if(c.mode==="url"&&!M)throw new l(d.InvalidParams,"Client does not support URL-mode elicitation requests");let _=await Promise.resolve(t(o,m));if(c.task){let g=C(I,_);if(!g.success){let ue=g.error instanceof Error?g.error.message:String(g.error);throw new l(d.InvalidParams,`Invalid task creation result: ${ue}`)}return g.data}let f=C(Y,_);if(!f.success){let g=f.error instanceof Error?f.error.message:String(f.error);throw new l(d.InvalidParams,`Invalid elicitation result: ${g}`)}let p=f.data,v=c.mode==="form"?c.requestedSchema:void 0;if(c.mode==="form"&&p.action==="accept"&&p.content&&v&&this._capabilities.elicitation?.form?.applyDefaults)try{k(v,p.content)}catch{}return p};return super.setRequestHandler(e,u)}if(h==="sampling/createMessage"){let u=async(o,m)=>{let a=C(B,o);if(!a.success){let p=a.error instanceof Error?a.error.message:String(a.error);throw new l(d.InvalidParams,`Invalid sampling request: ${p}`)}let{params:c}=a.data,w=await Promise.resolve(t(o,m));if(c.task){let p=C(I,w);if(!p.success){let v=p.error instanceof Error?p.error.message:String(p.error);throw new l(d.InvalidParams,`Invalid task creation result: ${v}`)}return p.data}let _=c.tools||c.toolChoice?Z:J,f=C(_,w);if(!f.success){let p=f.error instanceof Error?f.error.message:String(f.error);throw new l(d.InvalidParams,`Invalid sampling result: ${p}`)}return f.data};return super.setRequestHandler(e,u)}return super.setRequestHandler(e,t)}assertCapability(e,t){if(!this._serverCapabilities?.[e])throw new Error(`Server does not support ${e} (required for ${t})`)}async connect(e,t){if(await super.connect(e),e.sessionId===void 0)try{let s=await this.request({method:"initialize",params:{protocolVersion:x,capabilities:this._capabilities,clientInfo:this._clientInfo}},j,t);if(s===void 0)throw new Error(`Server sent invalid initialize result: ${s}`);if(!H.includes(s.protocolVersion))throw new Error(`Server's protocol version is not supported: ${s.protocolVersion}`);this._serverCapabilities=s.capabilities,this._serverVersion=s.serverInfo,e.setProtocolVersion&&e.setProtocolVersion(s.protocolVersion),this._instructions=s.instructions,await this.notification({method:"notifications/initialized"}),this._pendingListChangedConfig&&(this._setupListChangedHandlers(this._pendingListChangedConfig),this._pendingListChangedConfig=void 0)}catch(s){throw this.close(),s}}getServerCapabilities(){return this._serverCapabilities}getServerVersion(){return this._serverVersion}getInstructions(){return this._instructions}assertCapabilityForMethod(e){switch(e){case"logging/setLevel":if(!this._serverCapabilities?.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._serverCapabilities?.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":case"resources/subscribe":case"resources/unsubscribe":if(!this._serverCapabilities?.resources)throw new Error(`Server does not support resources (required for ${e})`);if(e==="resources/subscribe"&&!this._serverCapabilities.resources.subscribe)throw new Error(`Server does not support resource subscriptions (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._serverCapabilities?.tools)throw new Error(`Server does not support tools (required for ${e})`);break;case"completion/complete":if(!this._serverCapabilities?.completions)throw new Error(`Server does not support completions (required for ${e})`);break;case"initialize":break;case"ping":break}}assertNotificationCapability(e){switch(e){case"notifications/roots/list_changed":if(!this._capabilities.roots?.listChanged)throw new Error(`Client does not support roots list changed notifications (required for ${e})`);break;case"notifications/initialized":break;case"notifications/cancelled":break;case"notifications/progress":break}}assertRequestHandlerCapability(e){if(this._capabilities)switch(e){case"sampling/createMessage":if(!this._capabilities.sampling)throw new Error(`Client does not support sampling capability (required for ${e})`);break;case"elicitation/create":if(!this._capabilities.elicitation)throw new Error(`Client does not support elicitation capability (required for ${e})`);break;case"roots/list":if(!this._capabilities.roots)throw new Error(`Client does not support roots capability (required for ${e})`);break;case"tasks/get":case"tasks/list":case"tasks/result":case"tasks/cancel":if(!this._capabilities.tasks)throw new Error(`Client does not support tasks capability (required for ${e})`);break;case"ping":break}}assertTaskCapability(e){oe(this._serverCapabilities?.tasks?.requests,e,"Server")}assertTaskHandlerCapability(e){this._capabilities&&ie(this._capabilities.tasks?.requests,e,"Client")}async ping(e){return this.request({method:"ping"},T,e)}async complete(e,t){return this.request({method:"completion/complete",params:e},ee,t)}async setLoggingLevel(e,t){return this.request({method:"logging/setLevel",params:{level:e}},T,t)}async getPrompt(e,t){return this.request({method:"prompts/get",params:e},z,t)}async listPrompts(e,t){return this.request({method:"prompts/list",params:e},F,t)}async listResources(e,t){return this.request({method:"resources/list",params:e},A,t)}async listResourceTemplates(e,t){return this.request({method:"resources/templates/list",params:e},D,t)}async readResource(e,t){return this.request({method:"resources/read",params:e},N,t)}async subscribeResource(e,t){return this.request({method:"resources/subscribe",params:e},T,t)}async unsubscribeResource(e,t){return this.request({method:"resources/unsubscribe",params:e},T,t)}async callTool(e,t=S,s){if(this.isToolTaskRequired(e.name))throw new l(d.InvalidRequest,`Tool "${e.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`);let r=await this.request({method:"tools/call",params:e},t,s),n=this.getToolOutputValidator(e.name);if(n){if(!r.structuredContent&&!r.isError)throw new l(d.InvalidRequest,`Tool ${e.name} has an output schema but did not return structured content`);if(r.structuredContent)try{let h=n(r.structuredContent);if(!h.valid)throw new l(d.InvalidParams,`Structured content does not match the tool's output schema: ${h.errorMessage}`)}catch(h){throw h instanceof l?h:new l(d.InvalidParams,`Failed to validate structured content: ${h instanceof Error?h.message:String(h)}`)}}return r}isToolTask(e){return this._serverCapabilities?.tasks?.requests?.tools?.call?this._cachedKnownTaskTools.has(e):!1}isToolTaskRequired(e){return this._cachedRequiredTaskTools.has(e)}cacheToolMetadata(e){this._cachedToolOutputValidators.clear(),this._cachedKnownTaskTools.clear(),this._cachedRequiredTaskTools.clear();for(let t of e){if(t.outputSchema){let r=this._jsonSchemaValidator.getValidator(t.outputSchema);this._cachedToolOutputValidators.set(t.name,r)}let s=t.execution?.taskSupport;(s==="required"||s==="optional")&&this._cachedKnownTaskTools.add(t.name),s==="required"&&this._cachedRequiredTaskTools.add(t.name)}}getToolOutputValidator(e){return this._cachedToolOutputValidators.get(e)}async listTools(e,t){let s=await this.request({method:"tools/list",params:e},Q,t);return this.cacheToolMetadata(s.tools),s}_setupListChangedHandler(e,t,s,r){let n=W.safeParse(s);if(!n.success)throw new Error(`Invalid ${e} listChanged options: ${n.error.message}`);if(typeof s.onChanged!="function")throw new Error(`Invalid ${e} listChanged options: onChanged must be a function`);let{autoRefresh:h,debounceMs:u}=n.data,{onChanged:o}=s,m=async()=>{if(!h){o(null,null);return}try{let c=await r();o(null,c)}catch(c){let w=c instanceof Error?c:new Error(String(c));o(w,null)}},a=()=>{if(u){let c=this._listChangedDebounceTimers.get(e);c&&clearTimeout(c);let w=setTimeout(m,u);this._listChangedDebounceTimers.set(e,w)}else m()};this.setNotificationHandler(t,a)}async sendRootsListChanged(){return this.notification({method:"notifications/roots/list_changed"})}};b();var q=class i{constructor(){this._messageQueue=[]}static createLinkedPair(){let e=new i,t=new i;return e._otherTransport=t,t._otherTransport=e,[e,t]}async start(){for(;this._messageQueue.length>0;){let e=this._messageQueue.shift();this.onmessage?.(e.message,e.extra)}}async close(){let e=this._otherTransport;this._otherTransport=void 0,await e?.close(),this.onclose?.()}async send(e,t){if(!this._otherTransport)throw new Error("Not connected");this._otherTransport.onmessage?this._otherTransport.onmessage(e,{authInfo:t?.authInfo}):this._otherTransport._messageQueue.push({message:e,extra:{authInfo:t?.authInfo}})}};async function Ve(){let i=new ae({name:$,version:E()}),e=async n=>({ok:!1,error:`${n.name} cannot run while collecting the tool surface`});ce(i,e),le(i,e);let[t,s]=q.createLinkedPair();await i.connect(s);let r=new R({name:"tool-surface",version:"0.0.0"});await r.connect(t);try{let{tools:n}=await r.listTools(),{prompts:h}=await r.listPrompts(),u=(o,m)=>o.name.localeCompare(m.name);return{product:V,version:E(),tools:n.map(o=>({name:o.name,inputSchema:o.inputSchema})).sort(u),prompts:h.map(o=>({name:o.name,arguments:o.arguments??[]})).sort(u),cliVerbs:ne.flatMap(o=>o.cli?[o.cli.path,...o.cli.alias?[o.cli.alias]:[]]:[]).sort()}}finally{await r.close(),await i.close()}}export{Ve as collectToolSurface};
|