Download ComfyUI-MiniMaxH3-Context-Loop/ComfyUI-MAINodes/concept_lab/mcp.py from dzmdd/Fast_deploy: direct link, hf CLI and curl.
- Browser
- Download file 9.93 kB
-
https://huggingface.co/dzmdd/Fast_deploy/resolve/main/ComfyUI-MiniMaxH3-Context-Loop/ComfyUI-MAINodes/concept_lab/mcp.py
- Command line
-
hf download hf://dzmdd/Fast_deploy/ComfyUI-MiniMaxH3-Context-Loop/ComfyUI-MAINodes/concept_lab/mcp.py
-
curl -L -o mcp.py https://huggingface.co/dzmdd/Fast_deploy/resolve/main/ComfyUI-MiniMaxH3-Context-Loop/ComfyUI-MAINodes/concept_lab/mcp.py
9.93 kB
| """The agent surface: the same verbs as the CLI, typed. | |
| <mcp-venv>/bin/python -m concept_lab.mcp | |
| Built on the same MCPServer/pydantic shape the h3-audio-lab server uses, so | |
| one venv serves both and the two read alike. The mcp and pydantic imports | |
| are inside this module rather than the package, so a ComfyUI install with | |
| neither still loads concept_lab fine; only running the server needs them. | |
| What is deliberately NOT on this surface: | |
| space_export with include_private. Export is a publishing act, packs can | |
| encode a likeness, and a model cannot prove who is asking. The agent can | |
| export the shareable set and can see exactly which packs were held back | |
| and why; releasing a private one is a human's keystroke through the CLI. | |
| Any verb that would run a model. Capture costs GPU time on a shared box | |
| with production instances on it, so the agent plans and a human launches. | |
| capture_plan gives the agent the whole cost picture for free. | |
| An agent that can measure everything and publish nothing is the right shape | |
| for this subsystem. | |
| """ | |
| from __future__ import annotations | |
| import sys | |
| from typing import Optional | |
| from pydantic import BaseModel, Field | |
| from mcp.server import MCPServer | |
| from concept_lab import api | |
| mcp = MCPServer( | |
| name="concept-lab", | |
| title="Concept Lab", | |
| instructions=( | |
| "Functional conditioning: measure what a reference does to the " | |
| "model, factor it, compile it back. Records here are EVIDENCE and " | |
| "carry their scope: a capture belongs to one model stack and a " | |
| "factor belongs to the split it was fitted on. Nothing on this " | |
| "surface runs a model or publishes a concept pack; plan the work " | |
| "and hand the launch to a human. Imported records keep their origin " | |
| "space id and are never your own measurements."), | |
| ) | |
| # ------------------------------------------------------------- outputs | |
| class SpaceOut(BaseModel): | |
| space_id: str | |
| label: str = "" | |
| index_root: str = "" | |
| tensor_root: str = "" | |
| counts: dict = Field(default_factory=dict) | |
| imported_spaces: list = Field(default_factory=list) | |
| tensor_bytes: int = 0 | |
| class CorpusOut(BaseModel): | |
| name: str | |
| corpus_id: str | |
| n_rows: int | |
| by_split: dict = Field(default_factory=dict) | |
| label_keys: list = Field(default_factory=list) | |
| matched_groups: dict = Field(default_factory=dict) | |
| singleton_groups: list = Field(default_factory=list) | |
| containment: dict = Field( | |
| default_factory=dict, | |
| description="Sources appearing in more than one split, by " | |
| "content_hash and by source_id. Any entry here means a " | |
| "held-out score would be an extraction score.") | |
| warnings: list = Field( | |
| default_factory=list, | |
| description="Protocol gaps. Not errors: a corpus missing its " | |
| "adversarial split can still be captured, it just " | |
| "cannot support a factor claim afterwards.") | |
| class ConfoundOut(BaseModel): | |
| target: str | |
| n_rows: int | |
| labels: dict = Field( | |
| description="Per label: verdict perfect|partial|free. 'perfect' " | |
| "means the two labels are in bijection over these rows " | |
| "and no method separates them; the fix is another " | |
| "example, not another solver.") | |
| error: Optional[str] = None | |
| class PlanOut(BaseModel): | |
| corpus: str | |
| backend: str | |
| arms: list | |
| forwards: int = Field(description="model forward passes this would cost") | |
| tap_points: int = Field(description="tensors this would write") | |
| tap: dict | |
| cost: dict = Field( | |
| default_factory=dict, | |
| description="Forward count is not the cost unit on H3: a reference " | |
| "block roughly doubles the packed sequence and per-step " | |
| "cost is superlinear in it. Price by tokens x steps.") | |
| process_launch_id: str = "" | |
| protocol_notes: list = Field( | |
| default_factory=list, | |
| description="Constraints on how the capture may be run, not advice. " | |
| "All arms of one comparison belong to one process " | |
| "launch.") | |
| containment_overridden: list = Field(default_factory=list) | |
| warnings: list = Field(default_factory=list) | |
| note: str = "" | |
| class ExportOut(BaseModel): | |
| bundle: str | |
| origin_space_id: str | |
| included: list | |
| excluded: list = Field( | |
| description="What was left out and why. Private packs land here " | |
| "unless a human exports them from the shell.") | |
| tensor_count: int = 0 | |
| bytes: int = 0 | |
| class ImportOut(BaseModel): | |
| origin_space_id: str | |
| origin_label: str = "" | |
| landed: list | |
| refused: list | |
| index_dir: str | |
| tensor_dir: str | |
| # --------------------------------------------------------------- tools | |
| def space_status() -> SpaceOut: | |
| return SpaceOut(**api.space_status()) | |
| def space_doctor() -> dict: | |
| return api.space_doctor() | |
| def space_list(kind: str) -> dict: | |
| return api.space_list(kind) | |
| def corpus_new(name: str, notes: str = "") -> dict: | |
| return api.corpus_new(name, notes=notes) | |
| def corpus_add(name: str, source_kind: str, source_ref: str, | |
| labels: Optional[dict] = None, split: str = "extract", | |
| matched_group: Optional[str] = None, | |
| source_id: Optional[str] = None, | |
| notes: str = "") -> dict: | |
| return api.corpus_add(name, source_kind, source_ref, labels=labels, | |
| split=split, matched_group=matched_group, | |
| source_id=source_id, notes=notes) | |
| def corpus_status(name: str) -> CorpusOut: | |
| return CorpusOut(**api.corpus_status(name)) | |
| def corpus_confounds(name: str, target: str) -> ConfoundOut: | |
| return ConfoundOut(**api.corpus_confounds(name, target)) | |
| def capture_plan(corpus: str, backend: str = "h3", store: str = "stats", | |
| replicates: int = 1) -> PlanOut: | |
| return PlanOut(**api.capture_plan(corpus, backend=backend, store=store, | |
| replicates=replicates)) | |
| def arms_check(corpus: str, r_row_id: str, n_row_id: str, | |
| backend: str = "h3") -> dict: | |
| return api.arms_check(corpus, r_row_id, n_row_id, backend=backend) | |
| def capture_record(manifest: dict) -> dict: | |
| return api.capture_record(manifest) | |
| def space_export(out_path: str, note: str = "") -> ExportOut: | |
| res = api.space_export(out_path, include_private=False, note=note) | |
| return ExportOut(**{k: res[k] for k in | |
| ("bundle", "origin_space_id", "included", "excluded", | |
| "tensor_count", "bytes")}) | |
| def space_import(bundle_path: str) -> ImportOut: | |
| return ImportOut(**api.space_import(bundle_path)) | |
| def pack_list() -> dict: | |
| return api.pack_list() | |
| if __name__ == "__main__": | |
| sys.exit(mcp.run()) | |