@agdf/mcp-server 0.0.0-stage → 0.20.1
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.
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +135 -2
- package/bin/agdf-mcp.js +24 -0
- package/package.json +41 -4
- package/src/cockpit-resource.js +20 -0
- package/src/generation-entry.js +86 -0
- package/src/generation-protocol.js +44 -0
- package/src/generation.js +211 -0
- package/src/main.js +56 -0
- package/src/server.js +187 -0
- package/src/ui-capability.js +17 -0
- package/src/worker-entry.js +39 -0
- package/src/worker.js +134 -0
- package/ui/cockpit.html +109 -0
- package/ui/decision-manifest.json +8 -0
- package/ui/decision.html +108 -0
- package/ui/manifest.json +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
AI Governance & Delivery Framework (AGDF)
|
|
2
|
+
Copyright 2026 Arndt Gold
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Model Context Protocol project.
|
|
5
|
+
Dependency versions and licenses are recorded by the package lock and release inventory.
|
|
6
|
+
|
|
7
|
+
AGDF(TM) and AI Governance & Delivery Framework(TM) are marks of Arndt Gold.
|
|
8
|
+
The Apache License, Version 2.0 does not grant permission to use project names,
|
|
9
|
+
trademarks, service marks or logos except as required for reasonable and
|
|
10
|
+
customary description of the origin of the project.
|
package/README.md
CHANGED
|
@@ -1,3 +1,136 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agdf/mcp-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local STDIO MCP adapter for AGDF dispatch and control inspection.
|
|
4
|
+
|
|
5
|
+
MCP tools: `agdf_dispatch`, `agdf_inspect`, `agdf_prepare`, `agdf_record`, `agdf_approve`, `agdf_revise`, `agdf_closeout`.
|
|
6
|
+
|
|
7
|
+
The bounded write groups, selected contract/status reads, original-operation recovery and
|
|
8
|
+
focused app-only decision facade are described in [Core and MCP command flow](../../docs/architecture/core-mcp-command-flow.md).
|
|
9
|
+
Host tool permission is separate from a deliberate gate decision. The source candidate's
|
|
10
|
+
click actions remain disabled while native app-only mediation is unqualified.
|
|
11
|
+
|
|
12
|
+
`agdf_inspect` also exposes read-only draft preflight through `operation: artifact-readiness`:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"operation": "artifact-readiness",
|
|
17
|
+
"presentation_language": "de",
|
|
18
|
+
"working_directory": "/absolute/repository",
|
|
19
|
+
"target_source": "explicit_target",
|
|
20
|
+
"primary_target": "/absolute/repository",
|
|
21
|
+
"run_id": "selected-run",
|
|
22
|
+
"gate": "PRD",
|
|
23
|
+
"expected_revision_id": "00000000-0000-4000-8000-000000000000"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Supply the actual current revision. Supported drafts are UR, PRD, SD and TP; their canonical
|
|
28
|
+
run-local path is derived by Core. `report.ready` means the existing authoring checks passed,
|
|
29
|
+
including required localized summary and applicable product-decision/traceability checks.
|
|
30
|
+
`checks`, `diagnostics` and `next_action` explain failures, with exact source digest and revision
|
|
31
|
+
when available. Core uses a bounded, revalidated read snapshot. The operation never registers,
|
|
32
|
+
reseals, prepares a presentation or approves anything; semantic derivation and reviewed source
|
|
33
|
+
bindings remain separate. An absent or unsafe source, stale revision or current control blocker
|
|
34
|
+
is unready. QA decisions and UAT are outside this authoring preflight.
|
|
35
|
+
|
|
36
|
+
To read an existing prepared document, obtain the current run revision with `gate-check`, then
|
|
37
|
+
read `operation-contract` with `module: agdf_prepare/presentation.prepare`. Its derived
|
|
38
|
+
`inspect_contract` explains arguments/examples; `presentation_catalog` supplies validated
|
|
39
|
+
`read_arguments`. A complete unique match is readable; several matches require selection.
|
|
40
|
+
Absence or an unavailable/partial catalog cannot justify guessing or preparing another record.
|
|
41
|
+
Follow every returned `next_cursor` with `presentation-document` to reconstruct the frozen bytes.
|
|
42
|
+
Keep the original document revision, including for historical reads. Catalog pages contain at most
|
|
43
|
+
16 candidates; scans stop at 256 records, 1 MiB of record bytes or 1024 directory entries. Catalog,
|
|
44
|
+
document and preview cursors are not interchangeable. Prepared records prove no human approval.
|
|
45
|
+
|
|
46
|
+
Dispatch follows the canonical skill-dispatch contract;
|
|
47
|
+
inspect exposes read-only doctor, gate-check, delivery-map and contract operations.
|
|
48
|
+
|
|
49
|
+
The shared Core continuation service may record one previously sealed relationship correction
|
|
50
|
+
for an authorized bound `continue_delivery` request, then route the same run afresh. The routing
|
|
51
|
+
service itself remains read-only. Accordingly, `agdf_dispatch` declares `readOnlyHint: false`;
|
|
52
|
+
`agdf_inspect` declares `readOnlyHint: true`. Neither tool creates an approval.
|
|
53
|
+
|
|
54
|
+
> [!IMPORTANT]
|
|
55
|
+
> This package documents the repository development build. The previously published AGDF 0.14.5 release
|
|
56
|
+
> did not include the MCP support described here. Repository assemblies and local plugin builds still
|
|
57
|
+
> carry the canonical version `0.14.5`, but can contain these newer MCP features. The version alone
|
|
58
|
+
> does not identify the payload: verify the assembly or installed runtime digests and the loaded session.
|
|
59
|
+
> These development instructions do not establish what a current npm `@latest` resolution contains.
|
|
60
|
+
|
|
61
|
+
The server requires Node.js 22 or later, exposes no generic shell, filesystem or network operation,
|
|
62
|
+
and never grants AGDF approval or delivery authority. Use the `create-agdf` lifecycle command to
|
|
63
|
+
prepare and register the exact version-matched server for a delivered host adapter. Host support
|
|
64
|
+
remains unverified until direct registration, discovery, invocation, failure and removal evidence exists.
|
|
65
|
+
|
|
66
|
+
The guided `codex`, `claude`, `copilot` and `opencode` installers can call that same lifecycle after
|
|
67
|
+
the user explicitly chooses complete setup. In non-interactive use this requires `--with-mcp` and
|
|
68
|
+
an entered absolute `--dir`; otherwise installation remains plugin-only. The plugin transaction and
|
|
69
|
+
MCP transaction retain separate results and recovery. A verified plugin is never rolled back only
|
|
70
|
+
because MCP setup fails. Marketplace-only installation has no CLI callback and therefore remains
|
|
71
|
+
plugin-only.
|
|
72
|
+
|
|
73
|
+
`agdf_dispatch` requires `presentation_language` as one well-formed BCP 47 tag. The host selects it
|
|
74
|
+
from the latest natural-language request: an explicit response-language instruction wins, otherwise
|
|
75
|
+
the dominant language is used, with `en` for mixed or ambiguous input. Missing or invalid input is
|
|
76
|
+
rejected by the MCP schema before governance evaluation. A valid unsupported tag is accepted and
|
|
77
|
+
renders through the complete English locale pack. The production tests exercise this contract
|
|
78
|
+
separately for protocol versions `2025-11-25` and `2026-07-28`.
|
|
79
|
+
|
|
80
|
+
### Selected Cockpit draft authoring check
|
|
81
|
+
|
|
82
|
+
`agdf_cockpit_read` additionally supports `artifact_readiness` with exactly `session_id`, `snapshot_id`, `run_id`, `gate` (`UR | PRD | SD | TP`) and `expected_revision_id`. It checks the currently observed, supported unapproved canonical draft, including an unregistered draft where supported. It accepts no target/path/writer/general-inspect override.
|
|
83
|
+
|
|
84
|
+
The same Core authoring projection serves standalone inspection and the scoped reader. The selected descriptor captures the draft file or absence before the snapshot freezes. The check validates the old binding, replaces the read scope with a same-Run capture, revalidates revision/gate/source before publication, and reissues resource selectors. Session/worker/pool and source observers adopt that capture together; context cleanup quarantine and existing bounds remain enforced.
|
|
85
|
+
|
|
86
|
+
The optional selected-detail `draft_check` contains source metadata, the unchanged authoring report and a Core-derived display/recovery state. A passed report never grants semantic review, registration, approval, implementation permission or QA. Old operations remain compatible; a client against a server lacking this descriptor shows bounded unavailable without a general-tool fallback.
|
|
87
|
+
|
|
88
|
+
## Repository test dependencies
|
|
89
|
+
|
|
90
|
+
Prepare the current source assembly before installing or running MCP package tests:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm run build:prepare
|
|
94
|
+
npm --prefix packages/mcp-server ci --ignore-scripts
|
|
95
|
+
npm --prefix packages/mcp-server run test:protocol
|
|
96
|
+
npm --prefix packages/mcp-server run test:safety
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Run these commands from the repository root. The repository lock resolves `create-agdf` from
|
|
100
|
+
`dist/npm/create-agdf`, which includes the assembled Core and generated resources. The published
|
|
101
|
+
package dependency remains version-pinned. Safety and cockpit-gating tests import that assembly
|
|
102
|
+
directly, so rebuilding it cannot leave those tests using an older same-version npm copy.
|
|
103
|
+
Other package-consumer tests create their own isolated runtimes from the same assembly. Installing
|
|
104
|
+
SDK dependencies is a separate preparation step; these tests neither update a host installation
|
|
105
|
+
nor qualify a native session. A direct `node test/...` invocation also requires the preparation.
|
|
106
|
+
|
|
107
|
+
Business failures use MCP `isError: true`, preserve the public domain result in
|
|
108
|
+
`structuredContent` and the first text block, and append one bounded EN/DE
|
|
109
|
+
explanation with the cause, known effect limit and supported correction. Success
|
|
110
|
+
keeps its existing single block, including exact decision presentation text.
|
|
111
|
+
Successful doctor, readiness, operation-status and freshness observations remain
|
|
112
|
+
successful when they report blocked, not-ready or unknown state. SDK input errors
|
|
113
|
+
and protocol errors retain their SDK-owned behavior.
|
|
114
|
+
|
|
115
|
+
The producing runtime owns the pure `agdf-tool-result/1` projection. Its checked
|
|
116
|
+
private descriptor travels with an old generation's result and is consumed before
|
|
117
|
+
public serialization; generation qualification includes that contract version.
|
|
118
|
+
Error-domain invariants are checked even though SDK 2 skips output validation for
|
|
119
|
+
error results. Existing response limits include the explanation and fallback.
|
|
120
|
+
Known parse rejection means not dispatched; timeout, cancellation after handoff or
|
|
121
|
+
a lost connection cannot establish rollback. For an uncertain command, inspect
|
|
122
|
+
`operation-status` with the original UUID and retain its exact payload. Recovery,
|
|
123
|
+
receipts, approval eligibility and any permitted replay remain Core-owned.
|
|
124
|
+
|
|
125
|
+
Worker requests retain a ten-second total deadline, including shutdown confirmation.
|
|
126
|
+
Execution reserves up to one second (one quarter of shorter configured deadlines) for
|
|
127
|
+
termination. Capacity and owned locks are released only after confirmed termination or
|
|
128
|
+
an observed exit, including an exit after a rejected termination request. If shutdown
|
|
129
|
+
remains unconfirmed, the error preserves the typed `cause_code` when one exists and the
|
|
130
|
+
last allowlisted `worker_phase` in diagnostics and the bounded explanation. Result content
|
|
131
|
+
and raw exception text never become a cause; an uncertain worker continues to block reuse.
|
|
132
|
+
|
|
133
|
+
This follows the [MCP tool error contract](https://modelcontextprotocol.io/specification/2026-07-28/server/tools#error-handling)
|
|
134
|
+
and [SDK error behavior](https://ts.sdk.modelcontextprotocol.io/v2/servers/errors).
|
|
135
|
+
Local protocol, package and browser tests do not establish native host or agent
|
|
136
|
+
performance; the unchanged ergonomics comparison records that evidence separately.
|
package/bin/agdf-mcp.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
|
|
4
|
+
const major = Number.parseInt(process.versions.node.split(".")[0], 10);
|
|
5
|
+
if (!Number.isInteger(major) || major < 22) {
|
|
6
|
+
process.stderr.write("AGDF_MCP_NODE_UNSUPPORTED\n");
|
|
7
|
+
process.exitCode = 1;
|
|
8
|
+
} else {
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const valid = (args.length === 2 || args.length === 4 && ['codex', 'claude'].includes(args[1]) && args[2] === '--cockpit-dir')
|
|
11
|
+
&& args[0] === "--surface"
|
|
12
|
+
&& ["codex", "claude", "copilot", "opencode"].includes(args[1]);
|
|
13
|
+
if (!valid) {
|
|
14
|
+
process.stderr.write("AGDF_MCP_ARGUMENTS_INVALID\n");
|
|
15
|
+
process.exitCode = 1;
|
|
16
|
+
} else {
|
|
17
|
+
const { runMcpServer } = await import("../src/main.js");
|
|
18
|
+
try { await runMcpServer({ surface: args[1], cockpitDir: args.length === 4 ? args[3] : undefined }); }
|
|
19
|
+
catch (error) {
|
|
20
|
+
process.stderr.write(['AGDF_COCKPIT_TARGET_INVALID', 'AGDF_COCKPIT_UI_INVALID'].includes(error.message) ? `${error.message}\n` : 'AGDF_MCP_STARTUP_FAILED\n');
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agdf/mcp-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.20.1",
|
|
4
|
+
"description": "Local MCP adapter for version-matched AGDF dispatch and control inspection.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"bin",
|
|
8
|
+
"src",
|
|
9
|
+
"README.md",
|
|
10
|
+
"NOTICE",
|
|
11
|
+
"ui"
|
|
12
|
+
],
|
|
13
|
+
"bin": {
|
|
14
|
+
"agdf-mcp": "./bin/agdf-mcp.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/server.js"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@modelcontextprotocol/server": "2.0.0",
|
|
22
|
+
"create-agdf": "0.20.1"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"agdf",
|
|
29
|
+
"mcp",
|
|
30
|
+
"governance",
|
|
31
|
+
"coding-agents"
|
|
32
|
+
],
|
|
33
|
+
"license": "Apache-2.0",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/ArndtGold/ai-native-governance-delivery-framework.git",
|
|
40
|
+
"directory": "packages/mcp-server"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://agdf.iself.eu"
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFileSync, lstatSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
export function loadCockpitResource({ uri, mimeType, limit, kind = 'cockpit', directory = new URL('../ui/', import.meta.url) } = {}) {
|
|
5
|
+
try {
|
|
6
|
+
if (!['cockpit', 'decision'].includes(kind)) throw Error();
|
|
7
|
+
const manifestURL = new URL(kind === 'decision' ? 'decision-manifest.json' : 'manifest.json', directory), htmlURL = new URL(kind + '.html', directory);
|
|
8
|
+
for (const url of [directory, manifestURL, htmlURL]) if (lstatSync(url).isSymbolicLink()) throw Error();
|
|
9
|
+
const manifest = JSON.parse(readFileSync(manifestURL, 'utf8'));
|
|
10
|
+
const stat = lstatSync(htmlURL);
|
|
11
|
+
if (!stat.isFile() || !Number.isSafeInteger(limit) || stat.size > limit) throw Error();
|
|
12
|
+
const bytes = readFileSync(htmlURL);
|
|
13
|
+
const digest = createHash('sha256').update(bytes).digest('hex');
|
|
14
|
+
if (manifest.schema_version !== '1' || manifest.uri !== uri || manifest.mime_type !== mimeType
|
|
15
|
+
|| manifest.bytes !== bytes.length || manifest.digest !== `sha256:${digest}`) throw Error();
|
|
16
|
+
const text = new TextDecoder('utf8', { fatal: true }).decode(bytes);
|
|
17
|
+
return { uri, mimeType, text, digest,
|
|
18
|
+
_meta: { ui: { csp: { connectDomains: [], resourceDomains: [], frameDomains: [], baseUriDomains: [] } } } };
|
|
19
|
+
} catch { throw new TypeError('AGDF_COCKPIT_UI_INVALID'); }
|
|
20
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// A directly owned private child. It never reads or writes public MCP STDIO.
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { createAgdfWorkerExecutor } from './server.js';
|
|
4
|
+
import { loadCockpitResource } from './cockpit-resource.js';
|
|
5
|
+
import { generationMessage, validGenerationMessage, generationManifest, generationFailureReason } from './generation-protocol.js';
|
|
6
|
+
import { createMcpDispatchRuntime, createMcpDecisionRuntime, createMcpCockpitRuntime, DECISION_UI_URI,
|
|
7
|
+
inspectMcpDispatcherRuntime, releaseAbandonedOwnedLock } from 'create-agdf/mcp-dispatch-runtime';
|
|
8
|
+
const epoch = process.argv[2], generation = Number(process.argv[3]);
|
|
9
|
+
let runtime, executor, starting = false, closing = false, inflight = 0, serverDigest, sdkDigest, uiDigest;
|
|
10
|
+
const observed = new Set(), unknown = new Set();
|
|
11
|
+
function status() {
|
|
12
|
+
const owned = runtime?.inspectOwnership?.() ?? { views: 0 };
|
|
13
|
+
return { ...owned, inflight: inflight + (starting ? 1 : 0) + (owned.inflight ?? 0),
|
|
14
|
+
executor: executor?.active ? 1 : 0, uncertain: unknown.size + (owned.uncertain ?? 0), closing };
|
|
15
|
+
}
|
|
16
|
+
function send(input, kind, payload) {
|
|
17
|
+
const reply = generationMessage(epoch, generation, kind, payload, {}, input.original_operation_id, input.request_id);
|
|
18
|
+
if (validGenerationMessage(reply, { epoch, generation, reply: true })) process.send?.(reply);
|
|
19
|
+
else process.send?.(generationMessage(epoch, generation, 'failure', { reason: 'generation_result_limit' }, {}, input.original_operation_id, input.request_id));
|
|
20
|
+
}
|
|
21
|
+
process.on('message', async input => {
|
|
22
|
+
if (!validGenerationMessage(input, { epoch, generation }) || observed.has(input.request_id)) return;
|
|
23
|
+
if (observed.size >= 8192) { send(input, 'failure', { reason: 'generation_request_capacity' }); return; }
|
|
24
|
+
observed.add(input.request_id);
|
|
25
|
+
try {
|
|
26
|
+
if (input.kind === 'qualify') {
|
|
27
|
+
if (runtime || starting || closing) throw Error('generation_already_initialized');
|
|
28
|
+
starting = true;
|
|
29
|
+
const { surface, commandGroups, cockpitDir, cockpitMode } = input.payload;
|
|
30
|
+
const inspected = inspectMcpDispatcherRuntime();
|
|
31
|
+
if (inspected.provenanceStatus !== 'matched') throw Error('runtime_provenance_invalid');
|
|
32
|
+
runtime = cockpitDir || cockpitMode ? await createMcpCockpitRuntime({ surface, cockpitDir, cockpitMode, inspected })
|
|
33
|
+
: createMcpDispatchRuntime({ surface, commandGroups, inspected });
|
|
34
|
+
if (!cockpitDir && !cockpitMode && surface === 'codex') {
|
|
35
|
+
const ui = { uri: DECISION_UI_URI, mimeType: 'text/html;profile=mcp-app', limit: 4 * 1024 ** 2, kind: 'decision' };
|
|
36
|
+
ui.digest = loadCockpitResource(ui).digest;
|
|
37
|
+
runtime = await createMcpDecisionRuntime({ runtime, ui });
|
|
38
|
+
}
|
|
39
|
+
if (runtime.ui) uiDigest = loadCockpitResource(runtime.ui).digest;
|
|
40
|
+
// Inspect reports package-owned immutable identities, not caller evidence.
|
|
41
|
+
sdkDigest = inspected.generationIdentity.sdk_digest; serverDigest = inspected.generationIdentity.server_digest;
|
|
42
|
+
executor = runtime.mode === 'cockpit' ? null : createAgdfWorkerExecutor(runtime, { releaseOwnedLock: releaseAbandonedOwnedLock });
|
|
43
|
+
const support = { ui: Boolean(runtime.ui), app_mediation: runtime.mode === 'decision'
|
|
44
|
+
&& runtime.trustedContext.decisionQualification(input.context.client, uiDigest) === true };
|
|
45
|
+
starting = false;
|
|
46
|
+
send(input, 'qualified', { manifest: generationManifest(runtime, uiDigest, sdkDigest),
|
|
47
|
+
producer: { server_digest: serverDigest, dispatcher_digest: inspected.generationIdentity.dispatcher_digest, sdk_digest: sdkDigest }, support });
|
|
48
|
+
} else if (input.kind === 'session_inspect') {
|
|
49
|
+
send(input, 'status', status());
|
|
50
|
+
} else if (input.kind === 'shutdown') {
|
|
51
|
+
if (closing || starting || inflight || unknown.size) throw Error('generation_work_protected');
|
|
52
|
+
closing = true;
|
|
53
|
+
await executor?.close(); await runtime?.close?.();
|
|
54
|
+
const remaining = status();
|
|
55
|
+
if (remaining.views || remaining.inflight || remaining.executor || remaining.uncertain) throw Error('generation_cleanup_unconfirmed');
|
|
56
|
+
send(input, 'closed', remaining);
|
|
57
|
+
process.disconnect(); // Natural exit, no kill, after all owned work is closed.
|
|
58
|
+
} else {
|
|
59
|
+
if (!runtime || closing) throw Error('generation_unavailable');
|
|
60
|
+
const { name, arguments: args } = input.payload, tool = runtime.tool?.(name) ?? runtime.tools.find(t => t.name === name);
|
|
61
|
+
if (!tool || tool.requiresUi && input.context.uiSupported !== true) throw Error('resource_denied');
|
|
62
|
+
++inflight;
|
|
63
|
+
let result, phase = tool.parentOwned || !executor ? 'parse' : 'execute';
|
|
64
|
+
try {
|
|
65
|
+
if (tool.parentOwned || !executor) {
|
|
66
|
+
const parsed = tool.parse(args); phase = 'execute';
|
|
67
|
+
result = await tool.execute(parsed, undefined, input.context);
|
|
68
|
+
} else result = await executor.execute(args, { toolName: name });
|
|
69
|
+
if (runtime.postprocessToolResult) result = await runtime.postprocessToolResult(name, args, result, input.context);
|
|
70
|
+
if (input.original_operation_id && result.outcome === 'effect_unknown') unknown.add(input.original_operation_id);
|
|
71
|
+
if (name === 'agdf_inspect' && args.operation === 'operation-status' && result.report?.status === 'recorded'
|
|
72
|
+
&& result.report.receipt?.operation_id === args.module) unknown.delete(args.module);
|
|
73
|
+
send(input, 'result', runtime.projectToolResult(name, args, result));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
const facts = runtime.normalizeFailure(error, { phase });
|
|
76
|
+
if (input.original_operation_id && facts.dispatch !== 'not_dispatched') unknown.add(input.original_operation_id);
|
|
77
|
+
send(input, 'result', runtime.projectToolResult(name, args, runtime.failure(facts.code, name, args, facts), facts));
|
|
78
|
+
} finally { --inflight; }
|
|
79
|
+
}
|
|
80
|
+
} catch (error) { if (input.kind === 'qualify') starting = false; send(input, 'failure', { reason: generationFailureReason(error) }); }
|
|
81
|
+
});
|
|
82
|
+
process.on('disconnect', () => {
|
|
83
|
+
// Loss of the facade does not cancel or replay business effects. Timers and
|
|
84
|
+
// existing worker/view owners retain their bounds; no process-wide force kill.
|
|
85
|
+
if (!closing) { void executor?.close().catch(() => {}); void runtime?.close?.().catch(() => {}); }
|
|
86
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
export const GENERATION_LIMITS = Object.freeze({ slots: 3, input: 65536, result: 1048576, qualify: 30000, close: 10000, receipts: 256, routes: 4096 });
|
|
3
|
+
const uuid = value => typeof value === 'string' && /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/u.test(value);
|
|
4
|
+
const fields = ['schema_version', 'owner_epoch', 'generation_id', 'request_id', 'kind', 'original_operation_id', 'payload', 'context'];
|
|
5
|
+
export function validGenerationMessage(value, { epoch, generation, reply = false } = {}) {
|
|
6
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).sort().join() !== [...fields].sort().join()
|
|
7
|
+
|| value.schema_version !== '1' || value.owner_epoch !== epoch || value.generation_id !== generation
|
|
8
|
+
|| !uuid(value.request_id) || !(value.original_operation_id === null || uuid(value.original_operation_id))
|
|
9
|
+
|| !Number.isSafeInteger(value.generation_id) || value.generation_id < 1
|
|
10
|
+
|| !(reply ? ['qualified', 'result', 'status', 'closed', 'failure'] : ['qualify', 'invoke', 'session_inspect', 'shutdown']).includes(value.kind)
|
|
11
|
+
|| !value.context || typeof value.context !== 'object' || Array.isArray(value.context)) return false;
|
|
12
|
+
try { return Buffer.byteLength(JSON.stringify(value)) <= (reply ? GENERATION_LIMITS.result : GENERATION_LIMITS.input); } catch { return false; }
|
|
13
|
+
}
|
|
14
|
+
export function generationMessage(epoch, generation, kind, payload, context = {}, original = null, requestId) {
|
|
15
|
+
return { schema_version: '1', owner_epoch: epoch, generation_id: generation, request_id: requestId,
|
|
16
|
+
kind, original_operation_id: original, payload, context };
|
|
17
|
+
}
|
|
18
|
+
export function generationManifest(runtime, uiDigest, sdkDigest) {
|
|
19
|
+
if (typeof runtime.toolErrorContract !== 'string' || !runtime.toolErrorContract
|
|
20
|
+
|| typeof runtime.projectToolResult !== 'function' || typeof runtime.consumeToolResult !== 'function'
|
|
21
|
+
|| typeof runtime.normalizeFailure !== 'function') throw Error('generation_manifest_incompatible');
|
|
22
|
+
// Stable transport shape, never business eligibility or a human-origin proof.
|
|
23
|
+
return { schema_version: '1', mode: runtime.mode ?? 'headless', sdk_digest: sdkDigest,
|
|
24
|
+
protocol: 'mcp-sdk/2:stdio-legacy-and-modern', tool_error_contract: runtime.toolErrorContract,
|
|
25
|
+
tools: runtime.tools.map(tool => ({ name: tool.name, definition: tool.definition })),
|
|
26
|
+
resource: runtime.ui ? { uri: runtime.ui.uri, mimeType: runtime.ui.mimeType, digest: uiDigest } : null,
|
|
27
|
+
command_groups: [...(runtime.trustedContext.commandGroups ?? [])] };
|
|
28
|
+
}
|
|
29
|
+
export const manifestDigest = manifest => createHash('sha256').update(JSON.stringify(manifest)).digest('hex');
|
|
30
|
+
|
|
31
|
+
const FAILURE_REASONS = new Set([
|
|
32
|
+
'generation_unavailable', 'generation_input_limit', 'generation_response_unknown', 'generation_connection_lost',
|
|
33
|
+
'generation_capacity_protected', 'generation_manifest_incompatible', 'generation_result_limit',
|
|
34
|
+
'generation_request_capacity', 'generation_already_initialized', 'generation_work_protected',
|
|
35
|
+
'generation_cleanup_unconfirmed', 'resource_denied', 'runtime_provenance_invalid', 'runtime_version_mismatch',
|
|
36
|
+
'dispatch_busy', 'dispatch_cancelled', 'dispatch_timeout', 'dispatch_worker_failed', 'dispatch_worker_termination_unconfirmed',
|
|
37
|
+
'runtime_publication_unowned', 'runtime_candidate_manifest_invalid', 'runtime_candidate_unowned', 'runtime_candidate_digest_mismatch',
|
|
38
|
+
'AGDF_MCP_EXECUTABLE_CLAIM_INVALID', 'AGDF_MCP_EXECUTABLE_CLAIM_CONTENDED',
|
|
39
|
+
'AGDF_MCP_EXECUTABLE_CLAIM_LOCK_UNCONFIRMED', 'AGDF_MCP_PUBLICATION_DEADLINE_EXCEEDED',
|
|
40
|
+
]);
|
|
41
|
+
export function generationFailureReason(error) {
|
|
42
|
+
const reason = error?.code ?? error?.message;
|
|
43
|
+
return FAILURE_REASONS.has(reason) ? reason : 'generation_runtime_failed';
|
|
44
|
+
}
|