If your MCP tools or prompts pull dependencies from their constructors, asserting their registration in tests could crash outright in earlier releases. The server's test helpers instantiated classes with a bare new expression, bypassing Laravel's container entirely. A small fix in the testing layer now resolves those classes through the container, so dependency-injected tools and prompts behave in test assertions exactly as they do at runtime.
What was breaking
The laravel/mcp documentation treats constructor injection as a first-class pattern for tools and prompts, and the server itself honors it — when a real request comes in, registered classes are built by the container. The testing helper behind assertRegistered() and assertNotRegistered(), however, took a shortcut. To read the name() off each registered class, it used (new $class)->name(), which fails the moment a constructor declares a required parameter:
class EngineDiagnosticTool extends Tool
{
protected string $name = 'garage/engine-diagnostics';
public function __construct(
protected DiagnosticsRepository $diagnostics,
) {}
public function handle(): string
{
return 'Diagnostics complete.';
}
}
With that tool registered on a server, a perfectly reasonable test died before the assertion could even run:
GarageListToolsServer::tools()->assertRegistered(EngineDiagnosticTool::class);
// ArgumentCountError: Too few arguments to function
// EngineDiagnosticTool::__construct(), 0 passed ...
The frustrating part was that the error said nothing about your assertion logic. The tool registered fine in production — only the test helper couldn't construct it.
The fix
Both assertRegistered() and assertNotRegistered() now fetch the container and let it build each class:
// Before (v1.2.0)
$name = (new $class)->name();
// After
$name = Container::getInstance()->make($class)->name();
Because make() resolves the full dependency graph, a tool like EngineDiagnosticTool now instantiates cleanly and the assertion gets back to its real job: comparing the resolved name() against the items in the list response. The change lands in the shared TestListResponse helper, so it covers tools and prompts — the two surfaces exercised by the new regression tests — and anything else that flows through the same code path.
Why it matters
Two reasons. First, parity: the test harness now constructs classes the same way the server does, so what you assert in tests matches what actually runs in production. Second, test-time container bindings are respected. Since resolution flows through the container, any binding you make in your test is honored during the assertion:
it('resolves tools with constructor dependencies', function () {
$this->instance(DiagnosticsRepository::class, new InMemoryDiagnosticsRepository);
GarageListToolsServer::tools()->assertRegistered(EngineDiagnosticTool::class);
});
That means you can point a tool at a fake repository for testing purposes without touching the tool itself — something that was previously impossible if the assertion helper couldn't even construct the class in the first place.
Upgrade impact
Upgrading from v1.2.0 requires no changes on your side: no method signatures changed, no new configuration was introduced, and no behavioral contract broke. Tests that already pass will keep passing, since dependency-free classes resolve through the container just as cleanly as they did via new. The visible difference is that tests that previously died with ArgumentCountError now execute normally.
If you worked around the old bug — by giving constructor parameters default values, creating stripped-down duplicates of your tools solely for tests, or asserting against dependency-free stand-ins — you can now delete those workarounds and inject your real dependencies directly.
Takeaways
assertRegistered()andassertNotRegistered()now resolve classes viaContainer::getInstance()->make(), so tools and prompts with constructor dependencies no longer crash withArgumentCountError.- Test-time container bindings, instances, and fakes are honored during registration assertions.
- No public API changes: upgrading from v1.2.0 requires no code changes in your application or test suite.
- Workarounds such as nullable constructor parameters or dependency-free test doubles used only to satisfy assertions can be removed.