Dependency injection for Mojo that fails at compile time, not in production.
mjdi validates your whole dependency graph while the compiler runs — missing providers, cycles, duplicates and scope mismatches become compile errors with actionable diagnostics. At runtime, a Container resolves cached singletons, fresh transients and scoped instances.
- documentation pages:
- example applications:
- release:
Everything checked before main() runs
mjdi keeps registration and validation entirely at compile time, and does exactly one runtime job: constructing and caching your objects.
Wire an application in three lines
Declare dependencies with Inject[T] members, build an immutable Registry by chaining register[T]() calls, and hand it to a Container. The graph is validated when the container alias is defined — miswiring never reaches runtime.
Install Mojo 1.2.0, drop the mjdi package next to your source, and wire your first application:
from mjdi import Container, Inject, Injectable, Registry
struct MessageRenderer(Injectable):
def render(self, name: String) -> String:
return String("Hello, ") + name + String("!")
struct GreetingService(Injectable):
var renderer: Inject[MessageRenderer]
def greet(self, name: String) -> String:
return self.renderer.value().render(name)
def main() raises:
comptime app_registry = (
Registry()
.register[MessageRenderer]()
.register[GreetingService]()
)
var app = Container[type_of(app_registry)]()
var service = app.resolve[GreetingService]()
print(service.greet("mojo"))
If a provider is missing — say you delete .register[MessageRenderer]() — the program no longer compiles: the diagnostic names the missing provider, the consumer GreetingService and how to fix it.
An MCP endpoint for agents: /api/mcp
The website exposes the mjdi documentation and example sources over the Model Context Protocol (Streamable HTTP, JSON-RPC 2.0). Wire it into your editor or agent and the docs travel with the tools.
/api/mcp and read the raw response — exactly what an MCP client does.Send a request to see the response.Point any MCP-capable client at the endpoint:
{
"mcpServers": {
"mjdi-docs": {
"type": "http",
"url": "https://your-host/api/mcp"
}
}
}
The server is stateless and read-only. It exposes tools (list_doc_versions, list_docs, get_doc, search_docs, get_quickstart, get_api_reference, get_changelog, list_examples, get_example — each documentation tool accepts an optional version argument) and resources (mjdi://docs/<version>/<slug>), so coding agents can pull accurate mjdi documentation — including compile-fail and crash-test behavior — straight from the repository markdown. Prefer plain HTTP? Every page is raw markdown at /api/docs/0.10.0/<page>.md. See the MCP server docs and the website docs.