MCPcopy
hub / github.com/ZToolsCenter/ZTools / getDeclaredToolsByPath

Method getDeclaredToolsByPath

src/main/api/plugin/tools.ts:77–106  ·  view source on GitHub ↗

* 从插件目录读取并筛选合法的 tools 声明。

(pluginPath: string)

Source from the content-addressed store, hash-verified

75 * 从插件目录读取并筛选合法的 tools 声明。
76 */
77 public getDeclaredToolsByPath(pluginPath: string): Record<string, DeclaredPluginTool> {
78 try {
79 const pluginJsonPath = path.join(pluginPath, 'plugin.json')
80 const pluginConfig = JSON.parse(
81 fsSync.readFileSync(pluginJsonPath, 'utf-8')
82 ) as PluginConfigWithTools
83 if (!pluginConfig.tools || typeof pluginConfig.tools !== 'object') {
84 return {}
85 }
86 return Object.entries(pluginConfig.tools).reduce<Record<string, DeclaredPluginTool>>(
87 (acc, [toolName, tool]) => {
88 if (
89 !tool ||
90 typeof tool !== 'object' ||
91 typeof tool.description !== 'string' ||
92 !tool.inputSchema ||
93 typeof tool.inputSchema !== 'object' ||
94 Array.isArray(tool.inputSchema)
95 ) {
96 return acc
97 }
98 acc[toolName] = tool
99 return acc
100 },
101 {}
102 )
103 } catch {
104 return {}
105 }
106 }
107
108 /**
109 * 根据 WebContents 反查所属插件并读取其 tools 声明。

Callers 3

registerToolMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected