Skip to content

Commit

Permalink
refactor(di): introduce dependency injection (di) util, untie service…
Browse files Browse the repository at this point in the history
…->cli dependency
  • Loading branch information
helmut-hoffer-von-ankershoffen committed Dec 27, 2024
1 parent 70fdf50 commit a5a61be
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/starbridge/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _generate_mcp_server_config(
}


# locate sub cli's and register them
# dynamically locate and register subcommands
for _cli in locate_implementations(typer.Typer):
if _cli != cli:
cli.add_typer(_cli)
Expand Down
2 changes: 1 addition & 1 deletion src/starbridge/mcp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def health():
@cli.command()
def services():
"""Services exposed by modules"""
console.print(MCPServer.services())
console.print(MCPServer.service_classes())


@cli.command()
Expand Down
8 changes: 4 additions & 4 deletions src/starbridge/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class MCPServer:
"""MCP Server for Starbridge."""

def __init__(self):
# dynamically locate and register services
self._services = []
for service_class in MCPServer.services():
for service_class in MCPServer.service_classes():
self._services.append(service_class())

self._server = Server(__project_name__)
Expand All @@ -61,8 +62,7 @@ def __init__(self):
def health(self, context: MCPContext | None = None) -> AggregatedHealth:
"""Health of services and their dependencies"""
dependencies = {}
for service_class in MCPServer.services():
service = service_class()
for service in self._services:
service_name = service.__class__.__module__.split(".")[1]
dependencies[service_name] = service.health()

Expand Down Expand Up @@ -262,7 +262,7 @@ async def run_stdio(self):
)

@staticmethod
def services() -> list[type["MCPBaseService"]]:
def service_classes() -> list[type["MCPBaseService"]]:
return locate_subclasses(MCPBaseService) # type: ignore

@staticmethod
Expand Down

0 comments on commit a5a61be

Please sign in to comment.