@pipeworx/mcp-guam-code 0.0.0-stage → 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mojibake Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,275 @@
1
- # Temporary Holding Version
1
+ # @pipeworx/guam-code
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Guam Code Annotated (GCA) — Guam territorial statutes, by citation and by
4
+ topic/keyword search. Keyless.
5
+
6
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1763+ live data sources. This is an independent, unofficial integration — not affiliated with, endorsed by, or published by the upstream provider.
7
+
8
+ ## Tools
9
+
10
+ - `gu_statute(citation, title?)` — full text of a GCA section by citation
11
+ ("9 GCA 16.30" is Aggravated Murder Defined; "21 GCA 33101" is who may
12
+ take an acknowledgment of a deed). Resolves the citation to its one
13
+ chapter PDF, fetches it live, and extracts the text. `title` is only
14
+ needed if not already embedded in `citation`.
15
+ - `gu_search(query, title?, limit?)` — topic/keyword search over section and
16
+ chapter catchlines (not full statutory prose — see below), optionally
17
+ restricted to one Title (1-22).
18
+
19
+ ## Auth
20
+
21
+ Keyless.
22
+
23
+ ## Source and shape
24
+
25
+ The Compiler of Laws (Judiciary of Guam, `col.guamcourts.gov`) publishes the
26
+ GCA as ~800 per-CHAPTER PDFs, linked from one static HTML page: 22
27
+ collapsible Title panels, each listing its Chapters. There is no per-title
28
+ listing, no search API, and no site-wide section index (confirmed live) —
29
+ the same gap `mcps/north-dakota-code` hit for the Century Code. That page is
30
+ baked ONCE (title/chapter/catchline/PDF URL) by `scripts/bake-index.mjs`.
31
+
32
+ Unlike North Dakota, the GCA index page does not also enumerate every
33
+ section. But every sampled chapter PDF opens with its own embedded table of
34
+ contents — a run of `§ <chapter>.<nn>. Catchline.` headings — so
35
+ `scripts/bake-sections.mjs` fetches all ~800 chapter PDFs once more and
36
+ bakes a section-level catchline index (15,760 rows) from that TOC block.
37
+ `gu_search` reads it; `gu_statute` never trusts it for the text it
38
+ returns — it re-derives section boundaries fresh from the live PDF on every
39
+ call.
40
+
41
+ ### Refresh path
42
+
43
+ Re-run both whenever the Compiler of Laws amends the GCA enough to be worth
44
+ re-baking (run the chapter index first — the section bake reads it):
45
+
46
+ ```
47
+ node mcps/guam-code/scripts/bake-index.mjs > mcps/guam-code/src/gu-index-data.ts
48
+ node --experimental-strip-types mcps/guam-code/scripts/bake-sections.mjs > mcps/guam-code/src/gu-section-data.ts
49
+ ```
50
+
51
+ The section bake needs `--experimental-strip-types` because it imports the
52
+ pack's own TypeScript extractor directly (no tsx/ts-node dependency in this
53
+ repo) — nothing at runtime needs that flag, only this one offline script.
54
+ Budget a few minutes: ~800 HTTP fetches at modest concurrency, as a courtesy
55
+ to `col.guamcourts.gov` rather than because it rate-limits.
56
+
57
+ Both baked modules are combined by `src/gu-baked-data.ts` (a plain
58
+ re-export) into the ONE data module `workers/gateway/src/pack-baked-indexes.json`
59
+ points at for this pack — the gateway uploads its exports to KV at deploy
60
+ and injects them as `args._bakedIndex`, never as a module-scope import (see
61
+ `index.ts`'s `ensureIndex`; fleet #2754 took the gateway down the one time a
62
+ baked table was value-imported into every isolate).
63
+
64
+ ## Two citation conventions, both real
65
+
66
+ Newer, recodified titles (9 GCA, the Criminal & Correctional Code, adapted
67
+ from the 1977 Model Penal Code) cite "chapter.section" with a dot — "9 GCA §
68
+ 16.30" is Aggravated Murder. Older titles (e.g. 21 GCA Ch. 33, Proof and
69
+ Acknowledgments of Instruments) concatenate chapter and a zero-padded
70
+ section number with no separator — "21 GCA § 33101" is chapter 33, section
71
+ 101. `gu_statute` accepts either form (see `parseGuCitation` in
72
+ `src/index.ts`). The chapter/section boundary for the no-dot form is
73
+ genuinely ambiguous from the digit string alone (chapter numbers vary in
74
+ length); it is resolved by picking the longest known chapter number, for the
75
+ given Title, that is a literal prefix of the citation — correct in every
76
+ case sampled.
77
+
78
+ ## `shared/src/pdf-text.ts` needed real fixes, forked pack-local instead
79
+
80
+ Guam's chapter PDFs defeated the shared extractor in ways it did not yet
81
+ handle, and this pack was built the same week another pack (#2884, New
82
+ Mexico) was independently editing that shared file — so the fixes live in
83
+ `src/gu-pdf-extract.ts`, a pack-local fork of `shared/src/pdf-text.ts`, with
84
+ a loud header comment for whoever next touches the shared extractor to fold
85
+ them in (nothing about them is Guam-specific):
86
+
87
+ 1. **Literal strings weren't routed through the font decoder.** Guam's
88
+ producer (Neevia Document Converter, from Word) writes some non-WinAnsi
89
+ subset fonts' text as parenthesized LITERAL strings (`(abc)Tj`) rather
90
+ than hex (`<...>Tj`). The shared extractor's `decodeRun` passes a literal
91
+ run through unchanged — correct for WinAnsi, but for these fonts the raw
92
+ bytes are a tiny, arbitrary code space meaningful only via the font's own
93
+ `/ToUnicode` CMap, which the shared code already has the machinery for
94
+ (built for North Dakota) but only wires to the HEX-string path. Confirmed
95
+ live: unfixed, `§ 16.10` extracted as control-character noise; fixed, it
96
+ reads correctly.
97
+ 2. **A declared `/Length` a few bytes long.** Several older chapter PDFs
98
+ ("MS Word for Windows Document" producer — an earlier era than the
99
+ Neevia-converted ones above) declare a `/Length` 1+ bytes longer than
100
+ their actual deflate stream. Python's zlib tolerates the trailing byte
101
+ silently; Node/Workers' strict `DecompressionStream` throws
102
+ `ERR_TRAILING_JUNK_AFTER_STREAM_END`. Retried with the stream's tail
103
+ trimmed a byte at a time (up to 4) before giving up.
104
+ 3. **A quote-glyph CMap that is wrong in the source file.** One embedded
105
+ symbol font per chapter PDF (`...+WPTypographicSymbols`, used only for
106
+ curly quotes) carries a `/ToUnicode` CMap that maps its two codes to
107
+ U+0041 ('A') and U+0040 ('@') instead of the left/right curly quote it
108
+ visually renders as. Confirmed by eye: "ADirector of Public Safety@" in
109
+ raw extraction is "“Director of Public Safety”" with those two codes
110
+ substituted back — the obviously intended reading, reproduced by any PDF
111
+ viewer's own copy-paste. Overridden by font name, since no general rule
112
+ could derive it.
113
+ 4. **Crash-adjacent, found while baking the section index.** The shared
114
+ `inflate()` helper's two stream writes were fire-and-forget
115
+ (`void writer.write(...)`); a malformed deflate stream (the same PDFs #2
116
+ above describes) rejected that promise as an UNHANDLED rejection,
117
+ invisible to any caller's try/catch and fatal to the whole process —
118
+ crashed `scripts/bake-sections.mjs` outright, mid-run. Fixed by attaching
119
+ a no-op `.catch()` to each write/close; the real failure still surfaces
120
+ through `reader.read()`, which the caller already handles. Worth
121
+ checking whether `shared/src/pdf-text.ts` has the same exposure.
122
+
123
+ ## Four capabilities — two available, two are not
124
+
125
+ - **Citation lookup** — available (`gu_statute`).
126
+ - **Topic/keyword search** — available (`gu_search`), over official
127
+ CATCHLINES (section + chapter name), not full statutory prose. Coverage
128
+ is best-effort: catchlines are derived from each chapter PDF's own table
129
+ of contents rather than a separate official index, so an unusually
130
+ formatted chapter can be under-represented.
131
+ - **Amendments/enactment history** — embedded in `gu_statute`'s `text`
132
+ field as the statute's own "SOURCE:" line (e.g. "Enacted 1977 as 16.30;
133
+ amended by P.L. 14-125..."), not split out as a separate field — the GCA
134
+ does not mark it up distinctly enough to parse reliably across both PDF
135
+ eras sampled.
136
+ - **Historical version** (a section's text as it read before an amendment)
137
+ — **not available**. `col.guamcourts.gov` serves the current text only;
138
+ no per-year or per-session archive was found.
139
+
140
+ ## Known rough edge: page-furniture noise at a chapter's last section
141
+
142
+ `gu_statute` strips the repeating running header ("9 GCA CRIMES AND
143
+ CORRECTIONS CH. 16 CRIMINAL HOMICIDE 1") and the "COL<digits>" stamp every
144
+ page carries, self-derived from the chapter text's own first occurrence.
145
+ Older-era PDFs (the "MS Word for Windows Document" producer, #2 above)
146
+ sometimes extract that header with no inter-word spacing ("21GCAREAL
147
+ PROPERTY" rather than "21 GCA REAL PROPERTY"), which the stripping regex —
148
+ anchored on `GCA` preceded by whitespace — does not match. The statutory
149
+ text itself is unaffected; only a section that happens to be the LAST one on
150
+ a page, in one of these older chapters, can carry a trailing fragment of the
151
+ next page's header/footer. Cosmetic, not a correctness defect.
152
+
153
+ ## Citations
154
+
155
+ Give `citation` as `"9 GCA 16.30"`, `"9 GCA § 16.30"`, `"21 GCA 33101"`, or a
156
+ bare section (`"16.30"` / `"33101"`) with `title` passed separately.
157
+
158
+ ## Data sources
159
+
160
+ - `https://col.guamcourts.gov/guam-code-annotated/guam-code-annotated` — the
161
+ Title/Chapter index (one collapsible page). Baked once into
162
+ `src/gu-index-data.ts`; never fetched per call.
163
+ - `https://col.guamcourts.gov/sites/default/files/9gc016.pdf` — one
164
+ chapter's full statutory text (here, 9 GCA Chapter 16, Criminal Homicide
165
+ — swap the filename for any other chapter). `gu_statute` fetches this
166
+ live on every call and extracts the target section out of it. The same
167
+ ~800 chapter PDFs are also fetched once, offline, by
168
+ `scripts/bake-sections.mjs` to build the catchline search index.
169
+
170
+ Both are plain, keyless, server-rendered HTML/PDF — no login, no JS, no
171
+ rate-limit observed during development.
172
+
173
+ ## Quick Start
174
+
175
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
176
+
177
+ ```json
178
+ {
179
+ "mcpServers": {
180
+ "guam-code": {
181
+ "url": "https://gateway.pipeworx.io/guam-code/mcp"
182
+ }
183
+ }
184
+ }
185
+ ```
186
+
187
+ ### What this endpoint actually serves
188
+
189
+ `tools/list` at `https://gateway.pipeworx.io/guam-code/mcp` returns the tools in the table
190
+ above **plus the shared Pipeworx meta-tools** — `ask_pipeworx`,
191
+ `discover_tools`, `search_within`, `remember`/`recall` and the rest of the
192
+ gateway-wide set. So the tool count you see is larger than this table: a
193
+ single-pack endpoint currently lists roughly 30 shared tools alongside the
194
+ pack's own. The connection's `initialize` response states its exact scope, and
195
+ is the authoritative answer for a given day.
196
+
197
+ This is deliberate, not multiplexing by accident. The meta-tools are what let a
198
+ scoped connection answer a question this pack does not cover — via
199
+ `ask_pipeworx`, which routes across the whole catalog — without you adding a
200
+ second MCP server. There is currently no way to mount a pack endpoint without
201
+ them; if the extra schemas cost you more context than the routing is worth,
202
+ connect to the full gateway once rather than to several pack endpoints.
203
+
204
+ Or connect to the full Pipeworx gateway to get every pack's tools listed
205
+ directly, instead of just this one's:
206
+
207
+ ```json
208
+ {
209
+ "mcpServers": {
210
+ "pipeworx": {
211
+ "url": "https://gateway.pipeworx.io/mcp"
212
+ }
213
+ }
214
+ }
215
+ ```
216
+
217
+ Both URLs reach the same gateway and the same 1763+ data sources. The
218
+ only difference is which pack's tools are listed **directly**; `ask_pipeworx`
219
+ reaches all of them from either one.
220
+
221
+ ## No MCP client? Call it over HTTP
222
+
223
+ ```bash
224
+ curl -X POST https://gateway.pipeworx.io/v1/tools/gu_statute \
225
+ -H 'Content-Type: application/json' \
226
+ -d '{"citation":"9 GCA 16.30"}'
227
+ ```
228
+
229
+ No account needed for the first calls. Inspect any tool: `GET https://gateway.pipeworx.io/v1/tools/gu_statute`. Find one: `POST https://gateway.pipeworx.io/v1/tools/search_packs` with `{"query":"..."}`.
230
+
231
+ ## Standalone (no gateway account)
232
+
233
+ This package also runs as a local stdio MCP server — no Pipeworx account, no
234
+ gateway round-trip:
235
+
236
+ ```json
237
+ {
238
+ "mcpServers": {
239
+ "guam-code": {
240
+ "command": "npx",
241
+ "args": ["-y", "@pipeworx/mcp-guam-code"]
242
+ }
243
+ }
244
+ }
245
+ ```
246
+
247
+ Or run it directly to confirm it starts:
248
+
249
+ ```bash
250
+ npx -y @pipeworx/mcp-guam-code
251
+ ```
252
+
253
+ It speaks MCP over stdin/stdout and answers `initialize`/`tools/list`/`tools/call`
254
+ for **only** this pack's tools — none of the shared meta-tools the gateway
255
+ connection above adds. Same source, same tools, no ask_pipeworx routing.
256
+
257
+ ## Using with ask_pipeworx
258
+
259
+ Instead of calling tools directly, you can ask questions in plain English —
260
+ this works on the pack endpoint above as well as on the full gateway:
261
+
262
+ ```
263
+ ask_pipeworx({ question: "your question about Guam Code data" })
264
+ ```
265
+
266
+ The gateway picks the right tool and fills the arguments automatically.
267
+
268
+ ## More
269
+
270
+ - [Docs and guides](https://pipeworx.io/docs)
271
+ - [pipeworx.io](https://pipeworx.io)
272
+
273
+ ## License
274
+
275
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ //
3
+ // Entry point for `npx @pipeworx/mcp-<slug>`.
4
+ //
5
+ // Packs ship as raw TypeScript (no build step — see publish-pack.sh for why:
6
+ // tsx sidesteps every extensionless-import / bare-JSON-import edge case a
7
+ // per-pack tsc build would have to solve one pack at a time). This file
8
+ // registers tsx's ESM loader programmatically, then hands off to src/server.ts,
9
+ // which wraps the pack's {tools, callTool} export in a stdio MCP server.
10
+ //
11
+ // Copied verbatim into every published pack repo by scripts/publish-pack.sh —
12
+ // edit this file, not a per-pack copy.
13
+ import { register } from 'tsx/esm/api';
14
+
15
+ register();
16
+
17
+ await import('../src/server.ts');
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@pipeworx/mcp-guam-code",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Guam Code Annotated (GCA) — section lookup and search. Fleet #2888.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "bin": {
9
+ "mcp-guam-code": "bin/cli.js"
10
+ },
11
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "guam-code"],
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/pipeworx-io/mcp-guam-code.git"
16
+ },
17
+ "scripts": {
18
+ "typecheck": "tsc --noEmit"
19
+ },
20
+ "dependencies": {
21
+ "@modelcontextprotocol/sdk": "^1.30.0",
22
+ "tsx": "^4.19.0"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^5.9.3",
26
+ "@cloudflare/workers-types": "^4.20260405.1"
27
+ },
28
+ "pipeworx": {
29
+ "sourceHash": "v1-528944ed480fcb0b07e7646725576e69ad019ebc4e97aa1753f64ffdb7dcea81",
30
+ "sourceCommit": "051ee2039fc96224cb5b7358fd69d525bced13a6"
31
+ }
32
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/guam-code",
4
+ "title": "Guam Code",
5
+ "description": "Guam Code Annotated (GCA) — section lookup and search. Fleet #2888.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/guam-code",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-guam-code",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/guam-code/mcp"
16
+ }
17
+ ]
18
+ }