Skip to content

fix(plugins): instantiate entry-point toolkits and raise on a broken plugin - #121

Merged
gopaljigaur merged 4 commits into
mainfrom
fix/plugin-loading
Oct 15, 2026
Merged

gopaljigaur merged 4 commits into
mainfrom
fix/plugin-loading

Conversation

@gopaljigaur

@gopaljigaur gopaljigaur commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • PluginManager.load_plugins calls what each cyclops.toolkits entry point names (a Toolkit subclass or a factory returning one) and registers the instance. Before, it registered the class itself, get_tools() failed on the unbound method, and the warning-only handling dropped every tool.
  • A plugin that fails to import or instantiate raises RuntimeError naming the entry point ('weather' (pkg.plugin:WeatherToolkit)) with the original error as the cause. A result that is not a Toolkit raises TypeError. This follows pluggy and pytest, which raise on a broken plugin: a missing toolkit should not be silent. Stevedore's invoke_on_load is the model for calling the loaded object, so classes and factories both work.
  • Two distributions that use the same entry-point name raise ValueError naming both, before any plugin loads; before, the second silently replaced the first. register raises Plugin name already registered on a name in use, as pluggy does.
  • load_plugins uses entry_points(group=...) directly and drops the outer catch-all. register_tools no longer swallows get_tools() errors; duplicate tool names are still skipped with a warning, as before.
  • Docs: the MathToolkit example raised TypeError (_make_tools.__func__(None)). It now uses @tool on functions in the class body, which are already Tool attributes. The guide, website page and API reference now describe what load_plugins does, so "instantiate WeatherToolkit automatically" is true. The website page gains the same @tool section.

Tests

tests/test_plugins.py writes a module and a .dist-info with entry_points.txt into a tmp dir on sys.path, so loading goes through real importlib.metadata entry points: a class, a factory, tool execution, a plugin that fails to import, a factory returning a non-Toolkit, two plugins sharing a tool name, and two distributions sharing a plugin name. A further test covers a duplicate name passed to register.

The guide's and website's WeatherToolkit and MathToolkit blocks were also run as installed entry-point plugins.

uv run pytest (478 passed), uv run pre-commit run --all-files and uv run mypy cyclops pass.

Closes #116

@gopaljigaur gopaljigaur left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading, the errors and the docs work as described. I installed the WeatherToolkit and MathToolkit examples from both pages as real packages and ran their tools through MCPServer. The new tests use real entry points and all six fail on main. pytest (also run twice in reversed order), pre-commit, mypy and CI pass. Raising by default matches pluggy and Flask, and load_plugins=False with register() remains the way to skip a plugin.

One finding: a second distribution with the same entry point name silently replaces the first toolkit (inline on plugins.py).

Comment thread cyclops/toolkit/plugins.py Resolved

@gopaljigaur gopaljigaur left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate name check works, and the docs, tests and checks are fine apart from one gap. Two real .dist-info dirs that share an entry-point name now raise ValueError: Toolkit plugin name 'm' is used by d1, d2 before anything loads. The two new tests fail on the previous commit. On the tree merged with main: pytest, pre-commit and mypy pass, and CI is green.

One finding: the register docs do not mention the new ValueError (inline on docs/guide/plugins.md).

Comment thread docs/guide/plugins.md Resolved
…plugin

load_plugins registered the class an entry point names without calling
it, so get_tools() failed on the unbound method and the warning-only
handling dropped every tool. It now calls the loaded class or factory,
checks the result is a Toolkit, and raises RuntimeError naming the entry
point when loading fails, as pluggy and pytest do for broken plugins.
register_tools no longer swallows get_tools() errors.
The example called _make_tools.__func__(None) on a function that takes
no arguments and raised TypeError. Decorated functions in the class body
are already Tool attributes, so the example now uses @tool directly. The
notes now say load_plugins instantiates the class or factory and raises
on a broken plugin.
The second toolkit replaced the first in plugins without a trace.
load_plugins now raises ValueError naming both distributions before
loading anything, and register raises on a name already in use, as
pluggy does.

@gopaljigaur gopaljigaur left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings.

@gopaljigaur
gopaljigaur merged commit e4337e9 into main Oct 15, 2026
10 checks passed
@gopaljigaur
gopaljigaur deleted the fix/plugin-loading branch October 15, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(plugins): entry-point toolkits are registered without being instantiated

1 participant