This plugin demonstrates dynamic tool list management in hyper-mcp. It showcases how a plugin can modify its tool list at runtime and notify the MCP server about these changes.
- Dynamic Tool Creation: Starts with a single
add_tooland dynamically creates new tools - Host Function Integration: Uses the
notify_tool_list_changedhost function to notify the server - Atomic Counter: Thread-safe tool counting using atomic operations
The plugin begins with only one callable tool:
add_tool: When called, this tool creates a new tool namedtool_n(where n starts at 1 and increments)
After each call to add_tool:
- A new tool
tool_nis added to the plugin's tool list - The plugin calls
notify_tool_list_changed()to inform the MCP server - The server updates its understanding of available tools
- add_tool: Creates a new dynamic tool and notifies the server of the tool list change
- Takes no parameters
- Returns a JSON object with the new tool name and current tool count
- tool_1, tool_2, tool_3, ...: Created dynamically when
add_toolis called- Each tool returns information about itself when called
- Takes no parameters
- Initial state: Only
add_toolis available - Call
add_tool: Createstool_1and notifies the server - Call
add_toolagain: Createstool_2and notifies the server - Call
tool_1: Returns information about being the first dynamically created tool
cd hyper-mcp/examples/plugins/v1/tool-list-changed
cargo build --target wasm32-unknown-unknown --releaseThe compiled WASM file will be available at:
target/wasm32-unknown-unknown/release/tool_list_changed.wasm
This plugin requires no additional configuration. It uses atomic operations to maintain thread-safe state across calls.
- Uses
AtomicUsizefor thread-safe tool counting - Calls the
notify_tool_list_changedhost function after each tool addition - Implements both static (
add_tool) and dynamic (tool_n) tool handling - Provides JSON responses with relevant information about operations