defineToolPlugin का उपयोग तब करें जब
Plugin टूल की एक निश्चित सूची का स्वामी हो और आप चाहते हों कि OpenClaw वह manifest
metadata जनरेट करे जो runtime code लोड किए बिना उन टूल को खोजने योग्य बनाए रखता है।
अनुशंसित प्रवाह यह है:
openclaw plugins initके साथ package scaffold करें।defineToolPluginके साथ टूल लिखें।- JavaScript build करें।
openclaw plugins buildके साथopenclaw.plugin.jsonऔरpackage.jsonmetadata जनरेट करें।- प्रकाशित या इंस्टॉल करने से पहले जनरेट किए गए metadata को validate करें।
आवश्यकताएँ
- Node >= 22.
- TypeScript ESM package output.
- config और tool parameter schemas के लिए
typebox. openclaw >=2026.5.17, पहला OpenClaw version जोopenclaw/plugin-sdk/tool-pluginexport करता है।- ऐसा package root जो
dist/,openclaw.plugin.json, औरpackage.jsonship कर सके।
typebox import करता है, इसलिए typebox को
सिर्फ devDependencies में नहीं, बल्कि dependencies में रखें।
Quickstart
नया Plugin package बनाएँ:src/index.ts:echotool के साथ एकdefineToolPluginentry.src/index.test.ts: एक छोटा metadata test.tsconfig.json:dist/में NodeNext TypeScript output.package.json: scripts, runtime dependencies, औरopenclaw.extensions: ["./dist/index.js"].openclaw.plugin.json: शुरुआती tool के लिए जनरेट किया गया manifest metadata.
टूल लिखें
defineToolPlugin Plugin identity, एक वैकल्पिक config schema, और
टूल की static सूची लेता है। Parameter और config types TypeBox schemas से infer किए जाते हैं।
वैकल्पिक और factory टूल
जब users को tool model को भेजे जाने से पहले उसे स्पष्ट रूप से allowlist करना चाहिए, तबoptional: true set करें:
openclaw plugins build मेल खाती हुई toolMetadata.<tool>.optional
manifest entry लिखता है, ताकि OpenClaw Plugin runtime code लोड किए बिना tool खोज सके।
जब किसी tool को बनने से पहले runtime tool context की आवश्यकता हो, तब factory का उपयोग करें। factory metadata को static रखती है और tool को किसी
specific run के लिए opt out करने, sandbox state inspect करने, या runtime helpers bind करने देती है।
definePluginEntry का उपयोग करें।
Return values
defineToolPlugin plain return values को OpenClaw tool-result
format में wrap करता है:
- जब model को वही exact text दिखना चाहिए, तब string return करें।
- जब आप चाहते हैं कि model formatted JSON देखे
और OpenClaw original value को
detailsमें रखे, तब JSON-compatible value return करें।
AgentToolResult return करना हो या मौजूदा
api.registerTool implementation reuse करना हो, तब factory tool का उपयोग करें। जब आपको पूरी तरह dynamic tools या mixed Plugin
capabilities की आवश्यकता हो, तब defineToolPlugin के बजाय definePluginEntry का उपयोग करें।
Configuration
configSchema वैकल्पिक है। यदि आप इसे omit करते हैं, तो OpenClaw strict empty object
schema का उपयोग करता है और जनरेट किए गए manifest में फिर भी configSchema शामिल होता है।
configSchema शामिल करते हैं, तो दूसरा execute argument
schema से type किया जाता है:
जनरेट किया गया metadata
OpenClaw installed Plugins को cold metadata से discover करता है। उसे Plugin runtime code import करने से पहले Plugin manifest पढ़ने में सक्षम होना चाहिए। इसलिएdefineToolPlugin
static metadata expose करता है, और openclaw plugins build उस
metadata को package में लिखता है।
Plugin id, name, description, config schema,
activation, या tool names बदलने के बाद generator चलाएँ:
contracts.tools महत्वपूर्ण discovery contract है। यह OpenClaw को बताता है कि हर tool का स्वामी कौन सा
Plugin है, बिना हर installed Plugin runtime को लोड किए। यदि
manifest stale है, तो tool discovery से missing हो सकता है या registration error के लिए गलत Plugin को दोषी माना जा सकता है।
Package metadata
सरल tool-Plugin workflow के लिए,openclaw plugins build
package.json को selected single runtime entry के साथ align करता है:
./dist/index.js जैसी built JavaScript का उपयोग करें। Source
entries workspace development में उपयोगी हैं, लेकिन published packages को
TypeScript runtime loading पर निर्भर नहीं होना चाहिए।
CI में validate करें
जनरेट किया गया metadata stale होने पर files rewrite किए बिना CI fail करने के लिएplugins build --check का उपयोग करें:
plugins validate जाँचता है कि:
openclaw.plugin.jsonमौजूद है और normal manifest loader से pass होता है।- current entry
defineToolPluginmetadata export करती है। - जनरेट किए गए manifest fields entry metadata से match करते हैं।
contracts.toolsdeclared tool names से match करता है।package.jsonopenclaw.extensionsको selected runtime entry पर point करता है।
स्थानीय रूप से install और inspect करें
अलग OpenClaw checkout या installed CLI से, package path install करें:Publish
package ready होने पर ClawHub के माध्यम से publish करें:Troubleshooting
plugin entry not found: ./dist/index.js
selected entry file मौजूद नहीं है। npm run build चलाएँ, फिर
openclaw plugins build --entry ./dist/index.js या
openclaw plugins validate --entry ./dist/index.js फिर से चलाएँ।
plugin entry does not expose defineToolPlugin metadata
entry ने defineToolPlugin द्वारा created value export नहीं की। जाँचें कि
module default export defineToolPlugin(...) result है, या --entry के साथ सही
entry pass करें।
openclaw.plugin.json generated metadata is stale
manifest अब entry metadata से match नहीं करता। चलाएँ:
openclaw.plugin.json और package.json दोनों changes commit करें।
package.json openclaw.extensions must include ./dist/index.js
package metadata किसी अलग runtime entry की ओर point करता है। openclaw plugins build --entry ./dist/index.js चलाएँ ताकि generator
package metadata को उस entry के साथ align करे जिसे आप ship करना चाहते हैं।
Cannot find package 'typebox'
built Plugin runtime पर typebox import करता है। typebox को
dependencies में रखें, package dependencies reinstall करें, rebuild करें, और validation फिर से चलाएँ।
install के बाद tool दिखाई नहीं देता
इन्हें क्रम में जाँचें:openclaw plugins inspect <plugin-id> --runtimeopenclaw plugins validate --root <plugin-root> --entry ./dist/index.jsopenclaw.plugin.jsonमें expected tool names के साथcontracts.toolsहै।package.jsonमेंopenclaw.extensions: ["./dist/index.js"]है।- Plugin install करने के बाद Gateway restart या reload किया गया था।