@lastehr/agent-write-conformance 0.1.0

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 ADDED
@@ -0,0 +1,198 @@
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
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor,
137
+ except as required for reasonable and customary use in describing the
138
+ origin of the Work and reproducing the content of the NOTICE file.
139
+
140
+ 7. Disclaimer of Warranty. Unless required by applicable law or
141
+ agreed to in writing, Licensor provides the Work (and each
142
+ Contributor provides its Contributions) on an "AS IS" BASIS,
143
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
144
+ implied, including, without limitation, any warranties or conditions
145
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
146
+ PARTICULAR PURPOSE. You are solely responsible for determining the
147
+ appropriateness of using or redistributing the Work and assume any
148
+ risks associated with Your exercise of permissions under this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise,
152
+ unless required by applicable law (such as deliberate and grossly
153
+ negligent acts) or agreed to in writing, shall any Contributor be
154
+ liable to You for damages, including any direct, indirect, special,
155
+ incidental, or consequential damages of any character arising as a
156
+ result of this License or out of the use or inability to use the
157
+ Work (including but not limited to damages for loss of goodwill,
158
+ work stoppage, computer failure or malfunction, or any and all
159
+ other commercial damages or losses), even if such Contributor
160
+ has been advised of the possibility of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing
163
+ the Work or Derivative Works thereof, You may choose to offer,
164
+ and charge a fee for, acceptance of support, warranty, indemnity,
165
+ or other liability obligations and/or rights consistent with this
166
+ License. However, in accepting such obligations, You may act only
167
+ on Your own behalf and on Your sole responsibility, not on behalf
168
+ of any other Contributor, and only if You agree to indemnify,
169
+ defend, and hold each Contributor harmless for any liability
170
+ incurred by, or claims asserted against, such Contributor by reason
171
+ of your accepting any such warranty or additional liability.
172
+
173
+ END OF TERMS AND CONDITIONS
174
+
175
+ APPENDIX: How to apply the Apache License to your work.
176
+
177
+ To apply the Apache License to your work, attach the following
178
+ boilerplate notice, with the fields enclosed by brackets "[]"
179
+ replaced with your own identifying information. (Don't include
180
+ the brackets!) The text should be enclosed in the appropriate
181
+ comment syntax for the file format. We also recommend that a
182
+ file or class name and description of purpose be included on the
183
+ same "printed page" as the copyright notice for easier
184
+ identification within third-party archives.
185
+
186
+ Copyright 2026 Chris Betz
187
+
188
+ Licensed under the Apache License, Version 2.0 (the "License");
189
+ you may not use this file except in compliance with the License.
190
+ You may obtain a copy of the License at
191
+
192
+ http://www.apache.org/licenses/LICENSE-2.0
193
+
194
+ Unless required by applicable law or agreed to in writing, software
195
+ distributed under the License is distributed on an "AS IS" BASIS,
196
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
197
+ See the License for the specific language governing permissions and
198
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @lastehr/agent-write-conformance
2
+
3
+ Conformance suite for **[Approval-Gated Agent Writes on FHIR](https://www.lastehr.com/docs/agent-write-protocol)** (v0.1 draft): a small, framework-neutral protocol where every agent-initiated chart write is a proposal a human explicitly decides on before it commits.
4
+
5
+ The suite is an MCP stdio **client** with a scripted reviewer. It spawns your server fresh for every scenario, answers your elicitation prompts each possible way — approve, decline, cancel, accept-without-approving, transport failure, and a client that never declared the capability — and verifies every outcome against the FHIR store **with its own reads**, never your tool results' word for it.
6
+
7
+ ## Run it
8
+
9
+ ```bash
10
+ npx @lastehr/agent-write-conformance \
11
+ --server "node ./dist/my-mcp-server.js" \
12
+ --manifest ./awp-manifest.json \
13
+ --fhir-base-url http://localhost:8080/fhir \
14
+ --confirm-synthetic \
15
+ --report ./awp-report.json
16
+ ```
17
+
18
+ `--confirm-synthetic` is required: the suite creates and deletes resources — and its persistence sweeps diff **whole resource types**, so a misrouted write cannot hide under the wrong patient — which means the target must be a disposable synthetic store, never real or shared data. Bearer auth for the probe comes from `AWP_FHIR_BEARER_TOKEN` in the environment. Your server command and the probe must point at the same store, and should exec a single server process (a compound shell command can leave grandchildren running when a scenario's connection closes).
19
+
20
+ The manifest declares each write tool's name, a valid argument template (`$PATIENT_ID` and `$NONCE` are substituted per scenario), what it creates, and where the patient reference lands — see [examples/lastehr-mcp.awp-manifest.json](./examples/lastehr-mcp.awp-manifest.json), which is the manifest this repository's own `@lastehr/mcp` write profile passes with.
21
+
22
+ ## Checks (v0.1)
23
+
24
+ | id | level | proves |
25
+ | --- | --- | --- |
26
+ | `synthetic-target` | hygiene | The suite could create its tagged disposable patient. |
27
+ | `capability-gate` | must | Without the elicitation capability, write tools are unlisted and a call anyway persists nothing (spec §2). |
28
+ | `proposal-gate` | must | An invoked write tool produces a proposal, and sampled probes *during* deliberation and after a denial find nothing persisted (spec §1). |
29
+ | `decision-shape` | must | The decision exchange requests booleans only, never data (spec §2). |
30
+ | `proposal-renders-inputs` | partial | Every argument value appears in the proposal text (presence, not completeness of rendering — spec §1). |
31
+ | `approved-write` | must | Explicit approval commits exactly once, with the proposed values, on the right patient, reporting the server-assigned id (spec §2–3). |
32
+ | `denied-write` | must | Decline, cancel, and an unapproved accept each leave no new resource of the write's type anywhere in the store, and say so (spec §2). |
33
+ | `unavailable-write` | must | A decision exchange that fails in transit fails closed (spec §2). |
34
+ | `cleanup` | hygiene | Everything the suite created was deleted. |
35
+
36
+ ## What passing means — and doesn't
37
+
38
+ Passing proves **gate mechanics against this suite's scripted reviewer**. It does not prove clinical correctness, prompt-injection immunity, or authorization, and several spec requirements are attestation-only — the report's `attestations` block lists every one, including: tool code builds FHIR from validated capped inputs; the rendering is complete, not just present; no other approval path exists; unlisted tools follow the same gate; and persistence probing is point-sampled, so a write-then-rollback implementation racing the probes violates the spec but can evade detection. The report is deliberately scrub-clean — static detail strings only, no ids, endpoints, or error text — so it is safe to publish (check failures print their diagnostics to your terminal instead).
39
+
40
+ The suite versions against exactly one spec version per release (this release: spec v0.1 draft). The default result contract (JSON text with a boolean `saved` and the id) matches `@lastehr/mcp` and is non-normative in v0.1.
41
+
42
+ ## License
43
+
44
+ Apache-2.0. Part of [Last EHR](https://github.com/cbetz/last-ehr).
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, writeFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { createStdioConnector } from "./harness.js";
5
+ import { parseManifest } from "./manifest.js";
6
+ import { createRestProbe } from "./probe.js";
7
+ import { runConformance } from "./run.js";
8
+ function argValue(argv, flag) {
9
+ const index = argv.indexOf(flag);
10
+ const value = index >= 0 ? argv[index + 1] : undefined;
11
+ // A flag directly followed by another flag has no value; treating the
12
+ // next flag as one would silently misconfigure the run.
13
+ return value && !value.startsWith("--") ? value : undefined;
14
+ }
15
+ const SUITE_VERSION = createRequire(import.meta.url)("../package.json").version;
16
+ const HELP = `Approval-Gated Agent Writes on FHIR — conformance suite (spec v0.1 draft)
17
+
18
+ Usage:
19
+ awp-conformance --server "<command>" --manifest <awp-manifest.json> \\
20
+ --fhir-base-url <url> --confirm-synthetic [--report <path>]
21
+
22
+ --server Shell command that starts the MCP stdio server under
23
+ test (spawned fresh for every scenario).
24
+ --manifest Path to the implementer-supplied manifest declaring
25
+ each write tool's name, argument template, and where
26
+ its write lands. See examples/ in this package.
27
+ --fhir-base-url Base URL of the SAME FHIR store the server writes to;
28
+ the suite verifies side effects with its own reads.
29
+ Bearer auth: set AWP_FHIR_BEARER_TOKEN in the env.
30
+ --confirm-synthetic Required. The target must be a disposable synthetic
31
+ store: the suite creates and deletes resources.
32
+ --strict Count should-level audit checks (AIAST label, write
33
+ Provenance) toward the overall status.
34
+ --report Write the JSON report here (default: stdout only).
35
+
36
+ Passing proves gate mechanics against this suite's scripted reviewer. It
37
+ does not prove clinical correctness, prompt-injection immunity, or
38
+ authorization, and several spec requirements are attestation-only — see
39
+ the attestations block in the report.
40
+ `;
41
+ async function main() {
42
+ const argv = process.argv.slice(2);
43
+ if (argv.includes("--help") || argv.length === 0) {
44
+ process.stdout.write(HELP);
45
+ return;
46
+ }
47
+ const server = argValue(argv, "--server");
48
+ const manifestPath = argValue(argv, "--manifest");
49
+ const fhirBaseUrl = argValue(argv, "--fhir-base-url");
50
+ const reportPath = argValue(argv, "--report");
51
+ if (!server || !manifestPath || !fhirBaseUrl) {
52
+ process.stderr.write(HELP);
53
+ process.exitCode = 2;
54
+ return;
55
+ }
56
+ if (!argv.includes("--confirm-synthetic")) {
57
+ process.stderr.write("Refusing to run: pass --confirm-synthetic to state that the FHIR target is disposable and synthetic. The suite creates and deletes resources.\n");
58
+ process.exitCode = 2;
59
+ return;
60
+ }
61
+ const manifest = parseManifest(JSON.parse(readFileSync(manifestPath, "utf8")));
62
+ const report = await runConformance({
63
+ confirmSyntheticTarget: true,
64
+ connector: createStdioConnector(server),
65
+ probe: createRestProbe(fhirBaseUrl, {
66
+ bearerToken: process.env.AWP_FHIR_BEARER_TOKEN,
67
+ }),
68
+ manifest,
69
+ suiteVersion: SUITE_VERSION,
70
+ strict: argv.includes("--strict"),
71
+ });
72
+ for (const check of report.checks) {
73
+ const marker = check.status === "pass" ? "✓" : check.status === "fail" ? "✗" : "–";
74
+ process.stdout.write(`${marker} ${check.id} [${check.level}] ${check.status}\n`);
75
+ }
76
+ process.stdout.write(`\nstatus: ${report.status}\n`);
77
+ const serialized = JSON.stringify(report, null, 2);
78
+ if (reportPath) {
79
+ writeFileSync(reportPath, serialized);
80
+ process.stdout.write(`report: ${reportPath}\n`);
81
+ }
82
+ else {
83
+ process.stdout.write(`${serialized}\n`);
84
+ }
85
+ if (report.status !== "pass")
86
+ process.exitCode = 1;
87
+ }
88
+ main().catch((error) => {
89
+ // Terminal-only; the report itself never carries error text.
90
+ process.stderr.write(`awp-conformance failed: ${error instanceof Error ? `${error.name}: ${error.message}` : String(error)}\n`);
91
+ process.exitCode = 1;
92
+ });
@@ -0,0 +1,58 @@
1
+ import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
2
+ /**
3
+ * The scripted reviewer: each conformance scenario answers the
4
+ * implementation's elicitation exactly one way. Probing chart state
5
+ * INSIDE the reviewer (while the proposal is pending) is how the suite
6
+ * proves nothing persisted before a decision existed.
7
+ */
8
+ export type ElicitationRequest = {
9
+ message: string;
10
+ requestedSchema: {
11
+ type?: string;
12
+ properties?: Record<string, {
13
+ type?: string;
14
+ }>;
15
+ required?: string[];
16
+ };
17
+ };
18
+ export type ScriptedReviewer = (request: ElicitationRequest) => Promise<{
19
+ action: "accept";
20
+ content: Record<string, boolean>;
21
+ } | {
22
+ action: "decline";
23
+ } | {
24
+ action: "cancel";
25
+ }>;
26
+ export type ToolCallResult = {
27
+ isError: boolean;
28
+ text: string;
29
+ };
30
+ export type McpConnection = {
31
+ listToolNames(): Promise<string[]>;
32
+ callTool(name: string, args: Record<string, unknown>): Promise<ToolCallResult>;
33
+ /** Every elicitation the server sent over this connection, in order. */
34
+ elicitations: ElicitationRequest[];
35
+ close(): Promise<void>;
36
+ };
37
+ export type ConnectOptions = {
38
+ elicitation: boolean;
39
+ reviewer?: ScriptedReviewer;
40
+ };
41
+ /**
42
+ * One conformance scenario = one fresh connection (and, for stdio, a fresh
43
+ * server process): scenarios must not leak reviewer state into each other.
44
+ */
45
+ export type Connector = (options: ConnectOptions) => Promise<McpConnection>;
46
+ export declare function connectClient(transport: Transport, options: ConnectOptions): Promise<McpConnection>;
47
+ /**
48
+ * Spawn the implementer's server command per connection. The command runs
49
+ * through the platform shell so implementers can pass exactly what they
50
+ * run by hand ("node dist/server.js", "npx -y @lastehr/mcp", ...). stdout
51
+ * is the JSON-RPC channel; the child inherits the caller's environment.
52
+ *
53
+ * Closing a connection signals the shell child; a compound command
54
+ * (pipelines, backgrounded processes) can leave grandchildren running —
55
+ * prefer a command that execs a single server process.
56
+ */
57
+ export declare function createStdioConnector(serverCommand: string): Connector;
58
+ //# sourceMappingURL=harness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../src/harness.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAG/E;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAC/C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,kBAAkB,KACxB,OAAO,CACR;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GACtD;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,CACvB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/E,wEAAwE;IACxE,YAAY,EAAE,kBAAkB,EAAE,CAAC;IACnC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5E,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CAiDxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAkBrE"}
@@ -0,0 +1,70 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
+ import { ElicitRequestSchema } from "@modelcontextprotocol/sdk/types.js";
4
+ export async function connectClient(transport, options) {
5
+ const elicitations = [];
6
+ const client = new Client({ name: "awp-conformance", version: "0.1.0" }, { capabilities: options.elicitation ? { elicitation: {} } : {} });
7
+ if (options.elicitation) {
8
+ client.setRequestHandler(ElicitRequestSchema, async (request) => {
9
+ // URL-mode elicitation carries no schema; the decision-shape check
10
+ // treats an empty properties object as a failure, which is right —
11
+ // a URL-mode exchange is not a boolean decision request.
12
+ const requestedSchema = "requestedSchema" in request.params
13
+ ? request.params
14
+ .requestedSchema
15
+ : {};
16
+ const observed = {
17
+ message: request.params.message,
18
+ requestedSchema,
19
+ };
20
+ elicitations.push(observed);
21
+ if (!options.reviewer)
22
+ return { action: "decline" };
23
+ return options.reviewer(observed);
24
+ });
25
+ }
26
+ await client.connect(transport);
27
+ return {
28
+ elicitations,
29
+ async listToolNames() {
30
+ const { tools } = await client.listTools();
31
+ return tools.map((tool) => tool.name);
32
+ },
33
+ async callTool(name, args) {
34
+ const result = (await client.callTool({ name, arguments: args }, undefined,
35
+ // Reviewer deliberation is human-shaped even when scripted; the
36
+ // per-call probe reads inside the handler can be slow on remote
37
+ // stores.
38
+ { timeout: 120_000 }));
39
+ const text = result.content?.find((part) => part.type === "text")?.text ?? "";
40
+ return { isError: Boolean(result.isError), text };
41
+ },
42
+ async close() {
43
+ await client.close();
44
+ },
45
+ };
46
+ }
47
+ /**
48
+ * Spawn the implementer's server command per connection. The command runs
49
+ * through the platform shell so implementers can pass exactly what they
50
+ * run by hand ("node dist/server.js", "npx -y @lastehr/mcp", ...). stdout
51
+ * is the JSON-RPC channel; the child inherits the caller's environment.
52
+ *
53
+ * Closing a connection signals the shell child; a compound command
54
+ * (pipelines, backgrounded processes) can leave grandchildren running —
55
+ * prefer a command that execs a single server process.
56
+ */
57
+ export function createStdioConnector(serverCommand) {
58
+ const shell = process.platform === "win32"
59
+ ? { command: "cmd.exe", args: ["/c", serverCommand] }
60
+ : { command: "/bin/sh", args: ["-c", serverCommand] };
61
+ return async (options) => {
62
+ const transport = new StdioClientTransport({
63
+ command: shell.command,
64
+ args: shell.args,
65
+ env: Object.fromEntries(Object.entries(process.env).filter((entry) => typeof entry[1] === "string")),
66
+ stderr: "inherit",
67
+ });
68
+ return connectClient(transport, options);
69
+ };
70
+ }
@@ -0,0 +1,6 @@
1
+ export { connectClient, createStdioConnector, type ConnectOptions, type Connector, type ElicitationRequest, type McpConnection, type ScriptedReviewer, type ToolCallResult, } from "./harness.js";
2
+ export { parseDefaultResult, parseManifest, substituteArguments, type ConformanceManifest, type WriteToolManifest, } from "./manifest.js";
3
+ export { createRestProbe, type FhirProbe, type FhirResource, } from "./probe.js";
4
+ export { ATTESTATIONS, CONFORMANCE_REPORT_SCHEMA_VERSION, SPEC, type CheckId, type CheckLevel, type ConformanceCheck, type ConformanceReport, } from "./report.js";
5
+ export { CONFORMANCE_TAG_SYSTEM, runConformance, type RunConformanceOptions, } from "./run.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,KAAK,SAAS,EACd,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,YAAY,EACZ,iCAAiC,EACjC,IAAI,EACJ,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { connectClient, createStdioConnector, } from "./harness.js";
2
+ export { parseDefaultResult, parseManifest, substituteArguments, } from "./manifest.js";
3
+ export { createRestProbe, } from "./probe.js";
4
+ export { ATTESTATIONS, CONFORMANCE_REPORT_SCHEMA_VERSION, SPEC, } from "./report.js";
5
+ export { CONFORMANCE_TAG_SYSTEM, runConformance, } from "./run.js";
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The manifest is the driver interface: the implementer declares each
4
+ * write tool's name, a valid argument template, and how to find the write
5
+ * on the chart. The suite never guesses tool semantics — guessing would
6
+ * make a pass meaningless.
7
+ *
8
+ * Template placeholders in argument string values:
9
+ * - "$PATIENT_ID" (exact) — replaced with the synthetic patient's id.
10
+ * - "$NONCE" (exact) — replaced with a run-unique NUMBER (for numeric
11
+ * fields like an observation value).
12
+ * - "$NONCE" (embedded in longer text) — replaced textually, keeping the
13
+ * value a string (for free-text fields).
14
+ */
15
+ declare const writeToolSchema: z.ZodObject<{
16
+ name: z.ZodString;
17
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
18
+ creates: z.ZodString;
19
+ patientReferencePath: z.ZodString;
20
+ nonceField: z.ZodString;
21
+ }, z.core.$strip>;
22
+ declare const manifestSchema: z.ZodObject<{
23
+ writeTools: z.ZodArray<z.ZodObject<{
24
+ name: z.ZodString;
25
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
26
+ creates: z.ZodString;
27
+ patientReferencePath: z.ZodString;
28
+ nonceField: z.ZodString;
29
+ }, z.core.$strip>>;
30
+ parseResult: z.ZodDefault<z.ZodLiteral<"default">>;
31
+ }, z.core.$strip>;
32
+ export type WriteToolManifest = z.infer<typeof writeToolSchema>;
33
+ export type ConformanceManifest = z.infer<typeof manifestSchema>;
34
+ export declare function parseManifest(raw: unknown): ConformanceManifest;
35
+ export type SubstitutedArguments = {
36
+ args: Record<string, unknown>;
37
+ nonce: number;
38
+ };
39
+ export declare function substituteArguments(tool: WriteToolManifest, patientId: string, nonce: number): SubstitutedArguments;
40
+ /**
41
+ * The default result contract: the tool returns JSON text whose object has
42
+ * a boolean `saved` and, when saved, the server-assigned id (the shape
43
+ * @lastehr/mcp ships; declared non-normative in spec v0.1).
44
+ */
45
+ export declare function parseDefaultResult(text: string): {
46
+ saved: boolean | undefined;
47
+ id: string | undefined;
48
+ };
49
+ export {};
50
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,eAAe;;;;;;iBAYnB,CAAC;AAEH,QAAA,MAAM,cAAc;;;;;;;;;iBAIlB,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAChE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEjE,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,mBAAmB,CAE/D;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,iBAAiB,EACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,oBAAoB,CActB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG;IAChD,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;CACxB,CAUA"}
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The manifest is the driver interface: the implementer declares each
4
+ * write tool's name, a valid argument template, and how to find the write
5
+ * on the chart. The suite never guesses tool semantics — guessing would
6
+ * make a pass meaningless.
7
+ *
8
+ * Template placeholders in argument string values:
9
+ * - "$PATIENT_ID" (exact) — replaced with the synthetic patient's id.
10
+ * - "$NONCE" (exact) — replaced with a run-unique NUMBER (for numeric
11
+ * fields like an observation value).
12
+ * - "$NONCE" (embedded in longer text) — replaced textually, keeping the
13
+ * value a string (for free-text fields).
14
+ */
15
+ const writeToolSchema = z.object({
16
+ name: z.string().min(1).max(128),
17
+ arguments: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
18
+ /** Resource type the approved write creates, e.g. "Observation". */
19
+ creates: z.string().min(1).max(64),
20
+ /** Dot path of the patient reference in the created resource. */
21
+ patientReferencePath: z.string().min(1).max(128),
22
+ /** Argument key whose (nonced) value identifies this run's write. */
23
+ nonceField: z.string().min(1).max(64),
24
+ });
25
+ const manifestSchema = z.object({
26
+ writeTools: z.array(writeToolSchema).min(1),
27
+ /** v0.1 supports only the default result parser: JSON text {saved, id?}. */
28
+ parseResult: z.literal("default").default("default"),
29
+ });
30
+ export function parseManifest(raw) {
31
+ return manifestSchema.parse(raw);
32
+ }
33
+ export function substituteArguments(tool, patientId, nonce) {
34
+ const args = {};
35
+ for (const [key, value] of Object.entries(tool.arguments)) {
36
+ if (value === "$PATIENT_ID") {
37
+ args[key] = patientId;
38
+ }
39
+ else if (value === "$NONCE") {
40
+ args[key] = nonce;
41
+ }
42
+ else if (typeof value === "string" && value.includes("$NONCE")) {
43
+ args[key] = value.replaceAll("$NONCE", String(nonce));
44
+ }
45
+ else {
46
+ args[key] = value;
47
+ }
48
+ }
49
+ return { args, nonce };
50
+ }
51
+ /**
52
+ * The default result contract: the tool returns JSON text whose object has
53
+ * a boolean `saved` and, when saved, the server-assigned id (the shape
54
+ * @lastehr/mcp ships; declared non-normative in spec v0.1).
55
+ */
56
+ export function parseDefaultResult(text) {
57
+ try {
58
+ const parsed = JSON.parse(text);
59
+ return {
60
+ saved: typeof parsed.saved === "boolean" ? parsed.saved : undefined,
61
+ id: typeof parsed.id === "string" ? parsed.id : undefined,
62
+ };
63
+ }
64
+ catch {
65
+ return { saved: undefined, id: undefined };
66
+ }
67
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Minimal FHIR REST probe the harness uses to verify side effects with its
3
+ * own eyes: chart state before and after each scripted decision, never the
4
+ * implementation's word for it. Deliberately tiny and dependency-free —
5
+ * search, create, read, delete — and structured params only.
6
+ */
7
+ export type FhirResource = {
8
+ resourceType: string;
9
+ id?: string;
10
+ [key: string]: unknown;
11
+ };
12
+ export interface FhirProbe {
13
+ searchResources(resourceType: string, params: Record<string, string>): Promise<FhirResource[]>;
14
+ createResource(resource: FhirResource): Promise<FhirResource>;
15
+ readResource(resourceType: string, id: string): Promise<FhirResource>;
16
+ deleteResource(resourceType: string, id: string): Promise<void>;
17
+ }
18
+ /** Bearer auth comes from the environment so tokens never hit argv. */
19
+ export declare function createRestProbe(baseUrl: string, options?: {
20
+ bearerToken?: string;
21
+ }): FhirProbe;
22
+ //# sourceMappingURL=probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../src/probe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,eAAe,CACb,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAC3B,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9D,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACtE,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GACrC,SAAS,CA4DX"}