@su-sws/synthetic-web-team-mcp 0.2.7 → 0.2.9

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/README.md CHANGED
@@ -17,13 +17,19 @@ server will not start, nothing else stops working.
17
17
 
18
18
  ## Tools
19
19
 
20
- | Tool | What it is for |
21
- |---|---|
22
- | `sws_get_standard` | Fetch a policy, pattern, recipe, or fragment. Accepts synonyms: `footer`, `wcag`, `sso`, `cookies`, `tokens`. Call with no topic to list everything |
23
- | `sws_footer_html` | Correct Stanford Global Footer markup, generated from the byte-exact contract |
24
- | `sws_check` | The advisory compliance report, structured, with a score out of 100 |
25
- | `sws_decanter_token` | Resolve a Decanter token from the CSS of the version actually installed |
26
- | `sws_scaffold` | Install the contract, standards and per-site record into a project. **Dry run by default.** Project scope only — the skills install once per machine, outside this tool |
20
+ | Tool | What it is for | Writes |
21
+ |---|---|---|
22
+ | `sws_get_standard` | Fetch a policy, pattern, recipe, or fragment. Accepts synonyms: `footer`, `wcag`, `sso`, `cookies`, `tokens`. Call with no topic to list everything | Nothing |
23
+ | `sws_footer_html` | Correct Stanford Global Footer markup, generated from the byte-exact contract | Nothing |
24
+ | `sws_check` | The advisory compliance report, structured, with a score out of 100 | Nothing |
25
+ | `sws_decanter_token` | Resolve a Decanter token from the CSS of the version actually installed | Nothing |
26
+ | `sws_scaffold` | Install the contract, standards and per-site record into a project. **Dry run by default.** Project scope only — the skills install once per machine, outside this tool | The project install, only with `write: true` |
27
+
28
+ Each tool carries MCP annotations that say the same thing, so a client can tell
29
+ what is safe to run without asking. The four that write nothing are marked
30
+ read-only. `sws_check` is one of them because it runs `sws doctor --no-history`,
31
+ so a report a model asked for does not move your "since your last local run".
32
+ `sws_scaffold` is marked as a tool that writes.
27
33
 
28
34
  Documents are also exposed as resources at `sws://standard/<path>`, for clients
29
35
  that support them. Tools are the portable surface; resources are the idiomatic
@@ -45,10 +51,24 @@ separate service. That is also why this project does not depend on
45
51
 
46
52
  ## Design notes
47
53
 
48
- **`sws_check` and `sws_scaffold` shell out** to `@su-sws/sws-cli` and
49
- `@su-sws/synthetic-web-team` rather than reimplementing them. One implementation
50
- means the MCP result and the terminal result can never disagree, which is the
51
- drift this project is organised against. The cost is a process spawn.
54
+ **`sws_check` and `sws_scaffold` shell out** to the `sws` CLI and the wizard
55
+ rather than reimplementing them. One implementation means the MCP result and
56
+ the terminal result can never disagree, which is the drift this project is
57
+ organised against. The cost is a process spawn.
58
+
59
+ **Both ship inside `@su-sws/synthetic-web-team`**, which this package depends
60
+ on, and that is the only name they are looked up by. `src/locate.mjs` finds the
61
+ package, then reads its `bin` map for the two scripts. It works the same way in
62
+ three places: this repository, a project that installed both packages, and the
63
+ npx cache. `scripts/validate-packed.mjs` installs both tarballs into an empty
64
+ project and calls every tool over stdio, because a lookup that only works in
65
+ this repository passes every test that runs in this repository.
66
+
67
+ **The standards are found the way the CLI finds them.** `--standards <dir>` if
68
+ it was passed, then the project's `.sws/standards`, then its `standards/`, then
69
+ the copy inside `@su-sws/synthetic-web-team`. So `sws_get_standard` and
70
+ `sws_footer_html` quote the copy `sws_check` judged against. The choice is made
71
+ once, when the server starts, for the directory in `--root`.
52
72
 
53
73
  **Nothing is written to stdout except protocol frames.** stdout *is* the
54
74
  transport; a stray `console.log` corrupts the stream and the client reports a
package/bin/sws-mcp.mjs CHANGED
@@ -18,7 +18,10 @@ if (args.includes('--help') || args.includes('-h')) {
18
18
 
19
19
  --root <dir> Default project directory for sws_check and sws_scaffold.
20
20
  Defaults to the working directory.
21
- --standards <dir> Standards directory. Defaults to the copy bundled in @su-sws/synthetic-web-team.
21
+ --standards <dir> Standards directory. Defaults to the project's own copy,
22
+ .sws/standards under --root, when it has one, and
23
+ otherwise to the copy in @su-sws/synthetic-web-team.
24
+ That is the order the sws CLI uses.
22
25
 
23
26
  Add to an MCP client config:
24
27
 
@@ -33,7 +36,7 @@ if (args.includes('--help') || args.includes('-h')) {
33
36
 
34
37
  const { server, index, contentRoot } = build({
35
38
  root: flag('--root') ?? process.cwd(),
36
- standards: flag('--standards') ?? undefined,
39
+ standards: flag('--standards'),
37
40
  });
38
41
 
39
42
  if (!index.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-sws/synthetic-web-team-mcp",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "MCP server exposing Stanford Web Services standards, the Global Footer contract, Decanter tokens, and the advisory compliance report to any MCP client.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@modelcontextprotocol/sdk": "^1.30.0",
19
- "@su-sws/synthetic-web-team": "^0.2.7",
19
+ "@su-sws/synthetic-web-team": "^0.2.9",
20
20
  "yaml": "^2.8.1",
21
21
  "zod": "^4.1.13"
22
22
  },
package/src/locate.mjs ADDED
@@ -0,0 +1,101 @@
1
+ // Where the other package is, and the three things this server takes from it.
2
+ //
3
+ // This server is published on its own and depends on
4
+ // @su-sws/synthetic-web-team, which carries the standards, the sws CLI and the
5
+ // wizard. Everything is found through that public name and the files it really
6
+ // ships, because that is the only name that exists once the packages are
7
+ // installed.
8
+ //
9
+ // The bug this replaces: sws_check and sws_scaffold resolved the workspace
10
+ // names of the CLI and the wizard. Those packages are private. They exist only
11
+ // as links in this repository's node_modules, so both tools worked here and
12
+ // failed in every install.
13
+ //
14
+ // It has to hold in three layouts:
15
+ //
16
+ // 1. This repository. node_modules/@su-sws/synthetic-web-team links to the
17
+ // repository root, and a checkout laid out the same way is the fallback.
18
+ // 2. A project that installed both packages. They sit side by side in the
19
+ // project's node_modules.
20
+ // 3. `npx -y @su-sws/synthetic-web-team-mcp`. The same, inside the npx cache.
21
+
22
+ import { existsSync, readFileSync } from 'node:fs';
23
+ import { createRequire } from 'node:module';
24
+ import { dirname, join, resolve } from 'node:path';
25
+ import { fileURLToPath } from 'node:url';
26
+
27
+ const CORE = '@su-sws/synthetic-web-team';
28
+ const HERE = dirname(fileURLToPath(import.meta.url));
29
+
30
+ function manifest(dir) {
31
+ try { return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')); }
32
+ catch { return null; }
33
+ }
34
+
35
+ let core = null;
36
+
37
+ /** The directory of the installed @su-sws/synthetic-web-team, or null. */
38
+ export function corePackage() {
39
+ if (core) return core;
40
+ const candidates = [];
41
+
42
+ // Node's own resolution, which is right for layouts 1 to 3.
43
+ try {
44
+ candidates.push(dirname(createRequire(import.meta.url).resolve(`${CORE}/package.json`)));
45
+ } catch { /* not resolvable; keep looking */ }
46
+
47
+ // The same walk by hand. Resolution refuses a deep path once a package
48
+ // declares an `exports` map, and that must not take two tools down with it.
49
+ for (let d = HERE; ; d = dirname(d)) {
50
+ candidates.push(join(d, 'node_modules', ...CORE.split('/')));
51
+ if (dirname(d) === d) break;
52
+ }
53
+
54
+ // A checkout with no install: packages/mcp/src is three levels below the root.
55
+ candidates.push(resolve(HERE, '..', '..', '..'));
56
+
57
+ // The name is checked so that a neighbouring folder is never mistaken for it.
58
+ core = candidates.find((c) => manifest(c)?.name === CORE) ?? null;
59
+ return core;
60
+ }
61
+
62
+ // A script the package ships. Its own `bin` map is asked first, because that is
63
+ // what the package promises; the path it has today is the fallback.
64
+ function script(name, today) {
65
+ const dir = corePackage();
66
+ if (!dir) return null;
67
+ for (const rel of [manifest(dir)?.bin?.[name], today]) {
68
+ if (typeof rel === 'string' && existsSync(join(dir, rel))) return join(dir, rel);
69
+ }
70
+ return null;
71
+ }
72
+
73
+ /** The sws CLI entry point, or null. */
74
+ export const cliPath = () => script('sws', 'packages/cli/bin/sws.mjs');
75
+
76
+ /** The wizard entry point, or null. */
77
+ export const wizardPath = () => script('synthetic-web-team', 'packages/wizard/bin/wizard.mjs');
78
+
79
+ /** The standards that ship inside the package, or null. */
80
+ export function bundledStandards() {
81
+ const dir = corePackage();
82
+ return dir ? join(dir, 'standards') : null;
83
+ }
84
+
85
+ /**
86
+ * The standards for a project at `root`, by the rule the CLI uses
87
+ * (packages/cli/src/standards.mjs): an explicit directory, then the project's
88
+ * `.sws/standards`, then its `standards/`, then the bundled copy. Every
89
+ * candidate but the explicit one must carry the Global Footer contract, the one
90
+ * file every copy of ours has, so a team's own `standards/` folder never wins.
91
+ *
92
+ * The same rule in both places is the point: sws_check runs the CLI, so
93
+ * sws_get_standard and sws_footer_html have to quote the copy it judged against.
94
+ */
95
+ export function findStandards(root, { explicit = null } = {}) {
96
+ if (explicit) return resolve(explicit);
97
+ for (const c of [join(root, '.sws', 'standards'), join(root, 'standards'), bundledStandards()]) {
98
+ if (c && existsSync(join(c, 'fragments', 'global-footer.yml'))) return c;
99
+ }
100
+ return null;
101
+ }
package/src/scaffold.mjs CHANGED
@@ -12,23 +12,15 @@
12
12
 
13
13
  import { existsSync } from 'node:fs';
14
14
  import { execFileSync } from 'node:child_process';
15
- import { createRequire } from 'node:module';
15
+ import { wizardPath } from './locate.mjs';
16
16
 
17
17
  const ok = (text) => ({ content: [{ type: 'text', text }] });
18
18
  const problem = (text) => ({ content: [{ type: 'text', text }], isError: true });
19
19
 
20
- function wizardPath() {
21
- try {
22
- return createRequire(import.meta.url).resolve('@su-sws/wizard/bin/wizard.mjs');
23
- } catch {
24
- const guess = new URL('../../wizard/bin/wizard.mjs', import.meta.url).pathname;
25
- return existsSync(guess) ? guess : null;
26
- }
27
- }
28
-
29
20
  export function scaffold(defaultRoot, { path, answers, editors, write = false, mode = 'new' } = {}) {
21
+ // The wizard ships inside @su-sws/synthetic-web-team. See locate.mjs.
30
22
  const bin = wizardPath();
31
- if (!bin) return problem('Could not locate the wizard. Install @su-sws/synthetic-web-team.');
23
+ if (!bin) return problem('Could not locate the wizard. Install @su-sws/synthetic-web-team next to this server.');
32
24
 
33
25
  const root = path || defaultRoot;
34
26
  if (!existsSync(root)) return problem(`Path does not exist: ${root}`);
@@ -47,7 +39,7 @@ export function scaffold(defaultRoot, { path, answers, editors, write = false, m
47
39
 
48
40
  let out;
49
41
  try {
50
- out = execFileSync('node', args, { encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });
42
+ out = execFileSync(process.execPath, args, { encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });
51
43
  } catch (err) {
52
44
  // Exit 2 is bad input and still prints JSON on stdout, so prefer that to the
53
45
  // exception message.
package/src/server.mjs CHANGED
@@ -31,27 +31,35 @@
31
31
  import { readFileSync } from 'node:fs';
32
32
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
33
33
  import { z } from 'zod';
34
- import { createRequire } from 'node:module';
35
- import { existsSync } from 'node:fs';
36
- import { dirname, join } from 'node:path';
37
34
  import { indexStandards, getStandard, footerHtml, check, decanterToken } from './tools.mjs';
38
35
  import { scaffold } from './scaffold.mjs';
36
+ import { findStandards } from './locate.mjs';
39
37
 
40
38
  const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
41
39
 
42
- // Standards ship inside @su-sws/synthetic-web-team. Resolve that package, then fall back to the
43
- // repository layout so this works from a checkout with no install.
44
- const bundledStandards = (() => {
45
- try {
46
- const p = createRequire(import.meta.url).resolve('@su-sws/synthetic-web-team/package.json');
47
- const c = join(dirname(p), 'standards');
48
- if (existsSync(c)) return c;
49
- } catch { /* not installed */ }
50
- const dev = new URL('../../../standards', import.meta.url).pathname;
51
- return existsSync(dev) ? dev : null;
52
- })();
53
-
54
- export function build({ root = process.cwd(), standards = bundledStandards } = {}) {
40
+ // What each tool does to the project, told to the client as annotations. A
41
+ // client uses them to decide what it may run without asking, so they describe
42
+ // what happens on disk, not what the tool is for.
43
+ //
44
+ // Nothing here reaches the network, so every tool is closed-world.
45
+ //
46
+ // Four tools only read. sws_check is one of them because it runs `sws doctor`
47
+ // with --no-history: without that flag doctor records each run in the
48
+ // project's .sws/score-history.json, and the tool could not claim this.
49
+ const READS = { readOnlyHint: true, openWorldHint: false };
50
+ // sws_scaffold with write=true rewrites the contract block and the vendored
51
+ // standards. Running it twice leaves the same result as running it once.
52
+ const WRITES = { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false };
53
+
54
+ /**
55
+ * `standards` is an explicit directory, or null to look the way the CLI does:
56
+ * the project's own copy when `root` has one, else the copy that ships in
57
+ * @su-sws/synthetic-web-team. See locate.mjs. It is decided once, here, so a
58
+ * project that vendors its standards while the server is running is served
59
+ * from its own copy after the next start.
60
+ */
61
+ export function build({ root = process.cwd(), standards: explicit = null } = {}) {
62
+ const standards = findStandards(root, { explicit });
55
63
  const server = new McpServer(
56
64
  { name: 'sws', version: pkg.version },
57
65
  {
@@ -85,6 +93,7 @@ export function build({ root = process.cwd(), standards = bundledStandards } = {
85
93
  'Call with no topic to list every available topic. Accepts common synonyms such as ' +
86
94
  '"footer", "wcag", "sso", "cookies", "tokens".',
87
95
  inputSchema: { topic: z.string().optional().describe('Topic or path, e.g. "minweb", "accessibility", "footer", "astro-static". Omit to list all.') },
96
+ annotations: READS,
88
97
  }, async ({ topic }) => getStandard(index, topic));
89
98
 
90
99
  // Resources too, for clients that support them. Same content, addressed as
@@ -108,10 +117,16 @@ export function build({ root = process.cwd(), standards = bundledStandards } = {
108
117
  'altered, reordered, or added to. Use this instead of writing footer markup yourself — ' +
109
118
  'two of its ten URLs are commonly gotten wrong.',
110
119
  inputSchema: { unit: z.string().optional().describe('Unit name, only so the response can tell you where unit links actually belong. The Global Footer takes no unit content.') },
120
+ annotations: READS,
111
121
  }, async ({ unit }) => footerHtml(standards, { unit }));
112
122
 
113
123
  // ---- the advisory report ----------------------------------------------
114
124
 
125
+ // A directory this server was started with is passed on to the CLI, so the
126
+ // report is judged against the copy the other tools quote. With none, the CLI
127
+ // looks for itself, by the same rule.
128
+ const passedOn = explicit ? standards : undefined;
129
+
115
130
  server.registerTool('sws_check', {
116
131
  title: 'Run the Stanford compliance report',
117
132
  description:
@@ -120,12 +135,13 @@ export function build({ root = process.cwd(), standards = bundledStandards } = {
120
135
  'accessibility, SEO, MinWeb ownership, secrets, and the performance budget. ' +
121
136
  'Never fails: a check that cannot run reports "unknown" and withholds its points ' +
122
137
  'rather than passing. Build the site first, and run sws a11y and sws perf, for a ' +
123
- 'complete result.',
138
+ 'complete result. Read-only: it writes nothing to the project.',
124
139
  inputSchema: {
125
140
  path: z.string().optional().describe('Project directory. Defaults to the server working directory.'),
126
141
  standards: z.string().optional().describe('Standards directory, if the project does not vendor one.'),
127
142
  },
128
- }, async ({ path, standards: std }) => check(root, { path, standards: std }));
143
+ annotations: READS,
144
+ }, async ({ path, standards: std }) => check(root, { path, standards: std ?? passedOn }));
129
145
 
130
146
  // ---- Decanter tokens, read from the installed package ------------------
131
147
 
@@ -140,6 +156,7 @@ export function build({ root = process.cwd(), standards = bundledStandards } = {
140
156
  query: z.string().optional().describe('Token fragment or value, e.g. "cardinal", "fog", "#8C1515", "font-size".'),
141
157
  path: z.string().optional().describe('Project directory containing node_modules/decanter.'),
142
158
  },
159
+ annotations: READS,
143
160
  }, async ({ query, path }) => decanterToken(root, { query, path }));
144
161
 
145
162
  // ---- scaffolding, dry by default --------------------------------------
@@ -169,6 +186,7 @@ export function build({ root = process.cwd(), standards = bundledStandards } = {
169
186
  payments: z.boolean().optional(), regulated: z.boolean().optional(),
170
187
  }).optional().describe('Project facts. The four booleans derive the compliance tier. Ask the user for owner names and emails; never invent them.'),
171
188
  },
189
+ annotations: WRITES,
172
190
  }, async (args) => scaffold(root, args));
173
191
 
174
192
  return { server, index, contentRoot: standards };
package/src/tools.mjs CHANGED
@@ -8,8 +8,8 @@
8
8
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
9
9
  import { join, relative, extname } from 'node:path';
10
10
  import { execFileSync } from 'node:child_process';
11
- import { createRequire } from 'node:module';
12
11
  import YAML from 'yaml';
12
+ import { cliPath } from './locate.mjs';
13
13
 
14
14
  const ok = (text) => ({ content: [{ type: 'text', text }] });
15
15
  const problem = (text) => ({ content: [{ type: 'text', text }], isError: true });
@@ -148,34 +148,38 @@ ${(c.copyright?.lines ?? []).map((l) => ` <span>${esc(l)}</span>`).join('\n')}
148
148
  // two implementations of a compliance score.
149
149
  // --------------------------------------------------------------------------
150
150
 
151
- function cliPath() {
152
- try {
153
- const req = createRequire(import.meta.url);
154
- return req.resolve('@su-sws/sws-cli/bin/sws.mjs');
155
- } catch {
156
- // Workspace layout, when exports are not resolvable from here.
157
- const guess = new URL('../../cli/bin/sws.mjs', import.meta.url).pathname;
158
- return existsSync(guess) ? guess : null;
159
- }
160
- }
161
-
162
151
  export function check(defaultRoot, { path, standards } = {}) {
152
+ // The CLI ships inside @su-sws/synthetic-web-team. See locate.mjs.
163
153
  const bin = cliPath();
164
- if (!bin) return problem('Could not locate the sws CLI. Install @su-sws/sws-cli.');
154
+ if (!bin) return problem('Could not locate the sws CLI. Install @su-sws/synthetic-web-team next to this server.');
165
155
  const cwd = path ? path : defaultRoot;
166
156
  if (!existsSync(cwd)) return problem(`Path does not exist: ${cwd}`);
167
157
 
168
- const args = ['doctor', '--format', 'json', '--no-publish', '--no-summary'];
158
+ // --no-history: a report a model asked for must not move the person's "since
159
+ // your last local run", and must not leave a file in a project that has not
160
+ // ignored it. With it, this tool writes nothing, which is what its read-only
161
+ // annotation promises.
162
+ const args = ['doctor', '--format', 'json', '--no-publish', '--no-summary', '--no-history'];
169
163
  if (standards) args.push('--standards', standards);
170
164
 
165
+ // `doctor`, not `check`: doctor always exits 0, so a compliance finding can
166
+ // never look like a tool failure to the model. The Node that runs this server
167
+ // runs the CLI too, so nothing depends on `node` being on PATH.
168
+ const run = (a) => execFileSync(process.execPath, [bin, ...a], {
169
+ cwd, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024,
170
+ env: { ...process.env, NO_COLOR: '1' },
171
+ });
172
+
171
173
  let out;
172
174
  try {
173
- // `doctor`, not `check`: doctor always exits 0, so a compliance finding can
174
- // never look like a tool failure to the model.
175
- out = execFileSync('node', [bin, ...args], {
176
- cwd, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024,
177
- env: { ...process.env, NO_COLOR: '1' },
178
- });
175
+ try { out = run(args); }
176
+ catch (err) {
177
+ // A CLI from before --no-history refuses the flag. This package depends
178
+ // on a release that has it, so that takes a mismatched install. A report
179
+ // that records itself still beats no report, so ask again without it.
180
+ if (!/Unknown option '--no-history'/.test(String(err.stderr ?? ''))) throw err;
181
+ out = run(args.filter((a) => a !== '--no-history'));
182
+ }
179
183
  } catch (err) {
180
184
  return problem(`sws could not run in ${cwd}: ${(err.stderr || err.message || '').toString().slice(0, 600)}`);
181
185
  }