52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""Control-plane service for independently scoped MCP clients."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from uuid import UUID
|
|
|
|
from packages.hub_clients import (
|
|
BootstrapHandle,
|
|
ClientConfig,
|
|
ClientKind,
|
|
ClientRecord,
|
|
ClientRegistry,
|
|
generate_config,
|
|
)
|
|
|
|
|
|
class ClientService:
|
|
def __init__(self, registry: ClientRegistry | None = None) -> None:
|
|
self.registry = registry or ClientRegistry()
|
|
|
|
def create(
|
|
self, *, name: str, project: str, environment: str, kind: ClientKind
|
|
) -> tuple[ClientRecord, BootstrapHandle, ClientConfig]:
|
|
record = self.registry.create(
|
|
name=name, project=project, environment=environment, kind=kind
|
|
)
|
|
bootstrap = self.registry.issue_bootstrap(record.id)
|
|
return record, bootstrap, generate_config(record)
|
|
|
|
def list(self) -> tuple[ClientRecord, ...]:
|
|
return self.registry.list()
|
|
|
|
def config(self, client_id: UUID, kind: ClientKind | None = None) -> ClientConfig:
|
|
record = self.registry.get(client_id)
|
|
if record is None:
|
|
raise KeyError(client_id)
|
|
selected = (
|
|
record
|
|
if kind is None or kind is record.kind
|
|
else record.model_copy(update={"kind": kind})
|
|
)
|
|
return generate_config(selected)
|
|
|
|
def disable(self, client_id: UUID) -> ClientRecord:
|
|
return self.registry.disable(client_id)
|
|
|
|
def revoke(self, client_id: UUID) -> ClientRecord:
|
|
return self.registry.revoke(client_id)
|
|
|
|
def bootstrap(self, client_id: UUID) -> BootstrapHandle:
|
|
return self.registry.issue_bootstrap(client_id)
|