@pipeworx/mcp-guam-code 0.0.0-stage → 0.1.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 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,285 @@
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 1784+ 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 — folded in, fork deleted (fleet #2904)
79
+
80
+ Guam's chapter PDFs originally defeated the shared extractor in ways it did
81
+ not yet handle, and this pack was built the same week another pack (#2884,
82
+ New Mexico) was independently editing that shared file — so the fixes
83
+ initially lived in `src/gu-pdf-extract.ts`, a pack-local fork of
84
+ `shared/src/pdf-text.ts`, with a loud header comment for whoever next
85
+ touched the shared extractor to fold them in (nothing about them was
86
+ Guam-specific). That fold-in happened in fleet #2904: the fork is gone, this
87
+ pack now calls `extractPdfText` from `@pipeworx/shared` directly, and all
88
+ three fixes below live in `shared/src/pdf-text.ts` itself, benefiting every
89
+ other PDF pack (kentucky-code, north-dakota-code, wyoming-code,
90
+ new-mexico-code), not just this one:
91
+
92
+ 1. **Literal strings weren't routed through the font decoder.** Guam's
93
+ producer (Neevia Document Converter, from Word) writes some non-WinAnsi
94
+ subset fonts' text as parenthesized LITERAL strings (`(abc)Tj`) rather
95
+ than hex (`<...>Tj`). The shared extractor's `decodeRun` passed a literal
96
+ run through unchanged — correct for WinAnsi, but for these fonts the raw
97
+ bytes are a tiny, arbitrary code space meaningful only via the font's own
98
+ `/ToUnicode` CMap, which the shared code already had the machinery for
99
+ (built for North Dakota) but only wired to the HEX-string path. Confirmed
100
+ live: unfixed, `§ 16.10` extracted as control-character noise; fixed, it
101
+ reads correctly.
102
+ 2. **A declared `/Length` a few bytes long.** Several older chapter PDFs
103
+ ("MS Word for Windows Document" producer — an earlier era than the
104
+ Neevia-converted ones above) declare a `/Length` 1+ bytes longer than
105
+ their actual deflate stream. Python's zlib tolerates the trailing byte
106
+ silently; Node/Workers' strict `DecompressionStream` throws
107
+ `ERR_TRAILING_JUNK_AFTER_STREAM_END`. Now retried with the stream's tail
108
+ trimmed a byte at a time (up to 4) before giving up.
109
+ 3. **Crash-adjacent, found while baking the section index.** The shared
110
+ `inflate()` helper's two stream writes were fire-and-forget
111
+ (`void writer.write(...)`); a malformed deflate stream (the same PDFs #2
112
+ above describes) rejected that promise as an UNHANDLED rejection,
113
+ invisible to any caller's try/catch and fatal to the whole process —
114
+ crashed `scripts/bake-sections.mjs` outright, mid-run. Fixed by attaching
115
+ a no-op `.catch()` to each write/close; the real failure still surfaces
116
+ through `reader.read()`, which the caller already handles.
117
+
118
+ **One delta stayed pack-local, in `src/gu-font-cmap-fix.ts`, because it
119
+ genuinely IS Guam-specific:** one embedded symbol font per chapter PDF
120
+ (`...+WPTypographicSymbols`, used only for curly quotes) carries a
121
+ `/ToUnicode` CMap that maps its two codes to U+0041 ('A') and U+0040 ('@')
122
+ instead of the left/right curly quote it visually renders as. Confirmed by
123
+ eye: "ADirector of Public Safety@" in raw extraction is "“Director of Public
124
+ Safety”" with those two codes substituted back — the obviously intended
125
+ reading, reproduced by any PDF viewer's own copy-paste. This is a defect in
126
+ Guam's own published PDF, not something a general-purpose extractor could
127
+ derive, so it is passed into `extractPdfText` via its new `fontCMapOverride`
128
+ option — a generic hook (match a font's own dictionary text, optionally
129
+ return a replacement `/ToUnicode` map) with nothing Guam-specific about the
130
+ mechanism itself, available to any future pack that hits a similarly broken
131
+ source PDF.
132
+
133
+ ## Four capabilities — two available, two are not
134
+
135
+ - **Citation lookup** — available (`gu_statute`).
136
+ - **Topic/keyword search** — available (`gu_search`), over official
137
+ CATCHLINES (section + chapter name), not full statutory prose. Coverage
138
+ is best-effort: catchlines are derived from each chapter PDF's own table
139
+ of contents rather than a separate official index, so an unusually
140
+ formatted chapter can be under-represented.
141
+ - **Amendments/enactment history** — embedded in `gu_statute`'s `text`
142
+ field as the statute's own "SOURCE:" line (e.g. "Enacted 1977 as 16.30;
143
+ amended by P.L. 14-125..."), not split out as a separate field — the GCA
144
+ does not mark it up distinctly enough to parse reliably across both PDF
145
+ eras sampled.
146
+ - **Historical version** (a section's text as it read before an amendment)
147
+ — **not available**. `col.guamcourts.gov` serves the current text only;
148
+ no per-year or per-session archive was found.
149
+
150
+ ## Known rough edge: page-furniture noise at a chapter's last section
151
+
152
+ `gu_statute` strips the repeating running header ("9 GCA CRIMES AND
153
+ CORRECTIONS CH. 16 CRIMINAL HOMICIDE 1") and the "COL<digits>" stamp every
154
+ page carries, self-derived from the chapter text's own first occurrence.
155
+ Older-era PDFs (the "MS Word for Windows Document" producer, #2 above)
156
+ sometimes extract that header with no inter-word spacing ("21GCAREAL
157
+ PROPERTY" rather than "21 GCA REAL PROPERTY"), which the stripping regex —
158
+ anchored on `GCA` preceded by whitespace — does not match. The statutory
159
+ text itself is unaffected; only a section that happens to be the LAST one on
160
+ a page, in one of these older chapters, can carry a trailing fragment of the
161
+ next page's header/footer. Cosmetic, not a correctness defect.
162
+
163
+ ## Citations
164
+
165
+ Give `citation` as `"9 GCA 16.30"`, `"9 GCA § 16.30"`, `"21 GCA 33101"`, or a
166
+ bare section (`"16.30"` / `"33101"`) with `title` passed separately.
167
+
168
+ ## Data sources
169
+
170
+ - `https://col.guamcourts.gov/guam-code-annotated/guam-code-annotated` — the
171
+ Title/Chapter index (one collapsible page). Baked once into
172
+ `src/gu-index-data.ts`; never fetched per call.
173
+ - `https://col.guamcourts.gov/sites/default/files/9gc016.pdf` — one
174
+ chapter's full statutory text (here, 9 GCA Chapter 16, Criminal Homicide
175
+ — swap the filename for any other chapter). `gu_statute` fetches this
176
+ live on every call and extracts the target section out of it. The same
177
+ ~800 chapter PDFs are also fetched once, offline, by
178
+ `scripts/bake-sections.mjs` to build the catchline search index.
179
+
180
+ Both are plain, keyless, server-rendered HTML/PDF — no login, no JS, no
181
+ rate-limit observed during development.
182
+
183
+ ## Quick Start
184
+
185
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
186
+
187
+ ```json
188
+ {
189
+ "mcpServers": {
190
+ "guam-code": {
191
+ "url": "https://gateway.pipeworx.io/guam-code/mcp"
192
+ }
193
+ }
194
+ }
195
+ ```
196
+
197
+ ### What this endpoint actually serves
198
+
199
+ `tools/list` at `https://gateway.pipeworx.io/guam-code/mcp` returns the tools in the table
200
+ above **plus the shared Pipeworx meta-tools** — `ask_pipeworx`,
201
+ `discover_tools`, `search_within`, `remember`/`recall` and the rest of the
202
+ gateway-wide set. So the tool count you see is larger than this table: a
203
+ single-pack endpoint currently lists roughly 30 shared tools alongside the
204
+ pack's own. The connection's `initialize` response states its exact scope, and
205
+ is the authoritative answer for a given day.
206
+
207
+ This is deliberate, not multiplexing by accident. The meta-tools are what let a
208
+ scoped connection answer a question this pack does not cover — via
209
+ `ask_pipeworx`, which routes across the whole catalog — without you adding a
210
+ second MCP server. There is currently no way to mount a pack endpoint without
211
+ them; if the extra schemas cost you more context than the routing is worth,
212
+ connect to the full gateway once rather than to several pack endpoints.
213
+
214
+ Or connect to the full Pipeworx gateway to get every pack's tools listed
215
+ directly, instead of just this one's:
216
+
217
+ ```json
218
+ {
219
+ "mcpServers": {
220
+ "pipeworx": {
221
+ "url": "https://gateway.pipeworx.io/mcp"
222
+ }
223
+ }
224
+ }
225
+ ```
226
+
227
+ Both URLs reach the same gateway and the same 1784+ data sources. The
228
+ only difference is which pack's tools are listed **directly**; `ask_pipeworx`
229
+ reaches all of them from either one.
230
+
231
+ ## No MCP client? Call it over HTTP
232
+
233
+ ```bash
234
+ curl -X POST https://gateway.pipeworx.io/v1/tools/gu_statute \
235
+ -H 'Content-Type: application/json' \
236
+ -d '{"citation":"9 GCA 16.30"}'
237
+ ```
238
+
239
+ 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":"..."}`.
240
+
241
+ ## Standalone (no gateway account)
242
+
243
+ This package also runs as a local stdio MCP server — no Pipeworx account, no
244
+ gateway round-trip:
245
+
246
+ ```json
247
+ {
248
+ "mcpServers": {
249
+ "guam-code": {
250
+ "command": "npx",
251
+ "args": ["-y", "@pipeworx/mcp-guam-code"]
252
+ }
253
+ }
254
+ }
255
+ ```
256
+
257
+ Or run it directly to confirm it starts:
258
+
259
+ ```bash
260
+ npx -y @pipeworx/mcp-guam-code
261
+ ```
262
+
263
+ It speaks MCP over stdin/stdout and answers `initialize`/`tools/list`/`tools/call`
264
+ for **only** this pack's tools — none of the shared meta-tools the gateway
265
+ connection above adds. Same source, same tools, no ask_pipeworx routing.
266
+
267
+ ## Using with ask_pipeworx
268
+
269
+ Instead of calling tools directly, you can ask questions in plain English —
270
+ this works on the pack endpoint above as well as on the full gateway:
271
+
272
+ ```
273
+ ask_pipeworx({ question: "your question about Guam Code data" })
274
+ ```
275
+
276
+ The gateway picks the right tool and fills the arguments automatically.
277
+
278
+ ## More
279
+
280
+ - [Docs and guides](https://pipeworx.io/docs)
281
+ - [pipeworx.io](https://pipeworx.io)
282
+
283
+ ## License
284
+
285
+ 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.1",
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-964fe40aed9923b374141088f42860d68ffb5efa97b3c7c3fc37b9902c46c79f",
30
+ "sourceCommit": "3723e46c6d115bd4a1fd2175e6bf758555e7cb50"
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.1",
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
+ }