MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / cacheToolMetadata

Method cacheToolMetadata

src/client/index.ts:806–827  ·  view source on GitHub ↗

* Cache validators for tool output schemas. * Called after listTools() to pre-compile validators for better performance.

(tools: Tool[])

Source from the content-addressed store, hash-verified

804 * Called after listTools() to pre-compile validators for better performance.
805 */
806 private cacheToolMetadata(tools: Tool[]): void {
807 this._cachedToolOutputValidators.clear();
808 this._cachedKnownTaskTools.clear();
809 this._cachedRequiredTaskTools.clear();
810
811 for (const tool of tools) {
812 // If the tool has an outputSchema, create and cache the validator
813 if (tool.outputSchema) {
814 const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema as JsonSchemaType);
815 this._cachedToolOutputValidators.set(tool.name, toolValidator);
816 }
817
818 // If the tool supports task-based execution, cache that information
819 const taskSupport = tool.execution?.taskSupport;
820 if (taskSupport === 'required' || taskSupport === 'optional') {
821 this._cachedKnownTaskTools.add(tool.name);
822 }
823 if (taskSupport === 'required') {
824 this._cachedRequiredTaskTools.add(tool.name);
825 }
826 }
827 }
828
829 /**
830 * Get cached validator for a tool

Callers 1

listToolsMethod · 0.95

Calls 2

clearMethod · 0.80
getValidatorMethod · 0.65

Tested by

no test coverage detected