mcp-dispatch 0.1.1__py3-none-any.whl
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.
- mcp_dispatch/__init__.py +59 -0
- mcp_dispatch/__main__.py +3 -0
- mcp_dispatch/agent_instructions/host.md +102 -0
- mcp_dispatch/agent_instructions/plugin.md +222 -0
- mcp_dispatch/check.py +310 -0
- mcp_dispatch/cli.py +276 -0
- mcp_dispatch/command.py +121 -0
- mcp_dispatch/dispatch.py +208 -0
- mcp_dispatch/docs.py +100 -0
- mcp_dispatch/errors.py +32 -0
- mcp_dispatch/lenient.py +172 -0
- mcp_dispatch/mcp_tools.py +195 -0
- mcp_dispatch/py.typed +0 -0
- mcp_dispatch/registry.py +972 -0
- mcp_dispatch/skills.py +533 -0
- mcp_dispatch/tags.py +173 -0
- mcp_dispatch/trials.py +380 -0
- mcp_dispatch-0.1.1.dist-info/METADATA +86 -0
- mcp_dispatch-0.1.1.dist-info/RECORD +22 -0
- mcp_dispatch-0.1.1.dist-info/WHEEL +4 -0
- mcp_dispatch-0.1.1.dist-info/entry_points.txt +2 -0
- mcp_dispatch-0.1.1.dist-info/licenses/LICENSE +21 -0
mcp_dispatch/trials.py
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"""Run an assistant that has never seen a project against it, and keep what
|
|
2
|
+
it did.
|
|
3
|
+
|
|
4
|
+
One run is one headless Claude Code session (``claude -p``) with none of the
|
|
5
|
+
machine's own settings, instructions, hooks or MCP servers. What it is told
|
|
6
|
+
and which tools it has is passed in: the file tools and a shell for an
|
|
7
|
+
assistant that writes code, or the tools of one MCP server and nothing else
|
|
8
|
+
for an assistant that uses a host. The raw transcript is kept; the counts
|
|
9
|
+
are read from it, never from what the assistant said.
|
|
10
|
+
|
|
11
|
+
from mcp_dispatch.trials import Session, run_session, store
|
|
12
|
+
|
|
13
|
+
A kit (a project's own scenarios, starting state and judge) builds on this.
|
|
14
|
+
A text that an assistant reads before it acts is tried here before it ships:
|
|
15
|
+
the arms of a comparison run interleaved in one batch, because the same text
|
|
16
|
+
gives different counts at different hours.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import contextlib
|
|
22
|
+
import hashlib
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import signal
|
|
26
|
+
import subprocess
|
|
27
|
+
import tempfile
|
|
28
|
+
import threading
|
|
29
|
+
import time
|
|
30
|
+
from collections.abc import Mapping, Sequence
|
|
31
|
+
from dataclasses import asdict, dataclass, field
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
from typing import Any
|
|
34
|
+
|
|
35
|
+
#: commands a session with a shell may run without a person there to approve them
|
|
36
|
+
SHELL = (
|
|
37
|
+
"uv", "ls", "cat", "head", "tail", "wc", "find", "grep", "rg", "sed", "mkdir",
|
|
38
|
+
"touch", "cp", "mv", "pwd", "cd", "echo", "python", "python3", "git status",
|
|
39
|
+
"git diff", "tree", "which",
|
|
40
|
+
) # fmt: skip
|
|
41
|
+
FILE_TOOLS = ("Read", "Write", "Edit", "Glob", "Grep")
|
|
42
|
+
#: the tools of a session that writes code
|
|
43
|
+
CODING = ("Bash", *FILE_TOOLS)
|
|
44
|
+
_MCP = "mcp__"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class ToolCall:
|
|
49
|
+
name: str
|
|
50
|
+
input: dict[str, Any]
|
|
51
|
+
output: str = ""
|
|
52
|
+
error: bool = False
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def command(self) -> str:
|
|
56
|
+
"""The shell command of a Bash call; empty for any other tool."""
|
|
57
|
+
return str(self.input.get("command", "")) if self.name == "Bash" else ""
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def tool(self) -> str:
|
|
61
|
+
"""The tool's own name: for a tool of an MCP server, without the
|
|
62
|
+
client's prefix (``mcp__<server>__``)."""
|
|
63
|
+
if self.name.startswith(_MCP):
|
|
64
|
+
return self.name[len(_MCP) :].partition("__")[2]
|
|
65
|
+
return self.name
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def refused(self) -> bool:
|
|
69
|
+
"""The host answered with a refusal (``[error:Code] ...``)."""
|
|
70
|
+
return self.output.lstrip().startswith("[error:")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class Session:
|
|
75
|
+
"""What one run did, read from its transcript."""
|
|
76
|
+
|
|
77
|
+
model: str = ""
|
|
78
|
+
client: str = ""
|
|
79
|
+
id: str = "" # to go on with the same conversation (``resume``)
|
|
80
|
+
calls: list[ToolCall] = field(default_factory=list)
|
|
81
|
+
said: list[str] = field(default_factory=list) # the assistant's own text
|
|
82
|
+
result: str = "" # its last message
|
|
83
|
+
turns: int = 0
|
|
84
|
+
cost_usd: float = 0.0
|
|
85
|
+
seconds: float = 0.0
|
|
86
|
+
tokens_in: int = 0
|
|
87
|
+
tokens_out: int = 0
|
|
88
|
+
ended: str = "" # "success", "stopped" (by ``stop_after``), or why not
|
|
89
|
+
exit_code: int = 0
|
|
90
|
+
|
|
91
|
+
def commands(self) -> list[ToolCall]:
|
|
92
|
+
return [c for c in self.calls if c.name == "Bash"]
|
|
93
|
+
|
|
94
|
+
def served(self) -> list[ToolCall]:
|
|
95
|
+
"""The calls that went to an MCP server, in order."""
|
|
96
|
+
return [c for c in self.calls if c.name.startswith(_MCP)]
|
|
97
|
+
|
|
98
|
+
def denied(self) -> list[ToolCall]:
|
|
99
|
+
"""Calls the client refused because nobody was there to approve them."""
|
|
100
|
+
marks = ("requires approval", "permission", "not allowed", "was blocked")
|
|
101
|
+
return [c for c in self.calls if c.error and any(m in c.output for m in marks)]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def clean_env() -> dict[str, str]:
|
|
105
|
+
"""The environment for a run: this one without the virtual environment
|
|
106
|
+
the kit itself runs in, which would otherwise show up in every `uv`
|
|
107
|
+
command of the session as a warning that names the kit's project."""
|
|
108
|
+
return {k: v for k, v in os.environ.items() if k != "VIRTUAL_ENV"}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _text(content: Any) -> str:
|
|
112
|
+
if isinstance(content, str):
|
|
113
|
+
return content
|
|
114
|
+
if isinstance(content, list):
|
|
115
|
+
return "\n".join(
|
|
116
|
+
part.get("text", "") for part in content if isinstance(part, dict)
|
|
117
|
+
)
|
|
118
|
+
return ""
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _tokens(usage: Mapping[str, Any]) -> tuple[int, int]:
|
|
122
|
+
read = (
|
|
123
|
+
usage.get("input_tokens", 0)
|
|
124
|
+
+ usage.get("cache_creation_input_tokens", 0)
|
|
125
|
+
+ usage.get("cache_read_input_tokens", 0)
|
|
126
|
+
)
|
|
127
|
+
return read, usage.get("output_tokens", 0)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def read_transcript(lines: Sequence[str]) -> Session:
|
|
131
|
+
"""A session from the lines of ``--output-format stream-json``."""
|
|
132
|
+
session = Session()
|
|
133
|
+
by_id: dict[str, ToolCall] = {}
|
|
134
|
+
seen = [0, 0] # tokens by the assistant's messages, where no result came
|
|
135
|
+
for line in lines:
|
|
136
|
+
try:
|
|
137
|
+
event = json.loads(line)
|
|
138
|
+
except json.JSONDecodeError:
|
|
139
|
+
continue
|
|
140
|
+
if not isinstance(event, dict):
|
|
141
|
+
continue
|
|
142
|
+
kind = event.get("type")
|
|
143
|
+
if kind == "system" and event.get("subtype") == "init":
|
|
144
|
+
session.model = event.get("model", "")
|
|
145
|
+
session.client = event.get("claude_code_version", "")
|
|
146
|
+
session.id = event.get("session_id", "")
|
|
147
|
+
elif kind == "assistant":
|
|
148
|
+
message = event.get("message", {})
|
|
149
|
+
read, written = _tokens(message.get("usage") or {})
|
|
150
|
+
seen = [seen[0] + read, seen[1] + written]
|
|
151
|
+
for part in message.get("content", []):
|
|
152
|
+
if part.get("type") == "text" and part.get("text", "").strip():
|
|
153
|
+
session.said.append(part["text"])
|
|
154
|
+
elif part.get("type") == "tool_use":
|
|
155
|
+
call = ToolCall(part.get("name", ""), part.get("input") or {})
|
|
156
|
+
by_id[part.get("id", "")] = call
|
|
157
|
+
session.calls.append(call)
|
|
158
|
+
elif kind == "user":
|
|
159
|
+
content = event.get("message", {}).get("content", [])
|
|
160
|
+
for part in content if isinstance(content, list) else []:
|
|
161
|
+
if part.get("type") == "tool_result":
|
|
162
|
+
found = by_id.get(part.get("tool_use_id", ""))
|
|
163
|
+
if found is not None:
|
|
164
|
+
found.output = _text(part.get("content"))
|
|
165
|
+
found.error = bool(part.get("is_error"))
|
|
166
|
+
elif kind == "result":
|
|
167
|
+
session.result = event.get("result") or ""
|
|
168
|
+
session.turns = event.get("num_turns", 0)
|
|
169
|
+
session.cost_usd = event.get("total_cost_usd", 0.0) or 0.0
|
|
170
|
+
session.seconds = (event.get("duration_ms", 0) or 0) / 1000
|
|
171
|
+
session.tokens_in, session.tokens_out = _tokens(event.get("usage") or {})
|
|
172
|
+
session.ended = event.get("subtype", "")
|
|
173
|
+
session.id = event.get("session_id", "") or session.id
|
|
174
|
+
elif kind == "stopped":
|
|
175
|
+
session.ended = "stopped"
|
|
176
|
+
elif kind == "timeout":
|
|
177
|
+
session.ended = "timeout"
|
|
178
|
+
if not session.tokens_in and not session.tokens_out:
|
|
179
|
+
session.tokens_in, session.tokens_out = seen
|
|
180
|
+
return session
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def command(
|
|
184
|
+
prompt: str,
|
|
185
|
+
*,
|
|
186
|
+
model: str,
|
|
187
|
+
told: str = "",
|
|
188
|
+
system: str | None = None,
|
|
189
|
+
tools: Sequence[str] = CODING,
|
|
190
|
+
shell: Sequence[str] = SHELL,
|
|
191
|
+
mcp_config: Path | None = None,
|
|
192
|
+
servers: Sequence[str] = (),
|
|
193
|
+
resume: str | None = None,
|
|
194
|
+
max_usd: float = 2.0,
|
|
195
|
+
) -> list[str]:
|
|
196
|
+
"""The command line of one session; see :func:`run_session`."""
|
|
197
|
+
allowed = [t for t in tools if t != "Bash"]
|
|
198
|
+
if "Bash" in tools:
|
|
199
|
+
allowed += [f"Bash({one}:*)" for one in shell]
|
|
200
|
+
allowed += [f"{_MCP}{server}__*" for server in servers]
|
|
201
|
+
words = [
|
|
202
|
+
"claude", "-p", prompt,
|
|
203
|
+
"--model", model,
|
|
204
|
+
"--strict-mcp-config", "--setting-sources", "",
|
|
205
|
+
"--tools", ",".join(tools),
|
|
206
|
+
"--allowedTools", *allowed,
|
|
207
|
+
"--max-budget-usd", f"{max_usd:.2f}",
|
|
208
|
+
"--output-format", "stream-json", "--verbose",
|
|
209
|
+
] # fmt: skip
|
|
210
|
+
if mcp_config is not None:
|
|
211
|
+
words += ["--mcp-config", str(mcp_config)]
|
|
212
|
+
else:
|
|
213
|
+
# everything of the machine's own switched off; it would switch off
|
|
214
|
+
# the servers a session is given, too
|
|
215
|
+
words.append("--safe-mode")
|
|
216
|
+
if system is not None:
|
|
217
|
+
words += ["--system-prompt", system]
|
|
218
|
+
if told:
|
|
219
|
+
words += ["--append-system-prompt", told]
|
|
220
|
+
if resume:
|
|
221
|
+
words += ["--resume", resume]
|
|
222
|
+
return words
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def run_session(
|
|
226
|
+
prompt: str,
|
|
227
|
+
cwd: Path,
|
|
228
|
+
transcript: Path,
|
|
229
|
+
*,
|
|
230
|
+
model: str,
|
|
231
|
+
told: str = "",
|
|
232
|
+
system: str | None = None,
|
|
233
|
+
tools: Sequence[str] = CODING,
|
|
234
|
+
shell: Sequence[str] = SHELL,
|
|
235
|
+
mcp: Mapping[str, Mapping[str, Any]] | None = None,
|
|
236
|
+
resume: str | None = None,
|
|
237
|
+
stop_after: int | None = None,
|
|
238
|
+
max_usd: float = 2.0,
|
|
239
|
+
timeout: int = 1200,
|
|
240
|
+
) -> Session:
|
|
241
|
+
"""One headless session in ``cwd``; its transcript is written to
|
|
242
|
+
``transcript``.
|
|
243
|
+
|
|
244
|
+
``told`` is what the project tells an assistant (its AGENTS.md), added to
|
|
245
|
+
the client's own system prompt; ``system`` replaces that prompt, for an
|
|
246
|
+
assistant in a chat application. ``tools`` are the client's own tools the
|
|
247
|
+
session has: by default the file tools and the commands of ``shell``;
|
|
248
|
+
``()`` for none. ``mcp`` are the MCP servers it is connected to, by name,
|
|
249
|
+
each as the client's configuration writes it, e.g. ``{"notes": {"type":
|
|
250
|
+
"http", "url": "http://127.0.0.1:8787/mcp", "headers": {"Authorization":
|
|
251
|
+
"Bearer ..."}}}``; every tool of theirs may be called. ``resume`` is the
|
|
252
|
+
``id`` of an earlier session: the prompt is then the next turn of that
|
|
253
|
+
conversation. ``stop_after`` ends the session once that many tool calls
|
|
254
|
+
were answered, to see what an assistant does first without paying for
|
|
255
|
+
the rest.
|
|
256
|
+
"""
|
|
257
|
+
config = None
|
|
258
|
+
if mcp:
|
|
259
|
+
handle, name = tempfile.mkstemp(prefix="mcp-", suffix=".json")
|
|
260
|
+
with os.fdopen(handle, "w", encoding="utf-8") as out:
|
|
261
|
+
json.dump({"mcpServers": dict(mcp)}, out)
|
|
262
|
+
config = Path(name)
|
|
263
|
+
words = command(
|
|
264
|
+
prompt,
|
|
265
|
+
model=model,
|
|
266
|
+
told=told,
|
|
267
|
+
system=system,
|
|
268
|
+
tools=tools,
|
|
269
|
+
shell=shell,
|
|
270
|
+
mcp_config=config,
|
|
271
|
+
servers=tuple(mcp or ()),
|
|
272
|
+
resume=resume,
|
|
273
|
+
max_usd=max_usd,
|
|
274
|
+
)
|
|
275
|
+
started = time.monotonic()
|
|
276
|
+
lines: list[str] = []
|
|
277
|
+
late = False
|
|
278
|
+
try:
|
|
279
|
+
process = subprocess.Popen(
|
|
280
|
+
words,
|
|
281
|
+
cwd=cwd,
|
|
282
|
+
stdin=subprocess.DEVNULL,
|
|
283
|
+
stdout=subprocess.PIPE,
|
|
284
|
+
stderr=subprocess.PIPE,
|
|
285
|
+
text=True,
|
|
286
|
+
env=clean_env(),
|
|
287
|
+
# a group of its own, so that ending it ends what it started too
|
|
288
|
+
start_new_session=True,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
def end(how: int) -> None:
|
|
292
|
+
with contextlib.suppress(ProcessLookupError, PermissionError):
|
|
293
|
+
os.killpg(process.pid, how)
|
|
294
|
+
|
|
295
|
+
errors: list[str] = []
|
|
296
|
+
assert process.stdout is not None and process.stderr is not None
|
|
297
|
+
stderr = process.stderr
|
|
298
|
+
reader = threading.Thread(
|
|
299
|
+
target=lambda: errors.append(stderr.read()), daemon=True
|
|
300
|
+
)
|
|
301
|
+
reader.start()
|
|
302
|
+
watchdog = threading.Timer(timeout, end, (signal.SIGKILL,))
|
|
303
|
+
watchdog.start()
|
|
304
|
+
answered = 0
|
|
305
|
+
try:
|
|
306
|
+
for line in process.stdout:
|
|
307
|
+
lines.append(line.rstrip("\n"))
|
|
308
|
+
if stop_after is None or '"tool_result"' not in line:
|
|
309
|
+
continue
|
|
310
|
+
answered += line.count('"type":"tool_result"') or 1
|
|
311
|
+
if answered >= stop_after:
|
|
312
|
+
end(signal.SIGTERM)
|
|
313
|
+
lines.append(json.dumps({"type": "stopped", "after": answered}))
|
|
314
|
+
break
|
|
315
|
+
code = process.wait()
|
|
316
|
+
finally:
|
|
317
|
+
late = not watchdog.is_alive() and watchdog.finished.is_set()
|
|
318
|
+
watchdog.cancel()
|
|
319
|
+
reader.join(timeout=5)
|
|
320
|
+
if errors and errors[0].strip():
|
|
321
|
+
lines.append(json.dumps({"type": "stderr", "text": errors[0][-4000:]}))
|
|
322
|
+
if late and code != 0 and not any('"type":"stopped"' in x for x in lines[-1:]):
|
|
323
|
+
lines.append(json.dumps({"type": "timeout", "seconds": timeout}))
|
|
324
|
+
code = -1
|
|
325
|
+
finally:
|
|
326
|
+
if config is not None:
|
|
327
|
+
config.unlink(missing_ok=True)
|
|
328
|
+
transcript.parent.mkdir(parents=True, exist_ok=True)
|
|
329
|
+
transcript.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
330
|
+
session = read_transcript(lines)
|
|
331
|
+
session.exit_code = code
|
|
332
|
+
if not session.seconds:
|
|
333
|
+
session.seconds = time.monotonic() - started
|
|
334
|
+
return session
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def texts_hash(*texts: Path | str) -> str:
|
|
338
|
+
"""One short hash for the texts a run was given, so that runs on the same
|
|
339
|
+
texts can be put together and runs on changed texts told apart. A
|
|
340
|
+
``Path`` stands for the file's content."""
|
|
341
|
+
digest = hashlib.sha256()
|
|
342
|
+
for text in texts:
|
|
343
|
+
digest.update(
|
|
344
|
+
text.read_bytes() if isinstance(text, Path) else text.encode("utf-8")
|
|
345
|
+
)
|
|
346
|
+
return digest.hexdigest()[:12]
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def commit(repo: Path) -> str:
|
|
350
|
+
"""The commit a run was made at, with ``+`` when the tree had changes."""
|
|
351
|
+
|
|
352
|
+
def git(*args: str) -> str:
|
|
353
|
+
done = subprocess.run(
|
|
354
|
+
["git", "-C", str(repo), *args], capture_output=True, text=True
|
|
355
|
+
)
|
|
356
|
+
return done.stdout.strip()
|
|
357
|
+
|
|
358
|
+
head = git("rev-parse", "--short", "HEAD") or "none"
|
|
359
|
+
return head + ("+" if git("status", "--porcelain") else "")
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def store(file: Path, row: Mapping[str, Any]) -> None:
|
|
363
|
+
"""Add one run's row to a file of rows (JSON lines)."""
|
|
364
|
+
file.parent.mkdir(parents=True, exist_ok=True)
|
|
365
|
+
with file.open("a", encoding="utf-8") as out:
|
|
366
|
+
out.write(json.dumps(row, ensure_ascii=False) + "\n")
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def counts(session: Session) -> dict[str, Any]:
|
|
370
|
+
"""What every kit stores about a session."""
|
|
371
|
+
row = asdict(session)
|
|
372
|
+
for key in ("calls", "said", "result", "id"):
|
|
373
|
+
row.pop(key)
|
|
374
|
+
row["tool_calls"] = len(session.calls)
|
|
375
|
+
row["tool_errors"] = len([c for c in session.calls if c.error])
|
|
376
|
+
row["refused"] = len([c for c in session.calls if c.refused])
|
|
377
|
+
row["denied"] = len(session.denied())
|
|
378
|
+
row["cost_usd"] = round(session.cost_usd, 4)
|
|
379
|
+
row["seconds"] = round(session.seconds, 1)
|
|
380
|
+
return row
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mcp-dispatch
|
|
3
|
+
Version: 0.1.1
|
|
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
|
+
Project-URL: Homepage, https://github.com/retospect/mcp-dispatch
|
|
6
|
+
Project-URL: Repository, https://github.com/retospect/mcp-dispatch
|
|
7
|
+
Project-URL: Issues, https://github.com/retospect/mcp-dispatch/issues
|
|
8
|
+
Author-email: Reto Stamm <reto@retostamm.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: mcp,mcp-server,model-context-protocol,plugins,skills,tools
|
|
12
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Requires-Dist: pydantic>=2.7
|
|
20
|
+
Provides-Extra: mcp
|
|
21
|
+
Requires-Dist: mcp<2,>=1.30; extra == 'mcp'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# mcp-dispatch
|
|
25
|
+
|
|
26
|
+
A small framework for MCP servers whose tools are used by language models.
|
|
27
|
+
|
|
28
|
+
An MCP server usually shows an assistant one tool per thing it can do. Every tool's name, description and schema is read in every conversation, so a server that can do much costs much before the first call, and a permission has to be given tool by tool.
|
|
29
|
+
|
|
30
|
+
mcp-dispatch shows five tools and keeps everything else behind them:
|
|
31
|
+
|
|
32
|
+
| Tool | What it is for |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `get` | reads |
|
|
35
|
+
| `search` | finds things, and the how-to guides |
|
|
36
|
+
| `create` | adds or changes |
|
|
37
|
+
| `destroy` | removes for good |
|
|
38
|
+
| `share` | gives someone access |
|
|
39
|
+
|
|
40
|
+
A call names a path and its arguments: `create {"path": "shelf/add", "title": "Dune"}`. The paths come from plugins: Python classes whose tagged methods are the actions. What the assistant needs to know about an action is made from its signature and docstring and is fetched when it is needed (`"shelf/add?"`), as are the how-to guides a plugin ships (`search {"q": "lend a book", "t": "skill"}`).
|
|
41
|
+
|
|
42
|
+
What you get:
|
|
43
|
+
|
|
44
|
+
- **A small first read.** Five tool descriptions and a short first message, however many actions are installed.
|
|
45
|
+
- **One switch per risk.** A client that lets an assistant read without asking, and asks before it deletes or shares, needs four settings.
|
|
46
|
+
- **Plugins.** A package adds its actions by listing one class under an entry point. The host finds it when it starts.
|
|
47
|
+
- **A command line that falls out of it.** `mcp-dispatch call create shelf/add title=Dune` makes the same call without a client, and `mcp-dispatch help shelf/add` prints what an assistant would read about it.
|
|
48
|
+
- **Interface text that is checked.** `mcp-dispatch check` fails when an action is not documented in full, when an example call is not one the action accepts, or when a how-to guide names a call that no longer exists.
|
|
49
|
+
- **Interface text that can be tried.** `mcp_dispatch.trials` runs an assistant that has never seen your server against it, with your tools and nothing else, and keeps what it called. A text an assistant acts on is judged by what assistants do with it, beside the text it replaces.
|
|
50
|
+
|
|
51
|
+
## Who writes against it
|
|
52
|
+
|
|
53
|
+
Assistants do. The guide is written for them and ships in the package:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
uv run mcp-dispatch guide # how to write a plugin
|
|
57
|
+
uv run mcp-dispatch guide host # how to set up a host
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If you work with an assistant, put this line into your project's `AGENTS.md`:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
This project builds on mcp-dispatch. Before you write or change a plugin, read `uv run mcp-dispatch guide`; before you finish, `uv run mcp-dispatch check` must print ok.
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## A host in a few lines
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from mcp_dispatch import SKILL_SEARCH, Dispatch
|
|
70
|
+
|
|
71
|
+
dispatch = Dispatch() # the standard tools and the search
|
|
72
|
+
dispatch.find_plugins() # every plugin that is installed
|
|
73
|
+
dispatch.add_initial_message("You keep the lab's bookshelf for its people.")
|
|
74
|
+
dispatch.add_initial_message(SKILL_SEARCH)
|
|
75
|
+
dispatch.server("bookshelf").run()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Install with `pip install "mcp-dispatch[mcp]"` for a host, `pip install mcp-dispatch` for a plugin.
|
|
79
|
+
|
|
80
|
+
## State
|
|
81
|
+
|
|
82
|
+
Pre-alpha. It was built inside [Reticula](https://github.com/retospect/reticula-mcp) and lifted out. The texts an assistant reads have been tried only as far as `trials/README.md` records.
|
|
83
|
+
|
|
84
|
+
## Licence
|
|
85
|
+
|
|
86
|
+
MIT, see `LICENSE`. A plugin or a host that builds on mcp-dispatch may carry any licence.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
mcp_dispatch/__init__.py,sha256=uPyn7vTntARR_F7RkpSLclL8LW0C7kQFSO57sOYnkOg,1201
|
|
2
|
+
mcp_dispatch/__main__.py,sha256=waGQ8Isd1-Fa76-UxzHog1UUM0STi8JdbGMZ1wuAj7A,60
|
|
3
|
+
mcp_dispatch/check.py,sha256=1PrGtcTYiYuOqmYAXfWlu7WlN9FXb1fpX_aptJDJY8A,12461
|
|
4
|
+
mcp_dispatch/cli.py,sha256=uxctTN_-zJIyZC-rShlCFdy2WOmw0oxgpGQU1HQCIRs,10802
|
|
5
|
+
mcp_dispatch/command.py,sha256=FZpxMbmz5JEHvOoGBJ_oGPSVWVuJ8E__tMLN4i3py4o,4274
|
|
6
|
+
mcp_dispatch/dispatch.py,sha256=s35dh0t5zMdgaH3Fq8ziFOBwHxGJR93z0a9JRLeiH-U,8291
|
|
7
|
+
mcp_dispatch/docs.py,sha256=cJJB_MdaKxhBhGFedmuAeL-uqolDx2X-mFDvGv6Zp7U,3477
|
|
8
|
+
mcp_dispatch/errors.py,sha256=6j8WD4sNesBtKeUyQHizCqsmi7kQqePVHVQhx6H7RMk,1037
|
|
9
|
+
mcp_dispatch/lenient.py,sha256=Hcr7Yhky-ekjBVq36rAIZFtw-yJfUeEo-kVmyEALFs0,5795
|
|
10
|
+
mcp_dispatch/mcp_tools.py,sha256=oaH7Yu98D-__aehvrJgn-Qd6NPHPLEByZ62wCpf8OQQ,6916
|
|
11
|
+
mcp_dispatch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
mcp_dispatch/registry.py,sha256=NTds-F7BCs1oBUyfG_-Qme5q3k5afX81IYVTehZQ6GI,40242
|
|
13
|
+
mcp_dispatch/skills.py,sha256=iFl_Ld1o3p_oOtY8BvT5lntVhwZib6hOmwBk3vrbEUY,18672
|
|
14
|
+
mcp_dispatch/tags.py,sha256=FJH_gny5pQ_Nhk4QFMQyFDpx9OAMa1gad4Bz5sAflQY,6704
|
|
15
|
+
mcp_dispatch/trials.py,sha256=BbYC4N9kq369Cqs_HMSzeaU2PFgw7SildhVqsjLWG2E,14151
|
|
16
|
+
mcp_dispatch/agent_instructions/host.md,sha256=KkjlFeF4BH9b2ibXdNOLSoYmeDwgjDSooKkVRffsezM,6793
|
|
17
|
+
mcp_dispatch/agent_instructions/plugin.md,sha256=DkbKHRXxvUpXwFI4Q2CmMabDg-IUPqaKnGsBbXmIjeY,10268
|
|
18
|
+
mcp_dispatch-0.1.1.dist-info/METADATA,sha256=eRAz22vILAtWWikB91H2gHz5Ym7ywOrixhO9AZ96t6o,4465
|
|
19
|
+
mcp_dispatch-0.1.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
20
|
+
mcp_dispatch-0.1.1.dist-info/entry_points.txt,sha256=Hro0dCi6xszbZB2Zu81YGcdNva0SzThnilAFl6Adppc,55
|
|
21
|
+
mcp_dispatch-0.1.1.dist-info/licenses/LICENSE,sha256=QY7khYG2rW8xfCxusJkb0E00qz7Yahf963ydWL2YidM,1067
|
|
22
|
+
mcp_dispatch-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reto Stamm
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|