census-geo-mcp 1.0.4 → 1.0.5
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/dist/api.js +39 -0
- package/dist/server.js +2 -3
- package/package.json +2 -2
- package/server.json +2 -2
package/dist/api.js
CHANGED
|
@@ -80,3 +80,42 @@ export async function coordinateGeographies(args) {
|
|
|
80
80
|
throw new Error(`No census geographies for ${x},${y}.`);
|
|
81
81
|
return [`Census geographies for ${x},${y}`, ...lines].join('\n');
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
const CENSUS = 'https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress';
|
|
85
|
+
export async function addressGeographies(args = {}) {
|
|
86
|
+
const address = String(args?.address ?? '').trim();
|
|
87
|
+
if (address.length < 5)
|
|
88
|
+
throw new Error('Give a street address, like 1600 Pennsylvania Ave NW Washington DC.');
|
|
89
|
+
const qs = new URLSearchParams({
|
|
90
|
+
address,
|
|
91
|
+
benchmark: 'Public_AR_Current',
|
|
92
|
+
vintage: 'Current_Current',
|
|
93
|
+
format: 'json',
|
|
94
|
+
});
|
|
95
|
+
const res = await fetch(`${CENSUS}?${qs}`, {
|
|
96
|
+
headers: { 'User-Agent': 'mrfentmen-census-geo-mcp/1.0', Accept: 'application/json' },
|
|
97
|
+
signal: AbortSignal.timeout(30000),
|
|
98
|
+
});
|
|
99
|
+
if (!res.ok)
|
|
100
|
+
throw new Error(`Census geocoder returned ${res.status}`);
|
|
101
|
+
if (!(res.headers.get('content-type') ?? '').includes('json'))
|
|
102
|
+
throw new Error('The Census geocoder answered with a page instead of data; try again shortly.');
|
|
103
|
+
const body = (await res.json());
|
|
104
|
+
const match = body.result?.addressMatches?.[0];
|
|
105
|
+
if (!match)
|
|
106
|
+
throw new Error(`The Census geocoder could not match "${address}"`);
|
|
107
|
+
const layers = Object.entries(match.geographies ?? {});
|
|
108
|
+
const lines = layers.map(([layer, rows]) => {
|
|
109
|
+
const names = (rows ?? []).map((r) => r.NAME ?? r.BASENAME ?? '?').filter(Boolean);
|
|
110
|
+
return `${layer}: ${names.join(', ') || 'no name reported'}`;
|
|
111
|
+
});
|
|
112
|
+
const c = match.coordinates ?? {};
|
|
113
|
+
return [
|
|
114
|
+
`Matched: ${match.matchedAddress ?? address}`,
|
|
115
|
+
`Coordinates: ${c.y ?? '?'}, ${c.x ?? '?'}`,
|
|
116
|
+
`Benchmark ${body.result?.benchmark?.benchmarkName ?? '?'} · vintage ${body.result?.vintage?.vintageName ?? '?'}`,
|
|
117
|
+
'',
|
|
118
|
+
`${layers.length} geographies:`,
|
|
119
|
+
...lines,
|
|
120
|
+
].join('\n');
|
|
121
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { coordinates, geocode, coordinateGeographies } from "./api.js";
|
|
3
|
+
import { coordinates, geocode, coordinateGeographies, addressGeographies } from "./api.js";
|
|
4
4
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
5
5
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
6
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -39,9 +39,8 @@ export function createServer() {
|
|
|
39
39
|
inputSchema: z.object({ address: z.string().describe("Street address, e.g. '1600 Pennsylvania Ave NW Washington DC'.") }),
|
|
40
40
|
annotations: READ_ONLY,
|
|
41
41
|
}, async (args) => {
|
|
42
|
-
// TODO: implement geographies locally (paywall removed)
|
|
43
42
|
try {
|
|
44
|
-
return
|
|
43
|
+
return text(await addressGeographies(args));
|
|
45
44
|
}
|
|
46
45
|
catch (e) {
|
|
47
46
|
return textError(String(e));
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/mrfentmen/census-geo-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.5",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "census-geo-mcp",
|
|
14
|
-
"version": "1.0.
|
|
14
|
+
"version": "1.0.5",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
}
|