MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / getServerCapabilities

Method getServerCapabilities

package/cli.js:1750–1750  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1748
1749Recurring tasks auto-expire after ${kq6} days — they fire one final time, then are deleted. This bounds session lifetime. Tell the user about the ${kq6}-day limit when scheduling recurring jobs.
1750
1751Returns a job ID you can pass to ${Vq6}.`}function Xp1(q){return q?`Cancel a cron job previously scheduled with ${xL}. Removes it from .claude/scheduled_tasks.json (durable jobs) or the in-memory session store (session-only jobs).`:`Cancel a cron job previously scheduled with ${xL}. Removes it from the in-memory session store.`}function Wp1(q){return q?`List all cron jobs scheduled via ${xL}, both durable (.claude/scheduled_tasks.json) and session-only.`:`List all cron jobs scheduled via ${xL} in this session.`}var ry4=300000,kq6,xL="CronCreate",Vq6="CronDelete",Ro6="CronList",Mp1="Cancel a scheduled cron job by ID",Pp1="List scheduled cron jobs";var gr=y(()=>{o1();vq6();m8();kq6=kU.recurringMaxAgeMs/86400000});var mV6,Dp1,iN8,ay4;var ho6=y(()=>{Z$();vU();IY();NO6();qM();Hr();E2();rF();GU();gr();mV6=new Set([ak,kX,Zq6,v4,a$,zI]),Dp1=new Set([...mV6]),iN8=new Set([Cq,$N,BC,n3,Sj,i9,...jr,X4,tK,nW,JM,MD,CP,cN8,lN8]),ay4=new Set([TN,Gq6,Tq6,bL,wD,xL,Vq6,Ro6])});var au="TeamCreate";var Mw6="TeamDelete";function pV6(){return!1}var So6=y(()=>{ho6();o1();k8();Z$();IY();GU();m8()});class fp1{constructor(q){this._client=q}async*callToolStream(q,K=MB,_){let z=this._client,Y={..._,task:_?.task??(z.isToolTask(q.name)?{}:void 0)},$=z.requestStream({method:"tools/call",params:q},K,Y),A=z.getToolOutputValidator(q.name);for await(let O of $){if(O.type==="result"&&A){let w=O.result;if(!w.structuredContent&&!w.isError){yield{type:"error",error:new MK($5.InvalidRequest,`Tool ${q.name} has an output schema but did not return structured content`)};return}if(w.structuredContent)try{let j=A(w.structuredContent);if(!j.valid){yield{type:"error",error:new MK($5.InvalidParams,`Structured content does not match the tool's output schema: ${j.errorMessage}`)};return}}catch(j){if(j instanceof MK){yield{type:"error",error:j};return}yield{type:"error",error:new MK($5.InvalidParams,`Failed to validate structured content: ${j instanceof Error?j.message:String(j)}`)};return}}yield O}}async getTask(q,K){return this._client.getTask({taskId:q},K)}async getTaskResult(q,K,_){return this._client.getTaskResult({taskId:q},K,_)}async listTasks(q,K){return this._client.listTasks(q?{cursor:q}:void 0,K)}async cancelTask(q,K){return this._client.cancelTask({taskId:q},K)}requestStream(q,K,_){return this._client.requestStream(q,K,_)}}var sy4=y(()=>{lM()});function rN8(q,K){if(!q||K===null||typeof K!=="object")return;if(q.type==="object"&&q.properties&&typeof q.properties==="object"){let _=K,z=q.properties;for(let Y of Object.keys(z)){let $=z[Y];if(_[Y]===void 0&&Object.prototype.hasOwnProperty.call($,"default"))_[Y]=$.default;if(_[Y]!==void 0)rN8($,_[Y])}}if(Array.isArray(q.anyOf)){for(let _ of q.anyOf)if(typeof _!=="boolean")rN8(_,K)}if(Array.isArray(q.oneOf)){for(let _ of q.oneOf)if(typeof _!=="boolean")rN8(_,K)}}function wYz(q){if(!q)return{supportsFormMode:!1,supportsUrlMode:!1};let K=q.form!==void 0,_=q.url!==void 0;return{supportsFormMode:K||!K&&!_,supportsUrlMode:_}}var oN8;var ty4=y(()=>{V81();lM();y11();Yu6();sy4();oN8=class oN8 extends bu6{constructor(q,K){super(K);if(this._clientInfo=q,this._cachedToolOutputValidators=new Map,this._cachedKnownTaskTools=new Set,this._cachedRequiredTaskTools=new Set,this._listChangedDebounceTimers=new Map,this._capabilities=K?.capabilities??{},this._jsonSchemaValidator=K?.jsonSchemaValidator??new _m6,K?.listChanged)this._pendingListChangedConfig=K.listChanged}_setupListChangedHandlers(q){if(q.tools&&this._serverCapabilities?.tools?.listChanged)this._setupListChangedHandler("tools",Lu6,q.tools,async()=>{return(await this.listTools()).tools});if(q.prompts&&this._serverCapabilities?.prompts?.listChanged)this._setupListChangedHandler("prompts",yu6,q.prompts,async()=>{return(await this.listPrompts()).prompts});if(q.resources&&this._serverCapabilities?.resources?.listChanged)this._setupListChangedHandler("resources",Vu6,q.resources,async()=>{return(await this.listResources()).resources})}get experimental(){if(!this._experimental)this._experimental={tasks:new fp1(this)};return this._experimental}registerCapabilities(q){if(this.transport)throw Error("Cannot register capabilities after connecting to transport");this._capabilities=wz8(this._capabilities,q)}setRequestHandler(q,K){let z=BP6(q)?.method;if(!z)throw Error("Schema is missing a method literal");let Y;if(Oe(z)){let A=z;Y=A._zod?.def?.value??A.value}else{let A=z;Y=A._def?.value??A.value}if(typeof Y!=="string")throw Error("Schema method literal must be a string");let $=Y;if($==="elicitation/create"){let A=async(O,w)=>{let j=IT(sc,O);if(!j.success){let f=j.error instanceof Error?j.error.message:String(j.error);throw new MK($5.InvalidParams,`Invalid elicitation request: ${f}`)}let{params:H}=j.data;H.mode=H.mode??"form";let{supportsFormMode:J,supportsUrlMode:M}=wYz(this._capabilities.elicitation);if(H.mode==="form"&&!J)throw new MK($5.InvalidParams,"Client does not support form-mode elicitation requests");if(H.mode==="url"&&!M)throw new MK($5.InvalidParams,"Client does not support URL-mode elicitation requests");let X=await Promise.resolve(K(O,w));if(H.task){let f=IT(oc,X);if(!f.success){let G=f.error instanceof Error?f.error.message:String(f.error);throw new MK($5.InvalidParams,`Invalid task creation result: ${G}`)}return f.data}let P=IT(He,X);if(!P.success){let f=P.error instanceof Error?P.error.message:String(P.error);throw new MK($5.InvalidParams,`Invalid elicitation result: ${f}`)}let W=P.data,D=H.mode==="form"?H.requestedSchema:void 0;if(H.mode==="form"&&W.action==="accept"&&W.content&&D){if(this._capabilities.elicitation?.form?.applyDefaults)try{rN8(D,W.content)}catch{}}return W};return super.setRequestHandler(q,A)}if($==="sampling/createMessage"){let A=async(O,w)=>{let j=IT(r61,O);if(!j.success){let W=j.error instanceof Error?j.error.message:String(j.error);throw new MK($5.InvalidParams,`Invalid sampling request: ${W}`)}let{params:H}=j.data,J=await Promise.resolve(K(O,w));if(H.task){let W=IT(oc,J);if(!W.success){let D=W.error instanceof Error?W.error.message:String(W.error);throw new MK($5.InvalidParams,`Invalid task creation result: ${D}`)}return W.data}let X=H.tools||H.toolChoice?hu6:C96,P=IT(X,J);if(!P.success){let W=P.error instanceof Error?P.error.message:String(P.error);throw new MK($5.InvalidParams,`Invalid sampling result: ${W}`)}return P.data};return super.setRequestHandler(q,A)}return super.setRequestHandler(q,K)}assertCapability(q,K){if(!this._serverCapabilities?.[q])throw Error(`Server does not support ${q} (required for ${K})`)}async connect(q,K){if(await super.connect(q),q.sessionId!==void 0)return;try{let _=await this.request({method:"initialize",params:{protocolVersion:we,capabilities:this._capabilities,clientInfo:this._clientInfo}},B61,K);if(_===void 0)throw Error(`Server sent invalid initialize result: ${_}`);if(!c_8.includes(_.protocolVersion))throw Error(`Server's protocol version is not supported: ${_.protocolVersion}`);if(this._serverCapabilities=_.capabilities,this._serverVersion=_.serverInfo,q.setProtocolVersion)q.setProtocolVersion(_.protocolVersion);if(this._instructions=_.instructions,await this.notification({method:"notifications/initialized"}),this._pendingListChangedConfig)this._setupListChangedHandlers(this._pendingListChangedConfig),this._pendingListChangedConfig=void 0}catch(_){throw this.close(),_}}getServerCapabilities(){return this._serverCapabilities}getServerVersion(){return this._serverVersion}getInstructions(){return this._instructions}assertCapabilityForMethod(q){switch(q){case"logging/setLevel":if(!this._serverCapabilities?.logging)throw Error(`Server does not support logging (required for ${q})`);break;case"prompts/get":case"prompts/list":if(!this._serverCapabilities?.prompts)throw Error(`Server does not support prompts (required for ${q})`);break;case"resources/list":case"resources/templates/list":case"resources/read":case"resources/subscribe":case"resources/unsubscribe":if(!this._serverCapabilities?.resources)throw Error(`Server does not support resources (required for ${q})`);if(q==="resources/subscribe"&&!this._serverCapabilities.resources.subscribe)throw Error(`Server does not support resource subscriptions (required for ${q})`);break;case"tools/call":case"tools/list":if(!this._serverCapabilities?.tools)throw Error(`Server does not support tools (required for ${q})`);break;case"completion/complete":if(!this._serverCapabilities?.completions)throw Error(`Server does not support completions (required for ${q})`);break;case"initialize":break;case"ping":break}}assertNotificationCapability(q){switch(q){case"notifications/roots/list_changed":if(!this._capabilities.roots?.listChanged)throw Error(`Client does not support roots list changed notifications (required for ${q})`);break;case"notifications/initialized":break;case"notifications/cancelled":break;case"notifications/progress":break}}assertRequestHandlerCapability(q){if(!this._capabilities)return;switch(q){case"sampling/createMessage":if(!this._capabilities.sampling)throw Error(`Client does not support sampling capability (required for ${q})`);break;case"elicitation/create":if(!this._capabilities.elicitation)throw Error(`Client does not support elicitation capability (required for ${q})`);break;case"roots/list":if(!this._capabilities.roots)throw Error(`Client does not support roots capability (required for ${q})`);break;case"tasks/get":case"tasks/list":case"tasks/result":case"tasks/cancel":if(!this._capabilities.tasks)throw Error(`Client does not support tasks capability (required for ${q})`);break;case"ping":break}}assertTaskCapability(q){nz8(this._serverCapabilities?.tasks?.requests,q,"Server")}assertTaskHandlerCapability(q){if(!this._capabilities)return;iz8(this._capabilities.tasks?.requests,q,"Client")}async ping(q){return this.request({method:"ping"},rc,q)}async complete(q,K){return this.request({method:"completion/complete",params:q},o61,K)}async setLoggingLevel(q,K){return this.request({method:"logging/setLevel",params:{level:q}},rc,K)}async getPrompt(q,K){return this.request({method:"prompts/get",params:q},n61,K)}async listPrompts(q,K){return this.request({method:"prompts/list",params:q},Nu6,K)}async listResources(q,K){return this.request({method:"resources/list",params:q},vu6,K)}async listResourceTemplates(q,K){return this.request({method:"resources/templates/list",params:q},F61,K)}async readResource(q,K){return this.request({method:"resources/read",params:q},ku6,K)}async subscribeResource(q,K){return this.request({method:"resources/subscribe",params:q},rc,K)}async unsubscribeResource(q,K){return this.request({method:"resources/unsubscribe",params:q},rc,K)}async callTool(q,K=MB,_){if(this.isToolTaskRequired(q.name))throw new MK($5.InvalidRequest,`Tool "${q.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`);let z=await this.request({method:"tools/call",params:q},K,_),Y=this.getToolOutputValidator(q.name);if(Y){if(!z.structuredContent&&!z.isError)throw new MK($5.InvalidRequest,`Tool ${q.name} has an output schema but did not return structured content`);if(z.structuredContent)try{let $=Y(z.structuredContent);if(!$.valid)throw new MK($5.InvalidParams,`Structured content does not match the tool's output schema: ${$.errorMessage}`)}catch($){if($ instanceof MK)throw $;throw new MK($5.InvalidParams,`Failed to validate structured content: ${$ instanceof Error?$.message:String($)}`)}}return z}isToolTask(q){if(!this._serverCapabilities?.tasks?.requests?.tools?.call)return!1;return this._cachedKnownTaskTools.has(q)}isToolTaskRequired(q){return this._cachedRequiredTaskTools.has(q)}cacheToolMetadata(q){this._cachedToolOutputValidators.clear(),this._cachedKnownTaskTools.clear(),this._cachedRequiredTaskTools.clear();for(let K of q){if(K.outputSchema){let z=this._jsonSchemaValidator.getValidator(K.outputSchema);this._cachedToolOutputValidators.set(K.name,z)}let _=K.execution?.taskSupport;if(_==="required"||_==="optional")this._cachedKnownTaskTools.add(K.name);if(_==="required")this._cachedRequiredTaskTools.add(K.name)}}getToolOutputValidator(q){return this._cachedToolOutputValidators.get(q)}async listTools(q,K){let _=await this.request({method:"tools/list",params:q},Eu6,K);return this.cacheToolMetadata(_.tools),_}_setupListChangedHandler(q,K,_,z){let Y=eW7.safeParse(_);if(!Y.success)throw Error(`Invalid ${q} listChanged options: ${Y.error.message}`);if(typeof _.onChanged!=="function")throw Error(`Invalid ${q} listChanged options: onChanged must be a function`);let{autoRefresh:$,debounceMs:A}=Y.data,{onChanged:O}=_,w=async()=>{if(!$){O(null,null);return}try{let H=await z();O(null,H)}catch(H){let J=H instanceof Error?H:Error(String(H));O(J,null)}},j=()=>{if(A){let H=this._listChangedDebounceTimers.get(q);if(H)clearTimeout(H);let J=setTimeout(w,A);this._listChangedDebounceTimers.set(q,J)}else w()};this.setNotificationHandler(K,j)}async sendRootsListChanged(){return this.notification({method:"notifications/roots/list_changed"})}}});function Zp1(q){}function aN8(q){if(typeof q=="function")throw TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");let{onEvent:K=Zp1,onError:_=Zp1,onRetry:z=Zp1,onComment:Y}=q,$="",A=!0,O,w="",j="";function H(W){let D=A?W.replace(/^\xEF\xBB\xBF/,""):W,[f,G]=jYz(`${$}${D}`);for(let Z of f)J(Z);$=G,A=!1}function J(W){if(W===""){X();return}if(W.startsWith(":")){Y&&Y(W.slice(W.startsWith(": ")?2:1));return}let D=W.indexOf(":");if(D!==-1){let f=W.slice(0,D),G=W[D+1]===" "?2:1,Z=W.slice(D+G);M(f,Z,W);return}M(W,"",W)}function M(W,D,f){switch(W){case"event":j=D;break;case"data":w=`${w}${D}
1752`;break;case"id":O=D.includes("\x00")?void 0:D;break;case"retry":/^\d+$/.test(D)?z(parseInt(D,10)):_(new Gp1(`Invalid \`retry\` value: "${D}"`,{type:"invalid-retry",value:D,line:f}));break;default:_(new Gp1(`Unknown field "${W.length>20?`${W.slice(0,20)}…`:W}"`,{type:"unknown-field",field:W,value:D,line:f}));break}}function X(){w.length>0&&K({id:O,event:j||void 0,data:w.endsWith(`
1753`)?w.slice(0,-1):w}),O=void 0,w="",j=""}function P(W={}){$&&W.consume&&J($),A=!0,O=void 0,w="",j="",$=""}return{feed:H,reset:P}}function jYz(q){let K=[],_="",z=0;for(;z<q.length;){let Y=q.indexOf("\r",z),$=q.indexOf(`

Callers 4

Hb4Function · 0.95
cli.jsFile · 0.80
client.tsFile · 0.80
setupSdkMcpClientsFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected