Inferred from configSchema if provided
OptionalconfigPlugin configuration
If configSchema is provided, this will be validated at plugin creation.
OptionalconfigZod schema for config validation
If provided, config will be validated and TConfig will be inferred.
Unique plugin identifier
Used for logging, debugging, and error messages. Must be unique within an app.
OptionalversionPlugin version (semantic versioning recommended)
Optional but helpful for debugging.
OptionalafterCalled after tool handler succeeds
If this hook throws, error is logged but response is sent normally.
OptionalbeforeCalled before tool handler executes
Executes after middleware chain but before handler. If this hook throws, error is logged but tool execution continues.
OptionalonCalled when app is initialized (before server starts)
If this hook throws, app initialization fails.
OptionalonCalled when HTTP request received (before routing)
Not available for stdio transport. If this hook throws, error is logged but request continues.
OptionalonCalled before HTTP response sent
Not available for stdio transport. If this hook throws, error is logged but response is sent normally.
OptionalonCalled during graceful shutdown
Hook is subject to shutdown timeout (default 30s).
OptionalonCalled when server starts successfully
If this hook throws, error is logged but server continues.
OptionalonCalled when tool handler throws error
Cannot prevent error from propagating to client. If this hook throws, error is logged separately.
OptionalonCalled when UI resource is loaded
If this hook throws, error is logged but UI is served normally.
Plugin definition with lifecycle and execution hooks
Plugins extend app behavior without modifying tool handlers. All hooks are optional - implement only what you need.
Example