@mailwoman/mcp 10.0.0 → 10.2.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/README.md CHANGED
@@ -16,7 +16,7 @@ An **MCP server** exposing [Mailwoman](https://mailwoman.ai)'s parse/geocode/POI
16
16
  | `mailwoman_filer_lookup` | Reads the FCC filer identity crosswalk from a `filer.db` layer | No |
17
17
  | `mailwoman_filer_family` | Reads a corporate family's membership from a `filer.db` layer | No |
18
18
 
19
- The four model-backed tools load the `en-US` weights and open a resolver on the first call that needs them, not at
19
+ The four model-backed tools load the `en-US` weights and open a resolver on the first call that needs them rather than at
20
20
  startup. With neither `$MAILWOMAN_CANDIDATE_DB` nor a WOF distribution on the data root, that first call answers with
21
21
  the `mailwoman data pull candidate` fix instead of an internal resolver error.
22
22
 
package/cli/main.ts ADDED
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @copyright Sister Software
4
+ * @license AGPL-3.0
5
+ * @author Teffen Ellis, et al.
6
+ */
7
+
8
+ import { filingLandscape, plausibilityCheck, type BDCDatabase } from "@mailwoman/bdc"
9
+ import type { PipelineResult } from "@mailwoman/core"
10
+ import { dataRootPath } from "@mailwoman/core/data-root"
11
+ import { pathExists } from "@mailwoman/core/fs/readers/stat"
12
+ import { readLayerManifest, type layerschemadatabase } from "@mailwoman/core/layers"
13
+ import type { Resolver } from "@mailwoman/core/resolver"
14
+ import { parseArguments } from "@mailwoman/core/scripting/arguments"
15
+ import { familyRollup } from "@mailwoman/filer/family-rollup"
16
+ import { filerLookup } from "@mailwoman/filer/filer-lookup"
17
+ import { toFRN, type FRN } from "@mailwoman/filer/frn"
18
+ import { NeuralAddressClassifier, type ScriptRoutedClassifier } from "@mailwoman/neural"
19
+ import { getPOICategory } from "@mailwoman/poi-taxonomy"
20
+ import { emitOverpassQL } from "@mailwoman/poi-taxonomy/overpass"
21
+ import { createWOFResolver } from "@mailwoman/resolver"
22
+ import { wofExtractPaths } from "@mailwoman/resolver-wof-sqlite/paths"
23
+ import { DatabaseClient } from "@mailwoman/sqlite/client"
24
+ import { createRuntimePipeline } from "mailwoman"
25
+ import { geocodeAddress, USStateDatabaseProvider } from "mailwoman/geocode"
26
+ import { buildNoGazetteerMessage, createResolverBackend, resolveCandidateDBPath } from "mailwoman/resolver-backend"
27
+
28
+ import {
29
+ assertBDCDatabaseExists,
30
+ assertFilerDatabaseExists,
31
+ openBDCDatabaseIfPresent,
32
+ openFilerDatabaseIfPresent,
33
+ openPlausibilityPOIDeps,
34
+ } from "#layer-guards"
35
+ import { createMCPServer } from "#server"
36
+ import type { MCPToolDeps } from "#tools"
37
+
38
+ const { values } = parseArguments({
39
+ options: {
40
+ "poi-db": { type: "string" },
41
+ },
42
+ allowPositionals: true,
43
+ })
44
+
45
+ const poiDatabasePath = values["poi-db"] ?? null
46
+
47
+ let corePromise:
48
+ | Promise<{
49
+ classifier: ScriptRoutedClassifier<NeuralAddressClassifier>
50
+ resolver: Resolver
51
+ databases: USStateDatabaseProvider
52
+ }>
53
+ | undefined
54
+
55
+ const CORE_BACKED_TOOLS = "mailwoman_parse, mailwoman_geocode, mailwoman_poi_search, mailwoman_overpass_export"
56
+
57
+ const CORE_FREE_TOOLS =
58
+ "mailwoman_layer_manifest, mailwoman_bdc_filing_landscape, mailwoman_filer_lookup, mailwoman_filer_family"
59
+
60
+ function loadCore(): Promise<{
61
+ classifier: ScriptRoutedClassifier
62
+ resolver: Resolver
63
+ /**
64
+ * The concrete US provider, because `GeocodeDeps.databases` accepts a null state slug.
65
+ */
66
+ databases: USStateDatabaseProvider
67
+ }> {
68
+ corePromise ??= (async () => {
69
+ const resolverMod = await import("@mailwoman/resolver-wof-sqlite")
70
+ const wofPaths: string[] = []
71
+
72
+ for (const extractPath of wofExtractPaths()) {
73
+ if (await pathExists(extractPath)) {
74
+ wofPaths.push(extractPath)
75
+ }
76
+ }
77
+
78
+ const candidateDB = await resolveCandidateDBPath()
79
+
80
+ if (!candidateDB && !wofPaths.length) {
81
+ throw new Error(
82
+ `${buildNoGazetteerMessage({
83
+ dataRoot: dataRootPath(),
84
+ docsPath: "/docs/developers/how-to/use-the-mcp-server",
85
+ })}\n\n Needs it: ${CORE_BACKED_TOOLS}\n Works without it: ${CORE_FREE_TOOLS}`
86
+ )
87
+ }
88
+
89
+ const backend = await createResolverBackend(resolverMod, { wofPaths, candidateDB })
90
+ const resolver = createWOFResolver(backend)
91
+
92
+ let classifier: ScriptRoutedClassifier<NeuralAddressClassifier>
93
+
94
+ try {
95
+ classifier = await NeuralAddressClassifier.loadRoutedFromWeights({ locale: "en-US" })
96
+ } catch (error) {
97
+ throw new Error(
98
+ `✗ ${error instanceof Error ? error.message : String(error)}\n\n` +
99
+ ` Needs it: ${CORE_BACKED_TOOLS}\n Works without it: ${CORE_FREE_TOOLS}`
100
+ )
101
+ }
102
+
103
+ const databases = await USStateDatabaseProvider.create(resolverMod, dataRootPath())
104
+
105
+ return { classifier, resolver, databases }
106
+ })()
107
+
108
+ return corePromise
109
+ }
110
+
111
+ type Pipeline = (raw: string) => Promise<PipelineResult>
112
+
113
+ let plainPipeline: Pipeline | null = null
114
+
115
+ const poiPipelines = new Map<string, Pipeline>()
116
+
117
+ async function getPlainPipeline(): Promise<Pipeline> {
118
+ if (!plainPipeline) {
119
+ const { classifier, resolver } = await loadCore()
120
+
121
+ plainPipeline = createRuntimePipeline({ classifier, resolver })
122
+ }
123
+
124
+ return plainPipeline
125
+ }
126
+
127
+ async function getPoiPipeline(dbPath: string | null): Promise<Pipeline> {
128
+ const key = dbPath ?? ""
129
+ const cached = poiPipelines.get(key)
130
+
131
+ if (cached) return cached
132
+ const { classifier, resolver } = await loadCore()
133
+
134
+ const pipeline = createRuntimePipeline({
135
+ classifier,
136
+ resolver,
137
+ poiQueryKind: dbPath ? { poiDatabasePath: dbPath } : "extract",
138
+ })
139
+
140
+ poiPipelines.set(key, pipeline)
141
+
142
+ return pipeline
143
+ }
144
+
145
+ async function resolveGeocode(address: string) {
146
+ const { classifier, resolver, databases } = await loadCore()
147
+
148
+ return geocodeAddress(address, { classifier, resolver, databases: databases.for })
149
+ }
150
+
151
+ const deps: MCPToolDeps = {
152
+ async parse(text, opts) {
153
+ const pipeline = opts?.poi ? await getPoiPipeline(poiDatabasePath) : await getPlainPipeline()
154
+
155
+ return pipeline(text)
156
+ },
157
+
158
+ async geocode(text) {
159
+ return resolveGeocode(text)
160
+ },
161
+
162
+ async poiSearch(q) {
163
+ const pipeline = await getPoiPipeline(q.poiDatabasePath ?? poiDatabasePath)
164
+ const result = await pipeline(q.query)
165
+
166
+ return result.poiIntent ?? { type: "abstain", reason: "not_poi_shaped" }
167
+ },
168
+
169
+ async overpassExport(query) {
170
+ const pipeline = await getPoiPipeline(poiDatabasePath)
171
+ const result = await pipeline(query)
172
+ const poiIntent = result.poiIntent
173
+
174
+ if (!poiIntent || poiIntent.type !== "intent") {
175
+ const reason = poiIntent?.type === "abstain" ? `: ${poiIntent.reason}` : ""
176
+
177
+ throw new Error(
178
+ `mailwoman_overpass_export: query is not POI-shaped (${poiIntent?.type ?? "no poi intent"}${reason})`
179
+ )
180
+ }
181
+
182
+ const { subject } = poiIntent.intent
183
+
184
+ const osmTags =
185
+ subject.kind === "category"
186
+ ? subject.categoryIDs.map((id) => getPOICategory(id)?.osmTag).filter((tag) => tag !== undefined)
187
+ : []
188
+
189
+ return emitOverpassQL(
190
+ poiIntent.intent,
191
+ subject.kind === "category" && osmTags.length === subject.categoryIDs.length ? { osmTags } : {}
192
+ )
193
+ },
194
+
195
+ async layerManifest(databasePath) {
196
+ using db = new DatabaseClient<layerschemadatabase>(databasePath, { readOnly: true })
197
+
198
+ const manifest = await readLayerManifest(db)
199
+
200
+ const coverage = await db
201
+ .selectFrom("layer_coverage")
202
+ .select((eb) => [
203
+ eb.fn.count<number>("h3_cell").as("surveyedCellCount"),
204
+ eb.fn.avg<number>("completeness").as("averageCompleteness"),
205
+ eb.fn.sum<number>("observed_rows").as("totalObservedRows"),
206
+ ])
207
+ .executeTakeFirst()
208
+
209
+ return { manifest, coverage }
210
+ },
211
+
212
+ async bdcFilingLandscape(q) {
213
+ await assertBDCDatabaseExists("mailwoman_bdc_filing_landscape", q.databasePath)
214
+
215
+ using db = new DatabaseClient<BDCDatabase>(q.databasePath, { readOnly: true })
216
+
217
+ return await filingLandscape(db, { geoids: q.geoids, h3Cells: q.h3Cells })
218
+ },
219
+
220
+ async plausibilityCheck(q) {
221
+ const bdcDB = await openBDCDatabaseIfPresent(q.bdcDatabasePath)
222
+ const poi = await openPlausibilityPOIDeps(q.poiDatabasePath)
223
+
224
+ try {
225
+ return await plausibilityCheck(
226
+ {
227
+ address: q.address,
228
+ point: q.point,
229
+ geoid: q.geoid,
230
+ technologyCode: q.technologyCode,
231
+ claimedDownloadMbps: q.claimedDownloadMbps,
232
+ },
233
+ { bdcDB, poi, geocode: resolveGeocode }
234
+ )
235
+ } finally {
236
+ bdcDB?.destroy()
237
+ poi?.schemadb.destroy()
238
+ }
239
+ },
240
+
241
+ async filerLookup(q) {
242
+ await assertFilerDatabaseExists("mailwoman_filer_lookup", q.databasePath)
243
+
244
+ using db = (await openFilerDatabaseIfPresent(q.databasePath))!
245
+
246
+ let frn: FRN | null = null
247
+
248
+ if (q.frn) {
249
+ const parsed = toFRN(q.frn)
250
+
251
+ if (!parsed) {
252
+ throw new Error(`mailwoman_filer_lookup: "${q.frn}" is not a valid FRN`)
253
+ }
254
+
255
+ frn = parsed
256
+ }
257
+
258
+ return await filerLookup(db, {
259
+ frn,
260
+ form499ID: q.form499ID,
261
+ bdcProviderID: q.bdcProviderID,
262
+ asOf: q.asOf,
263
+ })
264
+ },
265
+
266
+ async filerFamily(q) {
267
+ await assertFilerDatabaseExists("mailwoman_filer_family", q.databasePath)
268
+
269
+ using db = (await openFilerDatabaseIfPresent(q.databasePath))!
270
+
271
+ return await familyRollup(db, {
272
+ familyID: q.familyID,
273
+ nodeID: q.nodeID,
274
+ asOf: q.asOf,
275
+ })
276
+ },
277
+ }
278
+
279
+ const server = createMCPServer(deps)
280
+ const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js")
281
+
282
+ await server.connect(new StdioServerTransport())
@@ -6,18 +6,18 @@
6
6
  * Decision 6 layer-absent guards — kept out of `cli.ts` in their own importable module so the
7
7
  * branching itself has direct unit coverage (`layer-guards.test.ts`), not just
8
8
  * "the tool handler passes an abstain through" (`tools.test.ts`'s stub-level dispatch tests). `cli.ts`
9
- * top-level-`await`s a real stdio transport connection at import time, so IT can't be imported by vitest — these
9
+ * top-level-`await`s a real stdio transport connection at import time, so IT can't be imported by vitest. These
10
10
  * three functions have no such dependency (pure existence-check + open, or a thrown Error), so they live here and
11
11
  * `cli.ts` just calls them.
12
12
  *
13
13
  * - `openBDCDatabaseIfPresent` / `openPlausibilityPOIDeps` — `mailwoman_plausibility_check`'s `bdcDB`/`poi` deps
14
- * (`PlausibilityDeps`) are each OPTIONAL, so a missing/absent path degrades to `undefined`, which
14
+ * (`PlausibilityDeps`) are each optional, so a missing/absent path degrades to `undefined`, which
15
15
  * `plausibilityCheck` (`@mailwoman/bdc`) already turns into a typed abstain evidence entry
16
16
  * (`{type:"abstain", reason:"requires_bdc_layer"|"requires_build_local_layer"}`) — never a raw sqlite throw.
17
17
  * - `assertBDCDatabaseExists` — `mailwoman_bdc_filing_landscape` requires bdc.db unconditionally (no optional-dep
18
18
  * abstain shape exists for that tool), so a missing file becomes one friendly thrown `Error` naming the layer
19
19
  * instead of the raw `node:sqlite` "unable to open database file" message.
20
- * - `openFilerDatabaseIfPresent` / `assertFilerDatabaseExists` — the SAME pairing, for filer.db.
20
+ * - `openFilerDatabaseIfPresent` / `assertFilerDatabaseExists` — the same pairing, for filer.db.
21
21
  * `mailwoman_filer_lookup` requires filer.db unconditionally (mirrors `mailwoman_bdc_filing_landscape`'s own
22
22
  * "requires the layer" discipline — `filerLookup` itself has no optional-dep abstain shape either, since criterion
23
23
  * 4 makes it throw rather than answer unstamped), so `cli.ts` pairs `assertFilerDatabaseExists` (the friendly
@@ -25,34 +25,45 @@
25
25
  */
26
26
 
27
27
  import type { BDCDatabase, PlausibilityDeps } from "@mailwoman/bdc"
28
- import { pathExists } from "@mailwoman/core/fs/readers"
28
+ import { pathExists } from "@mailwoman/core/fs/readers/stat"
29
29
  import type { FilerDatabase } from "@mailwoman/filer"
30
30
  import type { POIDatabase } from "@mailwoman/resolver-wof-sqlite/poi"
31
31
  import { DatabaseClient } from "@mailwoman/sqlite/client"
32
+ import type { PathBuilderLike } from "path-ts"
32
33
 
33
34
  /**
34
- * Open a bdc.db, or return `undefined` when `databasePath` is unset or the file is missing — NEVER a raw sqlite throw.
35
+ * Open a bdc.db, or return `undefined` when `databasePath` is unset
36
+ * or the file is missing, never a raw sqlite throw.
37
+ *
35
38
  * See the module header.
36
39
  */
37
40
  export async function openBDCDatabaseIfPresent(
38
- databasePath: string | undefined
39
- ): Promise<DatabaseClient<BDCDatabase> | undefined> {
40
- if (!databasePath || !(await pathExists(databasePath))) return undefined
41
+ databasePath: PathBuilderLike | undefined
42
+ ): Promise<DatabaseClient<BDCDatabase> | null> {
43
+ if (!databasePath || !(await pathExists(databasePath))) return null
41
44
 
42
45
  return new DatabaseClient<BDCDatabase>(databasePath, { readOnly: true })
43
46
  }
44
47
 
45
48
  /**
46
- * Same graceful discipline as {@link openBDCDatabaseIfPresent}, for the poi.db side of `plausibilityCheck`'s deps —
47
- * `undefined` here becomes the `{type:"abstain", reason:"requires_build_local_layer"}` entry `plausibilityCheck`
48
- * already produces when a claimed technology's physical-plant categories can't be searched. `POILookup` is dynamically
49
- * imported (matching `cli.ts`'s existing `resolver-wof-sqlite` laziness) since it's only ever needed when a caller
50
- * actually wires a poi.db. `lookup` and `contractDB` share ONE `DatabaseSync` handle (the AGENTS.md "one connection,
51
- * shared" convention) — a real poi.db's rows and its `layer_manifest`/`layer_coverage` tables live in the same file in
52
- * production, so disposing `contractDB` (which closes the shared handle) is enough; `POILookup` never owns it
49
+ * Same graceful discipline as {@link openBDCDatabaseIfPresent}, for the poi.db
50
+ * side of `plausibilityCheck`'s deps.
51
+ *
52
+ * `undefined` here becomes the `{type:"abstain", reason:"requires_build_local_layer"}`
53
+ * entry `plausibilityCheck` already produces when a claimed technology's
54
+ * physical-plant categories can't be searched.
55
+ *
56
+ * `POILookup` is dynamically imported (matching `cli.ts`'s existing `resolver-wof-sqlite` laziness)
57
+ * since it's only ever needed when a caller actually wires a poi.db.
58
+ * `lookup` and `schemadb` share one `DatabaseSync` handle
59
+ * (the agents.md "one connection, shared" convention) — a real poi.db's rows
60
+ * and its `layer_manifest`/`layer_coverage` tables live in the same file in production,
61
+ * so disposing `schemadb` (which closes the shared handle) is enough; `POILookup` never owns it
53
62
  * (constructed with `{database}`, not `{databasePath}` — see `poi-lookup.ts`), so it never double-closes.
54
63
  */
55
- export async function openPlausibilityPOIDeps(databasePath: string | undefined): Promise<PlausibilityDeps["poi"]> {
64
+ export async function openPlausibilityPOIDeps(
65
+ databasePath: PathBuilderLike | undefined
66
+ ): Promise<PlausibilityDeps["poi"]> {
56
67
  if (!databasePath || !(await pathExists(databasePath))) return undefined
57
68
 
58
69
  const { POILookup } = await import("@mailwoman/resolver-wof-sqlite/poi")
@@ -60,41 +71,47 @@ export async function openPlausibilityPOIDeps(databasePath: string | undefined):
60
71
 
61
72
  return {
62
73
  lookup: new POILookup({ database }),
63
- contractDB: database,
74
+ schemadb: database,
64
75
  }
65
76
  }
66
77
 
67
78
  /**
68
- * Throws a friendly Error naming the layer when `databasePath` doesn't exist — `mailwoman_bdc_filing_landscape`'s guard
69
- * (decision 6b). `toolName` is threaded through so the message matches whichever tool calls this (today: only
70
- * `mailwoman_bdc_filing_landscape`).
79
+ * Throws a friendly Error naming the layer when `databasePath` doesn't exist —
80
+ * `mailwoman_bdc_filing_landscape`'s guard (decision 6b).
81
+ *
82
+ * `toolName` is threaded through so the message matches whichever tool calls this
83
+ * (today: only `mailwoman_bdc_filing_landscape`).
71
84
  */
72
- export async function assertBDCDatabaseExists(toolName: string, databasePath: string): Promise<void> {
85
+ export async function assertBDCDatabaseExists(toolName: string, databasePath: PathBuilderLike): Promise<void> {
73
86
  if (!(await pathExists(databasePath))) {
74
87
  throw new Error(`${toolName}: bdc.db not found at "${databasePath}"`)
75
88
  }
76
89
  }
77
90
 
78
91
  /**
79
- * Open a filer.db, or return `undefined` when `databasePath` is unset or the file is missing — NEVER a raw sqlite throw
80
- * (mirroring {@link openBDCDatabaseIfPresent}). Used by `cli.ts`'s `mailwoman_filer_lookup` handler after
81
- * {@link assertFilerDatabaseExists} has already confirmed the file is present.
92
+ * Open a filer.db, or return `undefined` when `databasePath` is unset or the file is missing,
93
+ * never a raw sqlite throw (mirroring {@link openBDCDatabaseIfPresent}).
94
+ *
95
+ * Used by `cli.ts`'s `mailwoman_filer_lookup` handler after {@link assertFilerDatabaseExists}
96
+ * has already confirmed the file is present.
82
97
  */
83
98
  export async function openFilerDatabaseIfPresent(
84
- databasePath: string | undefined
85
- ): Promise<DatabaseClient<FilerDatabase> | undefined> {
86
- if (!databasePath || !(await pathExists(databasePath))) return undefined
99
+ databasePath: PathBuilderLike | undefined
100
+ ): Promise<DatabaseClient<FilerDatabase> | null> {
101
+ if (!databasePath || !(await pathExists(databasePath))) return null
87
102
 
88
103
  return new DatabaseClient<FilerDatabase>(databasePath, { readOnly: true })
89
104
  }
90
105
 
91
106
  /**
92
- * Throws a friendly Error naming the layer when `databasePath` doesn't exist — `mailwoman_filer_lookup`'s guard
93
- * (mirroring {@link assertBDCDatabaseExists}). `filerLookup` itself has no optional-dep abstain shape (criterion 4
94
- * makes it throw rather than answer unstamped), so filer.db is required unconditionally, same as bdc.db is for
95
- * `mailwoman_bdc_filing_landscape`.
107
+ * Throws a friendly Error naming the layer when `databasePath` doesn't exist —
108
+ * `mailwoman_filer_lookup`'s guard (mirroring {@link assertBDCDatabaseExists}).
109
+ *
110
+ * `filerLookup` itself has no optional-dep abstain shape
111
+ * (criterion 4 makes it throw rather than answer unstamped), so filer.db is required
112
+ * unconditionally, same as bdc.db is for `mailwoman_bdc_filing_landscape`.
96
113
  */
97
- export async function assertFilerDatabaseExists(toolName: string, databasePath: string): Promise<void> {
114
+ export async function assertFilerDatabaseExists(toolName: string, databasePath: PathBuilderLike): Promise<void> {
98
115
  if (!(await pathExists(databasePath))) {
99
116
  throw new Error(`${toolName}: filer.db not found at "${databasePath}"`)
100
117
  }
package/lib/server.ts CHANGED
@@ -4,29 +4,41 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
6
  * MCP server wiring — thin glue that registers `tools.ts`'s tool table on an `McpServer`. The tool table is the
7
- * stable, tested contract (`tools.test.ts`); this module only adapts it to the SDK's `registerTool` signature and
7
+ * stable, tested interface (`tools.test.ts`); this module only adapts it to the SDK's `registerTool` signature and
8
8
  * `CallToolResult` envelope. `cli.ts` owns building the real `MCPToolDeps` and connecting a transport.
9
9
  */
10
10
 
11
+ import { prettyJSON } from "@mailwoman/core/json"
12
+ import { readPackageJSON } from "@mailwoman/core/module/resolve-from"
11
13
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
12
14
  import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"
13
15
 
14
16
  import { buildToolTable, type MCPToolDeps } from "#tools"
15
17
 
16
18
  /**
17
- * The advertised server version — keep in lockstep with `package.json`'s `version` (not read from it dynamically: a
18
- * static string avoids `resolveJsonModule`/`composite` friction for one cosmetic field, the same tradeoff
19
- * `nominatim`/`photon`'s OpenAPI `info.version` DON'T make since theirs is a documented public contract; an MCP client
20
- * only ever logs this).
19
+ * The advertised server version, read from this package's own manifest at load.
20
+ *
21
+ * A JSON import would make `tsc` copy the file into `out/`, where it becomes the package
22
+ * scope for the compiled tree, so the manifest is read through the module resolver instead.
21
23
  */
22
- const MCP_SERVER_VERSION = "7.1.0"
24
+ const MCP_SERVER_VERSION = await readPackageJSON(import.meta.url, "@mailwoman/mcp").then((manifest) => {
25
+ if (!manifest.version) {
26
+ throw new Error("@mailwoman/mcp: package.json carries no version to advertise")
27
+ }
28
+
29
+ return manifest.version
30
+ })
23
31
 
24
32
  /**
25
- * Build an `McpServer` with every `tools.ts` tool registered. A handler's returned value is JSON-stringified into a
26
- * single `text` content block — every tool here answers with structured data (parse trees, geocode results, search
27
- * hits), so a plain JSON text block is the simplest faithful rendering; none of the tools need images, resource links,
28
- * or other MCP content kinds. A thrown error becomes an `isError` tool result instead of a protocol-level failure, so a
29
- * bad address / missing db surfaces to the agent as a normal (if unsuccessful) tool call.
33
+ * Build an `McpServer` with every `tools.ts` tool registered.
34
+ *
35
+ * A handler's returned value is JSON-stringified into a single `text` content block.
36
+ * Every tool here answers with structured data (parse trees, geocode results, search hits),
37
+ * so a plain JSON text block is the simplest faithful rendering.
38
+ *
39
+ * None of the tools need images, resource links, or other MCP content kinds.
40
+ * A thrown error becomes an `isError` tool result instead of a protocol-level failure,
41
+ * so a bad address / missing db surfaces to the agent as a normal (if unsuccessful) tool call.
30
42
  */
31
43
  export function createMCPServer(deps: MCPToolDeps): McpServer {
32
44
  const server = new McpServer({ name: "mailwoman", version: MCP_SERVER_VERSION })
@@ -39,7 +51,7 @@ export function createMCPServer(deps: MCPToolDeps): McpServer {
39
51
  try {
40
52
  const result = await tool.handler(args)
41
53
 
42
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }
54
+ return { content: [{ type: "text", text: prettyJSON(result) }] }
43
55
  } catch (error) {
44
56
  const message = error instanceof Error ? error.message : String(error)
45
57
 
package/lib/tools.ts CHANGED
@@ -2,44 +2,13 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * The MCP tool table — pure, transport-free. `server.ts` adapts this to the `@modelcontextprotocol/sdk`'s
7
- * registration API; `cli.ts` builds the real `MCPToolDeps` from the mailwoman library. Kept separate so this
8
- * file (the actual product surface) is testable without any MCP plumbing — `tools.test.ts` calls
9
- * `buildToolTable` directly with stub deps.
10
- *
11
- * One tool per capability the exotic-POI/BDC arcs' other packages expose to a human/CLI caller — see
12
- * `buildToolTable`'s return value for the authoritative, current list (this comment intentionally states no count,
13
- * so it can't go stale as tools are added):
14
- *
15
- * - `mailwoman_parse` — the runtime pipeline's parse (optionally POI-aware).
16
- * - `mailwoman_geocode` — the street-level geocode cascade (`mailwoman/geocode-core`).
17
- * - `mailwoman_poi_search` — POI-intent extraction + (when a poi.db is wired) execution.
18
- * - `mailwoman_overpass_export` — OverpassQL EXPORT emitter (`mailwoman/poi-overpass`) — "we print the query;
19
- * we never run it".
20
- * - `mailwoman_layer_manifest` — read a spatial-layer database's provenance manifest + coverage summary
21
- * (`@mailwoman/core/layers`).
22
- * - `mailwoman_bdc_filing_landscape` — read a bdc.db layer's provider/technology/speed-bucket filing census over a
23
- * set of census blocks or H3 cells (`@mailwoman/bdc`'s `filingLandscape`).
24
- * - `mailwoman_plausibility_check` — score one claimed broadband-service assertion against BDC filing evidence and
25
- * nearby telecom infrastructure (`@mailwoman/bdc`'s `plausibilityCheck`), returning a positive-evidence-only bundle
26
- * with an always-present `coverage_confidence`. A missing/absent `bdc_database_path`/`poi_database_path` degrades
27
- * to a typed abstain entry in the bundle, never a throw (decision 6).
28
- * - `mailwoman_filer_lookup` — read the FCC filer identity crosswalk (`@mailwoman/filer`'s
29
- * `filerLookup`) for one identifier (FRN, Form 499 ID, or BDC provider ID): every OTHER identifier it shares an
30
- * authoritative edge with, its current attributes, its authoritative entity cluster, and any inferred links —
31
- * reported separately, never merged into the cluster. `as_of` is always present (defaults to today).
32
- * - `mailwoman_filer_family` — read a corporate family's membership (`@mailwoman/filer/sdk`'s
33
- * `familyRollup`) from a filer.db layer database, given a `family_id` or a `node_id`. Distinct from an entity
34
- * cluster (same filer, different identifiers) — a corporate family spans several DIFFERENT filers under a
35
- * holding/parent/subsidiary/management relationship. The handler passes `familyRollup`'s result through
36
- * unchanged: no reshaping, filtering, or summarizing of who-owns-whom data.
37
5
  */
38
6
 
39
7
  import { z } from "zod"
40
8
 
41
9
  /**
42
- * The library surface every tool handler dispatches to. `cli.ts` builds the real implementation.
10
+ * Defines the library operations that MCP tool handlers call.
11
+ * `cli.ts` implements those operations.
43
12
  */
44
13
  export interface MCPToolDeps {
45
14
  parse: (text: string, opts?: { poi?: boolean }) => Promise<unknown>
@@ -68,13 +37,12 @@ export interface MCPToolDeps {
68
37
  }
69
38
 
70
39
  /**
71
- * One MCP tool. `inputSchema` is a plain Zod object (not `any` — this repo's oxlint config errors on
72
- * `typescript/no-explicit-any`) — `z.ZodRawShape` is zod's own umbrella type for "any object shape", so this stays
73
- * generic over the concrete per-tool schemas without reaching for `any`. `handler` re-parses `args` through the same
74
- * schema (cheap; zod objects are small here) rather than trusting an unchecked cast, so the array of heterogeneous
75
- * tools stays type-safe internally despite the necessarily-uniform external shape.
40
+ * Describes one MCP tool as registered with the server.
41
+ *
42
+ * Each `handler` re-parses `args` through its own `inputSchema` instead of trusting a cast,
43
+ * because the table's uniform signature erases the per-tool types.
76
44
  */
77
- export interface MCPToolDef {
45
+ interface MCPToolDef {
78
46
  name: string
79
47
  description: string
80
48
  inputSchema: z.ZodObject<z.ZodRawShape>
@@ -255,7 +223,8 @@ const FilerFamilyInputSchema = z.object({
255
223
  })
256
224
 
257
225
  /**
258
- * Build the tool table for a concrete `MCPToolDeps` implementation. Pure — no transport, no I/O of its own.
226
+ * Builds the MCP tool table over the given dependencies, without opening a transport
227
+ * or performing I/O itself.
259
228
  */
260
229
  export function buildToolTable(deps: MCPToolDeps): MCPToolDef[] {
261
230
  return [
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @copyright Sister Software
4
+ * @license AGPL-3.0
5
+ * @author Teffen Ellis, et al.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../cli/main.ts"],"names":[],"mappings":";AACA;;;;GAIG"}