mcp-dispatch 0.2.0__tar.gz → 0.3.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/AGENTS.md +17 -8
  2. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/CHANGELOG.md +18 -0
  3. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/PKG-INFO +1 -1
  4. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/pyproject.toml +1 -1
  5. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/__init__.py +1 -1
  6. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/_skill_meaning.py +20 -33
  7. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/agent_instructions/host.md +3 -3
  8. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/agent_instructions/plugin.md +6 -7
  9. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/check.py +219 -73
  10. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/cli.py +69 -62
  11. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/dispatch.py +8 -12
  12. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/errors.py +8 -3
  13. mcp_dispatch-0.3.0.dev1/src/mcp_dispatch/index.py +253 -0
  14. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/mcp_tools.py +1 -1
  15. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/registry.py +256 -84
  16. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/skills.py +69 -188
  17. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/tags.py +9 -0
  18. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/conftest.py +0 -8
  19. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/helpers.py +6 -2
  20. mcp_dispatch-0.3.0.dev1/tests/shelf_functions.py +78 -0
  21. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_check.py +353 -341
  22. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_cli.py +117 -248
  23. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_dispatch.py +45 -53
  24. mcp_dispatch-0.3.0.dev1/tests/test_functions.py +421 -0
  25. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_guides.py +15 -34
  26. mcp_dispatch-0.3.0.dev1/tests/test_index.py +204 -0
  27. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_package.py +0 -1
  28. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_registry.py +158 -47
  29. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_registry_skills.py +30 -134
  30. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_skill_relevance.py +10 -5
  31. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_skills.py +0 -201
  32. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/kit.py +1 -2
  33. mcp_dispatch-0.2.0/trials/guide/reference/skills/index.json +0 -18
  34. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/.gitignore +0 -0
  35. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/LICENSE +0 -0
  36. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/README.md +0 -0
  37. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/__main__.py +0 -0
  38. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/command.py +0 -0
  39. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/docs.py +0 -0
  40. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/lenient.py +0 -0
  41. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/py.typed +0 -0
  42. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/tables.py +0 -0
  43. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/src/mcp_dispatch/trials.py +0 -0
  44. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/__init__.py +0 -0
  45. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/data/skill_headers.json +0 -0
  46. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/data/skill_questions.txt +0 -0
  47. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_command.py +0 -0
  48. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_mcp.py +0 -0
  49. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_skill_meaning.py +0 -0
  50. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_tables.py +0 -0
  51. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/tests/test_trials.py +0 -0
  52. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/README.md +0 -0
  53. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/reference/skills/keep-stock.md +0 -0
  54. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/reference/stock.py +0 -0
  55. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/template/AGENTS.md +0 -0
  56. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/template/pyproject.toml +0 -0
  57. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/template/src/labkit/__init__.py +0 -0
  58. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/template/src/labkit/host.py +0 -0
  59. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/template/src/labkit/store.py +0 -0
  60. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/guide/template/tests/test_host.py +0 -0
  61. {mcp_dispatch-0.2.0 → mcp_dispatch-0.3.0.dev1}/trials/results/guide.jsonl +0 -0
@@ -18,17 +18,19 @@ uv run mcp-dispatch guide host # the guide for a host
18
18
 
19
19
  ```
20
20
  src/mcp_dispatch/
21
- tags.py Plugin, @action, @searches, Tool, standard_tools: what a plugin author imports; no dependencies
22
- errors.py DispatchError and how it reads to the caller; PluginError, a plugin that cannot be loaded
23
- registry.py Registry: the tools, the packages, resolve(tool, arguments) -> Help | Bound, argument checks from type hints, the search, help, contract()
24
- skills.py skill files (header, body), the generated index, the search over skills, the built-in package `skill`
21
+ tags.py Plugin (and its `modules`), @action, @searches, Tool, standard_tools: what a plugin author imports; no dependencies
22
+ errors.py DispatchError and how it reads to the caller; PluginError, an entry point that cannot be taken
23
+ registry.py Registry: the tools, the packages, resolve(tool, arguments) -> Help | Bound, argument checks from type hints, the search, help; a plugin found through its entry point is loaded at its first use
24
+ skills.py skill files (header, body), read when a package is registered; the guides as a kind of the store in memory and the bars a guide has to clear; the built-in package `skill`
25
+ index.py the one search's store in memory: MemoryIndex with put, remove, search over things of any kind and their pieces, by meaning or by words; `Registry.index`
26
+ _skill_meaning.py the model, which the process owns, and the bars measured for it
25
27
  docs.py Google docstrings read into their parts
26
28
  lenient.py JSON sent as text, read with repairs
27
29
  dispatch.py Dispatch: a host in a few lines (tools, plugins, the initial message, the server)
28
30
  mcp_tools.py the tools as an MCP server shows them (`register` and the annotations need the extra `mcp`; the schemas do not)
29
- check.py problems(dispatch), update(dispatch): what `mcp-dispatch check` and `update` do
31
+ check.py problems(dispatch), what `mcp-dispatch check` does: every action and skill, and a walk through every page of help; integrity(plugins), the same for a package's own tests; run_problems, every call that is shown to an assistant run once with what a test hands over
30
32
  command.py a call made without a client: the words of a command line as arguments, `answer(registry, tool, arguments, run)`
31
- cli.py the command line: guide, check, update, help, call
33
+ cli.py the command line: guide, check, help, call
32
34
  trials.py run_session: one headless assistant session with the tools it is given, its transcript read into calls and counts; what a project's trial kit builds on
33
35
  agent_instructions/ plugin.md, host.md: the guides, shipped in the wheel and printed by `mcp-dispatch guide`
34
36
  tests/
@@ -38,7 +40,8 @@ trials/ the library's own kit: trials of its guides with assistants tha
38
40
  ## Rules
39
41
 
40
42
  - **One way to do a thing.** No aliases for arguments, no second form of a call. A wrong form is refused with the right one in the hint.
41
- - **Fail loudly at the start.** A plugin that cannot be loaded, a tag for a tool the host does not have, a skill index that does not list the files that are there: each stops the host. Nothing is logged and skipped.
43
+ - **One source for each fact.** What an assistant is told about an action is read from the function: its tag, signature, type hints and docstring. Nothing is generated from them and nothing is pinned in a file; a copy would need a test that keeps it in step (`docs/services.md`, part 8).
44
+ - **Found when the host is deployed, not when it is loaded.** A plugin is loaded when it is first used. One that cannot be loaded, or is tagged for a tool the host does not have, answers `Unavailable` and is logged; a skill file that cannot be read is left out and logged. Neither stops the host. `mcp-dispatch check` loads every plugin and returns 1 for each: a host runs it when it is deployed, and a package's own tests run `check.integrity`. What is known without loading a plugin still stops the start: a name that is no package's name, one name for two plugins, a host without a tool that only reads.
42
45
  - **The texts are the interface.** The guides, the tools' default descriptions, the help that `registry.py` prints, every error message and hint are read by an assistant that acts on them. A change to one is tried with fresh assistants before it is merged (`trials/README.md`), and judged against the text it replaces in the same batch.
43
46
  - **An error says what to do.** Every problem the check prints names the place and the change. Every `DispatchError` that can name the right call does.
44
47
  - **Core has two dependencies**, pydantic and fastembed. Import fastembed inside the model loader. `mcp` is an extra; import it inside the functions that need it.
@@ -52,6 +55,8 @@ A result object (text, tables, hints, what to store); storing what an action ret
52
55
 
53
56
  Specified and not built (`docs/services.md`): needs and providers, so that a plugin says what it needs and a host provides it; and the services on top, each a package of its own (one Postgres database with a schema for each module, secrets and settings, things and links, the index). It would answer points 2 and 3 below, and "one ranked list across packages" above.
54
57
 
58
+ Built from that specification on the branch `one-source` and not released: its part 8, one source for each fact, and the first step of its part 5, the store in memory that the search for guides now goes through (`CHANGELOG.md`, 0.3.0). The store in Postgres, the handle a plugin gets and the one ranked list across packages are not built.
59
+
55
60
  ## What a host like precis needs that is not here
56
61
 
57
62
  Read from the source of precis-mcp on 29 Nov 2026 (seven verbs over more than 50 kinds, more than 300 skills, plugins for handlers, job types, migrations, skills and commands) and tried against this library with a throwaway plugin. Its live server could not be reached, so nothing here was seen running there. What already carries over: an id that is a string, a number or a list of both; a dict argument, also sent as JSON text or from a shell; `dry_run` and `confirm` as plain arguments; an answer of any size.
@@ -82,9 +87,13 @@ Found by the passes that wrote the tests (28 Nov 2026) and left as they are; non
82
87
  - An `Example:` written as a list of one call (`{"calls": [{...}]}`) passes the check and is printed in help that way.
83
88
  - The skill search with `limit` 0 or below returns one guide; `best_skills(limit=0)` returns none.
84
89
  - `Dispatch.first_read` sizes each schema without the example path a host may give `server`, so it is a few characters low.
85
- - The guide says an action's arguments are keyword-only; `def go(self, call, thing: str)` registers all the same.
90
+ - What stands before the `*` of an action is the host's, handed over by name; what stands after it is an argument. An argument written before the `*` stops the registration when the docstring describes it, and is taken for the host's otherwise: a run finds that (`check.run_problems`), the check does not.
86
91
  - A `Note:` alone on its line above `Args:` takes the paragraphs after it out of help, up to the next section. The check names the section, so the author is told.
87
92
  - The two bars of the guide search (`_skill_meaning.py`) were set on one calibration set of 13 guides, 156 paraphrases and 40 unrelated searches, and tried on no other. A search for guides is answered by the guides above .47: the right one for 154 of 156 paraphrases, and 6 of 31 unrelated searches get guides where "No skill matches" was due. Beside other packages a guide is named above .62 and within .10 of the best, and only for a search of two words that are not stop words: the right one for 88 of 156, and for no unrelated search. A host with many guides, or guides that are much alike, may need other numbers.
88
93
  - A session of the trial runner leaves the client's own copy of the conversation under `~/.claude/projects/`, one directory per working directory of a run.
89
94
  - Tried by a host and not here: Reticula's trial kit (its `trials/`) ran 1,530 scenario runs over this library on 29 Nov 2026. What it found about the library's own texts: a tool called `search` draws the first call (the host guide now says so), and how-to guides are read far more often as skills than they were as notes of the host.
90
95
  - Not tried with assistants (`trials/README.md`): the host guide; the check's message for an example that is not JSON, which no run of round one came to see; every message added on 28 Nov 2026 by the two test passes; `mcp-dispatch call`.
96
+ - Not tried with assistants, from the branch `one-source` (1 Dec 2026): the refusal `[error:Unavailable] <package> cannot be loaded on this server` and its hint; the refusal `[error:Unavailable] <path> was written for another server: it needs <name>, which a call here does not have`; in the plugin guide, that nothing is generated from a skill file, the commands of section 5 without `update`, and what a tag for a missing tool does; in the host guide, when a plugin is loaded and what the check is for; the message for a `contract` that is still named in `[tool.mcp-dispatch]`. The plugin guide does not yet say that an action can be a plain function of a module (`Plugin.modules`), nor that what stands before its `*` is handed over by name, nor that a package's tests run every shown call once: whether the method form stays beside the function is open (`docs/services.md`, point 13).
97
+ - The store in memory (`index.py`) is the registry's and no guide names it. Taken by the builder and not ruled (`docs/services.md`, part 5, "Built"): piece 0 of a thing is its title and piece 1 the line a hit shows; the bar below which a match is noise is the store's, the .47 measured on guides, for every kind; a plugin can reach the store as `self.registry.index`, and nothing stops it from putting a person's text there (point 17). A search holds the store's lock while the model works, so a second search of that host waits for it.
98
+ - Over MCP a call is resolved on the event loop, so the first use of a plugin that is slow to import holds the server's other calls for as long as the import takes, once.
99
+ - A page of help names the skills that use an action and the kinds every package finds, so asking for any page loads every plugin. Only a call for a path loads one plugin alone. A search loads them all until there is a store that answers it (`docs/services.md`, part 5).
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (not released; the branch `one-source`)
4
+
5
+ One source for each fact (`docs/services.md`, part 8). This release breaks what 0.2 published.
6
+
7
+ - **An action can be a plain function.** A plugin class names modules, `modules = (handlers,)`, and every tagged function those modules define is an action. The registry holds the function itself, so a test that calls it runs what the dispatcher runs. Methods of the class are actions as before.
8
+ - **What stands before the `*` of an action is the host's, handed over by name.** A parameter called `call` gets the call itself, any other gets what the call holds under that name: `def put(call, *, text)`, `def put(conn, viewer, *, text)` and `def now(*, zone)` are one form. A test calls a function with just what it lists. A call that does not hold a name answers `[error:Unavailable] <path> was written for another server`. An argument written before the `*` and described in the docstring stops the registration; it used to register.
9
+ - **An action is looked up where it is defined at each call**, in its module or on its plugin, so a test that replaces a function there replaces the action.
10
+ - **A package's tests run every call that is shown to an assistant once**: `check.run_problems(dispatch, make)` and `integrity(..., call=make)` run the example of each action and each call a skill names, with what the test hands over. A call that its action refuses has reached its function; one that does not get there, or raises, is a problem.
11
+ - **Nothing is generated.** A host reads a plugin's skills from the skill files. Gone: `skills/index.json`, `mcp-dispatch update`, `skills_from` of `Registry`, `Dispatch` and `build_registry`, `check.update`. Delete the `index.json` files; nothing reads them.
12
+ - **Nothing is pinned.** Gone: `Registry.contract()`, `--contract`, and `contract` under `[tool.mcp-dispatch]`, which the command line refuses with what to do. What is lost: a default or a type that changes and that no test asserts.
13
+ - **A plugin is loaded when it is first used.** `find_plugins()` takes note of the entry points and loads nothing. A call or help for a path loads that package; `?`, a search, the skills and any page of help load them all, once.
14
+ - **A plugin that cannot be loaded no longer stops the host.** Calls for its paths answer `[error:Unavailable]`, the log has the reason, `Registry.unavailable` keeps it, and `mcp-dispatch check` returns 1 for it. Run the check when a host is deployed. `PluginError` is now raised only for what the entry points alone show: a name that is no package's name, one name for two plugins.
15
+ - **A skill file that cannot be read** is left out by a running host with a line in the log, and is a problem of the check.
16
+ - **The check walks as an assistant does**: `?`, the search, each package, each action, each argument, with every page of help made. `check.integrity({"shelf": Shelf})` is the same check for a package's own tests, with no host and nothing installed. `problems(dispatch, texts=...)` also checks the calls a host names in texts of its own.
17
+ - **The search for guides goes through a store in memory** (`mcp_dispatch.index`, `Registry.index`): `put`, `remove` and `search` over things of any kind, each with several pieces, by meaning or by words. The guides are its first kind (`docs/services.md`, part 5, the first step). Every answer of a search is as it was. A piece is embedded once, and again only when its text changes; a guide added later no longer has every guide embedded again. Gone, and never part of what a plugin imports: `skills.fits`, `_skill_meaning.SkillVectors`.
18
+ - **Fixed:** an argument whose type has no JSON schema (a `Callable`) registered, and help for its action then raised. It now stops the registration and is named.
19
+ - Not tried with assistants yet: the `Unavailable` refusal and the sentences of both guides that changed (`AGENTS.md`, "Known and open").
20
+
3
21
  ## 0.2.0 (29 Nov 2026)
4
22
 
5
23
  How-to guides are found by meaning, and `help` prints tables for a person.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mcp-dispatch
3
- Version: 0.2.0
3
+ Version: 0.3.0.dev1
4
4
  Summary: A few MCP tools with paths behind them: plugins publish actions and skills, help comes from signatures and docstrings, and a check keeps what an assistant reads in order.
5
5
  Project-URL: Homepage, https://github.com/retospect/mcp-dispatch
6
6
  Project-URL: Repository, https://github.com/retospect/mcp-dispatch
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "mcp-dispatch"
7
- version = "0.2.0"
7
+ version = "0.3.0.dev1"
8
8
  description = "A few MCP tools with paths behind them: plugins publish actions and skills, help comes from signatures and docstrings, and a check keeps what an assistant reads in order."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -29,7 +29,7 @@ from mcp_dispatch.tags import (
29
29
  standard_tools,
30
30
  )
31
31
 
32
- __version__ = "0.2.0"
32
+ __version__ = "0.3.0.dev1"
33
33
 
34
34
  __all__ = [
35
35
  "BAD_INPUT",
@@ -1,18 +1,12 @@
1
- """The process owns the model. Each registry owns its skill vectors."""
1
+ """The process owns the model. Each store in memory owns its vectors (index.py)."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
6
  from collections.abc import Callable
7
- from itertools import islice
8
- from math import sumprod
9
7
  from pathlib import Path
10
8
  from threading import Lock
11
9
  from time import monotonic
12
- from typing import TYPE_CHECKING
13
-
14
- if TYPE_CHECKING:
15
- from mcp_dispatch.skills import Skill
16
10
 
17
11
  _MODEL = "BAAI/bge-base-en-v1.5"
18
12
  _QUERY = "Represent this sentence for searching relevant passages: "
@@ -72,29 +66,22 @@ class _Runtime:
72
66
  _runtime = _Runtime()
73
67
 
74
68
 
75
- class SkillVectors:
76
- def __init__(self) -> None:
77
- self._skills: tuple[Skill, ...] = ()
78
- self._vectors: list[list[list[float]]] = []
79
-
80
- def scores(self, skills: tuple[Skill, ...], q: str) -> list[float] | None:
81
- with _runtime.lock:
82
- if monotonic() < _runtime.retry_at:
83
- return None
84
- try:
85
- if _runtime.embed is None:
86
- _runtime.embed = _load()
87
- if skills != self._skills:
88
- headers = [(s.title, s.summary, *s.answers) for s in skills]
89
- vectors = iter(_runtime.embed([t for h in headers for t in h]))
90
- self._vectors = [list(islice(vectors, len(h))) for h in headers]
91
- self._skills = skills
92
- (query,) = _runtime.embed([_QUERY + q])
93
- except Exception:
94
- # A missing file or an unusable ONNX session can first show
95
- # up during inference. Other registries share the retry wait.
96
- _runtime.embed = None
97
- _runtime.retry_at = monotonic() + _RETRY_SECONDS
98
- return None
99
- vectors_by_skill = self._vectors
100
- return [max(sumprod(query, v) for v in group) for group in vectors_by_skill]
69
+ def embedded(texts: list[str], q: str) -> tuple[list[list[float]], list[float]] | None:
70
+ """The vectors of ``texts`` and of the question ``q``, one caller at a
71
+ time. None while the model cannot be used: it is tried again after
72
+ ``_RETRY_SECONDS``, by every store of the process."""
73
+ with _runtime.lock:
74
+ if monotonic() < _runtime.retry_at:
75
+ return None
76
+ try:
77
+ if _runtime.embed is None:
78
+ _runtime.embed = _load()
79
+ vectors = _runtime.embed(texts) if texts else []
80
+ (query,) = _runtime.embed([_QUERY + q])
81
+ except Exception:
82
+ # A missing file or an unusable ONNX session can first show
83
+ # up during inference. Other registries share the retry wait.
84
+ _runtime.embed = None
85
+ _runtime.retry_at = monotonic() + _RETRY_SECONDS
86
+ return None
87
+ return vectors, query
@@ -25,7 +25,7 @@ if __name__ == "__main__":
25
25
  dependencies = ["mcp-dispatch[mcp]"]
26
26
 
27
27
  [tool.mcp-dispatch]
28
- host = "my_package.host:dispatch" # so that check, update and help look at this host
28
+ host = "my_package.host:dispatch" # so that check and help look at this host
29
29
  ```
30
30
 
31
31
  A project that has no host of its own and lists its plugins under another entry point group says so in the same table: `group = "my_host.plugins"`.
@@ -43,7 +43,7 @@ The first guide search loads `BAAI/bge-base-en-v1.5` and embeds the installed he
43
43
 
44
44
  ## The plugins
45
45
 
46
- `find_plugins()` adds every plugin installed under the entry point group (`Dispatch(group="my_host.plugins")` for a group of your own). `add("shelf", Shelf)` adds one class by hand. A plugin that cannot be loaded, or that is tagged for a tool you do not have, stops the start: a host that came up without it would answer "not installed" to calls that worked the day before.
46
+ `find_plugins()` takes note of every plugin installed under the entry point group (`Dispatch(group="my_host.plugins")` for a group of your own). `add("shelf", Shelf)` adds one class by hand. A plugin that was found is loaded when it is first used: at the first call or help for one of its paths, or when everything installed is asked for (`?`, a search, the skills). One that cannot be loaded then, or that is tagged for a tool you do not have, does not stop the host: calls for its paths are answered `[error:Unavailable]`, and the log has the reason. Run `uv run mcp-dispatch check` when you deploy the host: it loads every plugin and returns 1 when one cannot be loaded.
47
47
 
48
48
  ## What an assistant is told first
49
49
 
@@ -102,4 +102,4 @@ A value is passed as its text and read by the action's type hints. What the acti
102
102
  uv run mcp-dispatch check
103
103
  ```
104
104
 
105
- With `[tool.mcp-dispatch] host = ...` it checks this host: every plugin's docstrings, skills and index, and the size of the initial message. `contract = "tests/contract.json"` in the same table pins the paths and their arguments in a file: the check fails when they differ, and `uv run mcp-dispatch update` writes the file again after a change that is meant.
105
+ With `[tool.mcp-dispatch] host = ...` it checks this host: every plugin's docstrings and skills, and the size of the initial message. Nothing is pinned in a file: the paths and their arguments are what the functions say, and the tests that call them say what holds.
@@ -100,7 +100,7 @@ The tag names the tool the action is called through:
100
100
  | `DESTROY` | removes something for good |
101
101
  | `SHARE` | gives someone access, changes it or takes it away |
102
102
 
103
- The question for `DESTROY` and `SHARE` is "can it be undone?", not "does it delete?". A tag that names a tool the host does not have stops the host from starting.
103
+ The question for `DESTROY` and `SHARE` is "can it be undone?", not "does it delete?". A tag that names a tool the host does not have makes the whole package unavailable on that host; the check says so.
104
104
 
105
105
  The shape:
106
106
 
@@ -171,15 +171,14 @@ answers:
171
171
  - The header has `title` and `summary`, one line each, and `answers`: the questions the skill answers, at least one and better three to six, in the words of someone who does not know the answer yet. The search matches a question against these three, so they decide whether the skill is found.
172
172
  - No argument lists: the help has them. Say which calls, in which order, and why.
173
173
  - Write every example call as `<tool> {json}`, the JSON exactly as it is sent: each is read as JSON and checked against the signatures. A blank for the assistant to fill is a string, quotes included: `"book": "<the book's id>"`. A number or a yes/no has no blank: write a real value, `"count": 5`, and say in the sentence what it stands for. `"count": <how many>` is not JSON and fails the check.
174
- - After adding or changing a skill, run `uv run mcp-dispatch update`. It writes `skills/index.json`, which a running host reads in place of the files. Commit it. A host refuses to start when the index does not list the files that are there.
174
+ - Nothing is generated from a skill file and nothing is written beside it. A host reads the headers when it loads the package. A file it cannot read is left out there, and the check names it: run the check after adding or changing a skill.
175
175
 
176
176
  An assistant finds a skill with `search {"q": "lend a book", "t": "skill"}` and reads it with `get {"path": "skill/get", "name": "lend-a-book"}`.
177
177
 
178
- ## 5. Check, update, read it as the assistant will
178
+ ## 5. Check, read it as the assistant will
179
179
 
180
180
  ```
181
- uv run mcp-dispatch update # writes skills/index.json, then checks
182
- uv run mcp-dispatch check # checks only; run it in CI
181
+ uv run mcp-dispatch check # run it in CI too
183
182
  uv run mcp-dispatch help --exact shelf/ # what "shelf/?" answers: the actions
184
183
  uv run mcp-dispatch help --exact shelf/add # what "shelf/add?" answers
185
184
  ```
@@ -199,7 +198,7 @@ class Books: # stands in for what the host hands to every call
199
198
  return "b12"
200
199
 
201
200
 
202
- registry = Registry(skills_from="files")
201
+ registry = Registry()
203
202
  registry.register("shelf", Shelf)
204
203
  found = registry.resolve("create", {"path": "shelf/add", "title": "Dune"})
205
204
  assert isinstance(found, Bound)
@@ -214,7 +213,7 @@ from mcp_dispatch.check import problems
214
213
 
215
214
 
216
215
  def test_everything_an_assistant_reads_is_in_order():
217
- dispatch = Dispatch(skills_from="files") # the skill files, as the check reads them
216
+ dispatch = Dispatch()
218
217
  assert dispatch.find_plugins(), "no plugin was found: is its entry point listed?"
219
218
  assert problems(dispatch) == []
220
219
  ```
@@ -1,5 +1,5 @@
1
- """The check and the updater: what an assistant will read about a host's
2
- plugins is checked, not reviewed.
1
+ """The check: what an assistant will read about a host's plugins is checked,
2
+ not reviewed.
3
3
 
4
4
  ``problems(dispatch)`` returns one line per thing that is wrong, each saying
5
5
  what to change; an empty list means the plugins are fit to ship. Run it in CI
@@ -10,31 +10,55 @@ what to change; an empty list means the plugins are fit to ship. Run it in CI
10
10
  def test_the_plugins_are_documented():
11
11
  assert problems(my_dispatch) == []
12
12
 
13
- ``update(dispatch)`` writes what is generated: each plugin's
14
- ``skills/index.json`` and, when asked, the pinned contract.
13
+ A package's own tests hand over its plugin classes and need no host::
14
+
15
+ from mcp_dispatch.check import integrity
16
+
17
+ def test_the_package_is_fit_to_ship():
18
+ assert integrity({"shelf": Shelf}) == []
19
+
20
+ The check walks as an assistant does: it asks for ``?``, then the help of each
21
+ package, each action and each argument, and has every page made. It runs when
22
+ a package is released, as that test, and when a host is deployed, on what is
23
+ installed there (``mcp-dispatch check``). It runs no action: it has nothing to
24
+ hand to one, and where a host is deployed it must not write.
25
+
26
+ A package's tests do have something to hand over, and run every call that is
27
+ shown to an assistant once (``integrity(..., call=...)``,
28
+ :func:`run_problems`): the example of each action and each call a skill
29
+ names. That is where a function that asks its host for a thing the host does
30
+ not have is found.
31
+
32
+ Nothing is generated and nothing is pinned in a file: the check reads the
33
+ functions and the skill files that a running host reads.
15
34
  """
16
35
 
17
36
  from __future__ import annotations
18
37
 
19
38
  import inspect
20
39
  import json
21
- import shlex
22
- from pathlib import Path
40
+ from collections.abc import Callable, Iterator, Mapping, Sequence
41
+ from contextlib import contextmanager
23
42
  from typing import Any
24
43
 
25
44
  from mcp_dispatch import skills as skill_files
26
45
  from mcp_dispatch.dispatch import Dispatch
27
- from mcp_dispatch.errors import DispatchError
46
+ from mcp_dispatch.errors import UNAVAILABLE, DispatchError
28
47
  from mcp_dispatch.registry import (
29
48
  KIND_KEY,
49
+ PATH_KEY,
50
+ SEARCH_PATH,
30
51
  SKILL_PACKAGE,
31
52
  Action,
32
53
  Bound,
54
+ Help,
33
55
  Package,
34
56
  Param,
35
57
  Registry,
58
+ sorted_by_name,
36
59
  )
37
- from mcp_dispatch.skills import INDEX, UPDATE, Skill
60
+ from mcp_dispatch.skills import Skill
61
+ from mcp_dispatch.tags import Plugin, Tool
38
62
 
39
63
  MAX_SUMMARY = 100 # characters of a docstring's first line (its first paragraph)
40
64
  MAX_DOC = 2000 # characters of one action's docstring
@@ -166,8 +190,7 @@ def _scanned(registry: Registry, package: Package) -> tuple[list[Skill], list[st
166
190
 
167
191
 
168
192
  def skill_problems(registry: Registry, package: Package) -> list[str]:
169
- """What is wrong with a package's skills: a header, an example call, or
170
- an index that does not say what the headers say."""
193
+ """What is wrong with a package's skills: a header or an example call."""
171
194
  if package.skills_dir is None:
172
195
  return []
173
196
  skills, out = _scanned(registry, package)
@@ -187,22 +210,79 @@ def skill_problems(registry: Registry, package: Package) -> list[str]:
187
210
  f"{where}: {_shown(tool, arguments)} asks for help; an"
188
211
  " example in a skill is a call that does something"
189
212
  )
190
- index = package.skills_dir / INDEX
191
- if not out:
192
- if not index.is_file():
193
- if skills:
194
- out.append(f"{package.name}: skills/{INDEX} is missing; {UPDATE}")
195
- elif index.read_text(encoding="utf-8") != skill_files.index_text(skills):
196
- out.append(f"{package.name}: skills/{INDEX} is out of date; {UPDATE}")
197
213
  return out
198
214
 
199
215
 
200
- def problems(dispatch: Dispatch, *, contract: Path | None = None) -> list[str]:
216
+ def help_paths(registry: Registry) -> list[str]:
217
+ """Every path an assistant can ask help for, without its question mark,
218
+ from the top down: everything installed, the search, each package, each
219
+ of its actions, each of their arguments."""
220
+ paths = [""]
221
+ if registry.searchers():
222
+ paths.append(SEARCH_PATH)
223
+ for package in sorted_by_name(registry.packages):
224
+ paths.append(f"{package.name}/")
225
+ for action in sorted_by_name(package.actions):
226
+ paths.append(action.path)
227
+ paths += [f"{action.path}/{p.name}" for p in action.params]
228
+ return paths
229
+
230
+
231
+ def walk(registry: Registry) -> list[str]:
232
+ """Ask for help as an assistant does, page by page, and say which page is
233
+ not answered. Every page is made: one that cannot be would otherwise be
234
+ found by the assistant that asks for it."""
235
+ out = []
236
+ for path in help_paths(registry):
237
+ arguments = {PATH_KEY: f"{path}?"}
238
+ asked = _shown(registry.read_tool, arguments)
239
+ try:
240
+ found = registry.resolve(registry.read_tool, arguments)
241
+ except DispatchError as exc:
242
+ out.append(f"{asked} is refused: {exc.message}")
243
+ continue
244
+ except Exception as exc:
245
+ out.append(f"{asked} cannot be answered: {type(exc).__name__}: {exc}")
246
+ continue
247
+ if not isinstance(found, Help) or not found.text.strip():
248
+ out.append(f"{asked} is answered with no help")
249
+ return out
250
+
251
+
252
+ def text_problems(registry: Registry, texts: Mapping[str, str]) -> list[str]:
253
+ """What is wrong with the calls a host names in texts of its own (what it
254
+ tells a client first, an instruction it ships): each ``<tool> {json}`` in
255
+ them is a call that is accepted, or help. ``texts`` is each text by what
256
+ it is called in a problem's line."""
257
+ out = []
258
+ for name, text in texts.items():
259
+ try:
260
+ calls = list(registry.example_calls(text))
261
+ except ValueError as exc:
262
+ out.append(f"{name}: {exc}")
263
+ continue
264
+ for tool, arguments in calls:
265
+ try:
266
+ registry.resolve(tool, arguments)
267
+ except DispatchError as exc:
268
+ out.append(
269
+ f"{name}: {_shown(tool, arguments)} is not a call that is"
270
+ f" accepted: {exc.message}"
271
+ )
272
+ return out
273
+
274
+
275
+ def problems(
276
+ dispatch: Dispatch, *, texts: Mapping[str, str] | None = None
277
+ ) -> list[str]:
201
278
  """Everything that is wrong with what a host's plugins show an assistant,
202
- one line each; empty when nothing is."""
279
+ one line each; empty when nothing is. ``texts`` are texts of the host's
280
+ own that name calls (see :func:`text_problems`)."""
203
281
  registry = dispatch.registry
204
- out = []
205
- for package in registry.packages.values():
282
+ packages = registry.packages # asking for them loads every one
283
+ # a plugin that cannot be loaded: nothing of it can be checked
284
+ out = [registry.unavailable[name] for name in sorted(registry.unavailable)]
285
+ for package in packages.values():
206
286
  if not package.doc.summary:
207
287
  out.append(
208
288
  f"{package.name}: the plugin class needs a docstring whose first"
@@ -214,30 +294,128 @@ def problems(dispatch: Dispatch, *, contract: Path | None = None) -> list[str]:
214
294
  for action in sorted(published, key=lambda a: a.name):
215
295
  out += action_problems(registry, action)
216
296
  out += skill_problems(registry, package)
297
+ out += walk(registry)
217
298
  try:
218
299
  dispatch.initial_message # noqa: B018 (raises when it is too long)
219
300
  except ValueError as exc:
220
301
  out.append(str(exc))
221
- if contract is not None:
222
- # the command that writes this file, whether it was named by the
223
- # project's settings or by --contract
224
- write = f"run `mcp-dispatch update --contract {shlex.quote(str(contract))}`"
225
- if not contract.is_file():
226
- out.append(f"the pinned contract {contract} is missing; {write}")
227
- else:
228
- try:
229
- pinned = json.loads(contract.read_text(encoding="utf-8"))
230
- except ValueError as exc:
231
- out.append(
232
- f"the pinned contract {contract} cannot be read ({exc!r}); {write}"
233
- )
234
- else:
235
- if pinned != _plain(registry.contract()):
236
- out.append(
237
- f"the paths or their arguments differ from the pinned contract"
238
- f" {contract}. If the change is meant, {write}; callers will"
239
- " have to follow it"
240
- )
302
+ out += text_problems(registry, texts or {})
303
+ return out
304
+
305
+
306
+ #: what a test hands to :func:`run_problems`: a function without arguments,
307
+ #: called once for every call that is run. What it returns is handed to the
308
+ #: action; a context manager is entered for that one call and left after it
309
+ Make = Callable[[], Any]
310
+ _NO_CALL: Any = object()
311
+
312
+
313
+ @contextmanager
314
+ def _made(make: Make) -> Iterator[Any]:
315
+ handed = make()
316
+ if hasattr(handed, "__enter__") and hasattr(handed, "__exit__"):
317
+ with handed as inside:
318
+ yield inside
319
+ else:
320
+ yield handed
321
+
322
+
323
+ def shown_calls(registry: Registry) -> list[tuple[str, str, dict[str, Any]]]:
324
+ """Every call that is shown to an assistant, once, with where it stands:
325
+ the example of each action and of each package's search, then each call a
326
+ skill names. One that cannot be read as a call is left out: the check
327
+ names it."""
328
+ found: list[tuple[str, str, dict[str, Any]]] = []
329
+ seen = set()
330
+
331
+ def take(where: str, text: str) -> None:
332
+ try:
333
+ calls = list(registry.example_calls(text))
334
+ except ValueError:
335
+ return
336
+ for tool, arguments in calls:
337
+ key = _shown(tool, arguments)
338
+ if key not in seen:
339
+ seen.add(key)
340
+ found.append((where, tool, arguments))
341
+
342
+ for package in sorted_by_name(registry.packages):
343
+ published = sorted_by_name(package.actions)
344
+ if package.search is not None:
345
+ published.append(package.search)
346
+ for action in published:
347
+ take(_where(action), action.doc.example)
348
+ for skill in registry.skills.values():
349
+ take(f"{skill.package}: skills/{skill.file.name}", skill.text)
350
+ return found
351
+
352
+
353
+ def run_problems(
354
+ dispatch: Dispatch,
355
+ make: Make,
356
+ *,
357
+ refusals: tuple[type[BaseException], ...] = (),
358
+ ) -> list[str]:
359
+ """Run every call that is shown to an assistant once, and say which does
360
+ not get as far as its function, or raises there.
361
+
362
+ ``make`` gives what the host hands to a call (see :data:`Make`): a test
363
+ opens a transaction there and rolls it back, so that nothing a call
364
+ writes is kept. A call may be refused by its action: a blank such as
365
+ ``"<the book's id>"`` names nothing that is there, and the refusal shows
366
+ that the function was reached, which is what is asked here. ``refusals``
367
+ are the host's own exceptions that are refusals, beside ``DispatchError``.
368
+ """
369
+ registry = dispatch.registry
370
+ out = []
371
+ for where, tool, arguments in shown_calls(registry):
372
+ shown = _shown(tool, arguments)
373
+ try:
374
+ found = registry.resolve(tool, arguments)
375
+ except DispatchError:
376
+ continue # not a call that is accepted: the check says so
377
+ if not isinstance(found, Bound):
378
+ continue
379
+ try:
380
+ with _made(make) as call:
381
+ found.run(call)
382
+ except DispatchError as exc:
383
+ if exc.code == UNAVAILABLE:
384
+ out.append(f"{where}: {shown} cannot be run: {exc.message}")
385
+ except refusals:
386
+ pass
387
+ except Exception as exc:
388
+ out.append(f"{where}: {shown} raised {type(exc).__name__}: {exc}")
389
+ return out
390
+
391
+
392
+ def integrity(
393
+ plugins: Mapping[str, type[Plugin]],
394
+ *,
395
+ tools: Sequence[Tool] | None = None,
396
+ texts: Mapping[str, str] | None = None,
397
+ call: Make = _NO_CALL,
398
+ refusals: tuple[type[BaseException], ...] = (),
399
+ ) -> list[str]:
400
+ """The check for a package's own tests: its plugin classes by the names
401
+ they are installed under, on a host with the standard tools, or with
402
+ ``tools`` where they are written for a host with tools of its own. No
403
+ entry point is looked up and nothing has to be installed.
404
+
405
+ With ``call``, every call that is shown to an assistant is also run once
406
+ (:func:`run_problems`): give a function that returns what the host hands
407
+ to a call, ``call=lambda: store``."""
408
+ if not plugins:
409
+ raise ValueError(
410
+ "no plugin was handed over, so nothing would be checked:"
411
+ ' integrity({"<package>": <the plugin class>})'
412
+ )
413
+ dispatch = Dispatch(tools, skill_search="words")
414
+ for name, plugin in plugins.items():
415
+ dispatch.add(name, plugin)
416
+ out = problems(dispatch, texts=texts)
417
+ if call is not _NO_CALL:
418
+ out += run_problems(dispatch, call, refusals=refusals)
241
419
  return out
242
420
 
243
421
 
@@ -257,10 +435,6 @@ def nothing_found(dispatch: Dispatch) -> str:
257
435
  )
258
436
 
259
437
 
260
- def _plain(value: Any) -> Any:
261
- return json.loads(json.dumps(value))
262
-
263
-
264
438
  def summary(dispatch: Dispatch) -> str:
265
439
  """One line on what was checked and how much is read before a first call."""
266
440
  registry = dispatch.registry
@@ -280,31 +454,3 @@ def summary(dispatch: Dispatch) -> str:
280
454
 
281
455
  def _count(n: int, what: str) -> str:
282
456
  return f"{n} {what}" if n == 1 else f"{n} {what}s"
283
-
284
-
285
- def update(dispatch: Dispatch, *, contract: Path | None = None) -> list[str]:
286
- """Write what is generated and say what was written. A skill that cannot
287
- be read stops it: ``ValueError`` with what is wrong."""
288
- registry = dispatch.registry
289
- wrong, done = [], []
290
- todo: list[tuple[Path, str]] = []
291
- for package in registry.packages.values():
292
- if package.skills_dir is None:
293
- continue
294
- skills, bad = _scanned(registry, package)
295
- wrong += bad
296
- if skills or (package.skills_dir / INDEX).exists():
297
- todo.append((package.skills_dir / INDEX, skill_files.index_text(skills)))
298
- if wrong:
299
- raise ValueError("\n".join(wrong))
300
- if contract is not None:
301
- text = json.dumps(registry.contract(), indent=1, ensure_ascii=False) + "\n"
302
- todo.append((contract, text))
303
- for file, text in todo:
304
- if file.is_file() and file.read_text(encoding="utf-8") == text:
305
- done.append(f"unchanged {file}")
306
- else:
307
- file.parent.mkdir(parents=True, exist_ok=True)
308
- file.write_text(text, encoding="utf-8")
309
- done.append(f"wrote {file}")
310
- return done