mcp-swarm-core 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TKasperczyk
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.
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-swarm-core
3
+ Version: 0.1.0
4
+ Summary: Shared stdlib-only MCP 2026-07-28, Tasks extension, process-tree, worktree, and JSONL swarm infrastructure
5
+ Author: TKasperczyk
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/TKasperczyk/mcp-swarm-core
8
+ Project-URL: Repository, https://github.com/TKasperczyk/mcp-swarm-core
9
+ Project-URL: Issues, https://github.com/TKasperczyk/mcp-swarm-core/issues
10
+ Keywords: mcp,swarm,async,parallel,tasks,worktree,jsonl
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # mcp-swarm-core
21
+
22
+ Shared, zero-dependency (Python stdlib only) infrastructure for building parallel MCP CLI swarm servers such as [codex-mcp-swarm](https://github.com/TKasperczyk/codex-mcp-swarm) and [antigravity-mcp-swarm](https://github.com/TKasperczyk/antigravity-mcp-swarm).
23
+
24
+ ## What it provides
25
+
26
+ - **MCP Protocol Engine (`mcp_swarm_core.protocol`)**
27
+ - Stateless MCP `2026-07-28` (`server/discover`, per-request `_meta["io.modelcontextprotocol/protocolVersion"]` and `_meta["io.modelcontextprotocol/clientCapabilities"]`, `resultType` discriminators, `-32022` unsupported-version rejection)
28
+ - Official MCP Tasks extension (`io.modelcontextprotocol/tasks`, SEP-2663: `CreateTaskResult`, `tasks/get`, `tasks/cancel`, tool-level `isError: true` under `status: "completed"`)
29
+ - Backward-compatible stateful MCP (`2024-11-05` through `2025-11-25`: `initialize`, `instructions`, `ping`, tool `annotations`, `outputSchema` + `structuredContent`, enriched `notifications/progress`, silent unknown notifications per JSON-RPC 2.0 §4.1)
30
+ - Multi-threaded stdio dispatcher with bounded request cancellation tracking and off-thread sync child termination
31
+ - **Cross-Platform Process & Tree Management (`mcp_swarm_core.platform`)**
32
+ - POSIX process-group isolation (`start_new_session=True`), group signalling (`os.killpg`), grandchild sweep, and Linux `/proc` PID-reuse + zombie detection
33
+ - Native Windows Win32 `ctypes` process liveness, creation-time PID-reuse protection, `taskkill.exe /T /F /PID` process-tree termination, and `CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP`
34
+ - Safe stdin payload transport (`prompt_stdin`): unlinked `TemporaryFile` on POSIX and regular `.stdin` files (no `O_TEMPORARY`) on Windows
35
+ - **Disk-Backed Task Store & Lifecycle (`mcp_swarm_core.task_store`)**
36
+ - Strictly lock-free POSIX `SIGCHLD` async reaper (no logging or locks inside the signal handler; safe against PID pop/resurrection races)
37
+ - Atomic metadata persistence (`mkstemp` + `os.replace` with Windows retry)
38
+ - Per-task finalization locking, automatic expiry cleanup, batch wait with client auto-backgrounding floor, and sync child tracking
39
+ - **Git Worktree Isolation (`mcp_swarm_core.worktree`)**
40
+ - Isolated `HEAD`-based git worktrees (`<prefix>/<id>`) with safe cleanup and branch deletion
41
+ - **Incremental Single-Pass JSONL Cache (`mcp_swarm_core.jsonl_cache`)**
42
+ - Parses growing task `.stdout` files incrementally for files above 8 KiB
43
+ - RFC 8259 Unicode line-separator safety (`split("\n")`, never `splitlines()`)
44
+ - `st_dev` + `st_ino != 0` + strict `>` shrink-race guards and isolated partial-tail state cloning
45
+ - **Shared Diagnostics & Schema Helpers (`mcp_swarm_core.diagnostics`)**
46
+ - Terminal-event precedence, conservative failure classification, structured failure formatting, live activity briefs, and JSON `outputSchema` builders
47
+
48
+ ## Requirements
49
+
50
+ - Python 3.8+
51
+ - Zero third-party dependencies (stdlib only)
52
+
53
+ ## License
54
+
55
+ MIT
@@ -0,0 +1,36 @@
1
+ # mcp-swarm-core
2
+
3
+ Shared, zero-dependency (Python stdlib only) infrastructure for building parallel MCP CLI swarm servers such as [codex-mcp-swarm](https://github.com/TKasperczyk/codex-mcp-swarm) and [antigravity-mcp-swarm](https://github.com/TKasperczyk/antigravity-mcp-swarm).
4
+
5
+ ## What it provides
6
+
7
+ - **MCP Protocol Engine (`mcp_swarm_core.protocol`)**
8
+ - Stateless MCP `2026-07-28` (`server/discover`, per-request `_meta["io.modelcontextprotocol/protocolVersion"]` and `_meta["io.modelcontextprotocol/clientCapabilities"]`, `resultType` discriminators, `-32022` unsupported-version rejection)
9
+ - Official MCP Tasks extension (`io.modelcontextprotocol/tasks`, SEP-2663: `CreateTaskResult`, `tasks/get`, `tasks/cancel`, tool-level `isError: true` under `status: "completed"`)
10
+ - Backward-compatible stateful MCP (`2024-11-05` through `2025-11-25`: `initialize`, `instructions`, `ping`, tool `annotations`, `outputSchema` + `structuredContent`, enriched `notifications/progress`, silent unknown notifications per JSON-RPC 2.0 §4.1)
11
+ - Multi-threaded stdio dispatcher with bounded request cancellation tracking and off-thread sync child termination
12
+ - **Cross-Platform Process & Tree Management (`mcp_swarm_core.platform`)**
13
+ - POSIX process-group isolation (`start_new_session=True`), group signalling (`os.killpg`), grandchild sweep, and Linux `/proc` PID-reuse + zombie detection
14
+ - Native Windows Win32 `ctypes` process liveness, creation-time PID-reuse protection, `taskkill.exe /T /F /PID` process-tree termination, and `CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP`
15
+ - Safe stdin payload transport (`prompt_stdin`): unlinked `TemporaryFile` on POSIX and regular `.stdin` files (no `O_TEMPORARY`) on Windows
16
+ - **Disk-Backed Task Store & Lifecycle (`mcp_swarm_core.task_store`)**
17
+ - Strictly lock-free POSIX `SIGCHLD` async reaper (no logging or locks inside the signal handler; safe against PID pop/resurrection races)
18
+ - Atomic metadata persistence (`mkstemp` + `os.replace` with Windows retry)
19
+ - Per-task finalization locking, automatic expiry cleanup, batch wait with client auto-backgrounding floor, and sync child tracking
20
+ - **Git Worktree Isolation (`mcp_swarm_core.worktree`)**
21
+ - Isolated `HEAD`-based git worktrees (`<prefix>/<id>`) with safe cleanup and branch deletion
22
+ - **Incremental Single-Pass JSONL Cache (`mcp_swarm_core.jsonl_cache`)**
23
+ - Parses growing task `.stdout` files incrementally for files above 8 KiB
24
+ - RFC 8259 Unicode line-separator safety (`split("\n")`, never `splitlines()`)
25
+ - `st_dev` + `st_ino != 0` + strict `>` shrink-race guards and isolated partial-tail state cloning
26
+ - **Shared Diagnostics & Schema Helpers (`mcp_swarm_core.diagnostics`)**
27
+ - Terminal-event precedence, conservative failure classification, structured failure formatting, live activity briefs, and JSON `outputSchema` builders
28
+
29
+ ## Requirements
30
+
31
+ - Python 3.8+
32
+ - Zero third-party dependencies (stdlib only)
33
+
34
+ ## License
35
+
36
+ MIT
@@ -0,0 +1,154 @@
1
+ """mcp-swarm-core -- Shared stdlib-only infrastructure for parallel MCP CLI swarms."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from .backend import RuntimeHooks, SwarmBackend, parse_env_int
6
+ from .diagnostics import (
7
+ FAILURE_SCHEMA,
8
+ TASK_ID_RE,
9
+ build_failure_info,
10
+ classify_failure,
11
+ clean_none,
12
+ decide_run_status,
13
+ error_message,
14
+ failure_structured,
15
+ format_failure_info,
16
+ format_mcp_task_status_message,
17
+ format_task_activity_brief,
18
+ iso_utc,
19
+ make_async_output_schema,
20
+ make_cancel_output_schema,
21
+ make_inferred_hints,
22
+ make_reply_output_schema,
23
+ make_status_output_schema,
24
+ make_sync_output_schema,
25
+ make_wait_output_schema,
26
+ safe_read,
27
+ validate_task_id,
28
+ )
29
+ from .jsonl_cache import IncrementalJsonlCache, JsonlParserAdapter
30
+ from .platform import (
31
+ DEFAULT_TMP,
32
+ IS_WINDOWS,
33
+ POPEN_FLAGS,
34
+ TEXT_KW,
35
+ default_user_tmp_dir,
36
+ default_worktree_dir,
37
+ ensure_private_dir,
38
+ get_pid_start_time,
39
+ is_alive,
40
+ popen_kw,
41
+ posix_group_alive,
42
+ posix_signal_tree,
43
+ prepare_log_parent,
44
+ prepare_runtime_dir,
45
+ prompt_stdin,
46
+ safe_which,
47
+ stop_proc,
48
+ win_is_running,
49
+ win_kill_tree,
50
+ win_open_process,
51
+ win_start_time,
52
+ win_system32,
53
+ )
54
+ from .protocol import (
55
+ ALL_PROTOCOL_VERSIONS,
56
+ BLOCKING_METHODS,
57
+ DEFAULT_PROTOCOL_VERSION,
58
+ DISCOVER_TTL_MS,
59
+ STATELESS_PROTOCOL_VERSIONS,
60
+ SUPPORTED_PROTOCOL_VERSIONS,
61
+ TASK_POLL_INTERVAL_MS,
62
+ TASKS_EXTENSION_ID,
63
+ CancellationTracker,
64
+ McpSwarmServer,
65
+ client_supports_tasks,
66
+ is_valid_request_id,
67
+ validate_task_ids_param,
68
+ )
69
+ from .task_store import (
70
+ ASYNC_PIDS,
71
+ ASYNC_PROCS,
72
+ NOT_REAPED,
73
+ SyncProcRegistry,
74
+ TaskManager,
75
+ install_sigchld_handler,
76
+ sigchld_handler,
77
+ write_meta_atomic,
78
+ )
79
+ from .worktree import create_worktree, remove_worktree
80
+
81
+ __all__ = [
82
+ "__version__",
83
+ "ALL_PROTOCOL_VERSIONS",
84
+ "ASYNC_PIDS",
85
+ "ASYNC_PROCS",
86
+ "BLOCKING_METHODS",
87
+ "CancellationTracker",
88
+ "DEFAULT_PROTOCOL_VERSION",
89
+ "DEFAULT_TMP",
90
+ "DISCOVER_TTL_MS",
91
+ "FAILURE_SCHEMA",
92
+ "IS_WINDOWS",
93
+ "IncrementalJsonlCache",
94
+ "JsonlParserAdapter",
95
+ "McpSwarmServer",
96
+ "NOT_REAPED",
97
+ "POPEN_FLAGS",
98
+ "RuntimeHooks",
99
+ "STATELESS_PROTOCOL_VERSIONS",
100
+ "SUPPORTED_PROTOCOL_VERSIONS",
101
+ "SwarmBackend",
102
+ "SyncProcRegistry",
103
+ "TASKS_EXTENSION_ID",
104
+ "TASK_ID_RE",
105
+ "TASK_POLL_INTERVAL_MS",
106
+ "TEXT_KW",
107
+ "TaskManager",
108
+ "build_failure_info",
109
+ "classify_failure",
110
+ "clean_none",
111
+ "client_supports_tasks",
112
+ "create_worktree",
113
+ "decide_run_status",
114
+ "default_user_tmp_dir",
115
+ "default_worktree_dir",
116
+ "ensure_private_dir",
117
+ "error_message",
118
+ "failure_structured",
119
+ "format_failure_info",
120
+ "format_mcp_task_status_message",
121
+ "format_task_activity_brief",
122
+ "get_pid_start_time",
123
+ "install_sigchld_handler",
124
+ "is_alive",
125
+ "is_valid_request_id",
126
+ "iso_utc",
127
+ "make_async_output_schema",
128
+ "make_cancel_output_schema",
129
+ "make_inferred_hints",
130
+ "make_reply_output_schema",
131
+ "make_status_output_schema",
132
+ "make_sync_output_schema",
133
+ "make_wait_output_schema",
134
+ "parse_env_int",
135
+ "popen_kw",
136
+ "posix_group_alive",
137
+ "posix_signal_tree",
138
+ "prepare_log_parent",
139
+ "prepare_runtime_dir",
140
+ "prompt_stdin",
141
+ "remove_worktree",
142
+ "safe_read",
143
+ "safe_which",
144
+ "sigchld_handler",
145
+ "stop_proc",
146
+ "validate_task_id",
147
+ "validate_task_ids_param",
148
+ "win_is_running",
149
+ "win_kill_tree",
150
+ "win_open_process",
151
+ "win_start_time",
152
+ "win_system32",
153
+ "write_meta_atomic",
154
+ ]