census-geo-mcp 1.0.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 +21 -0
- package/dist/api.js +36 -0
- package/dist/index.js +4 -0
- package/dist/server.js +38 -0
- package/package.json +44 -0
- package/server.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Census Geo MCP
|
|
2
|
+
|
|
3
|
+
Census Bureau geocoding API: address to coordinates and census geography. No key required.
|
|
4
|
+
|
|
5
|
+
This file is self contained. It reads public data only and never writes to the machine. All output is bounded and honest about what could not be fetched.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
* `geocode` Geocode a street address.
|
|
11
|
+
* `coordinates` Reverse geocode coordinates.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm run build
|
|
18
|
+
node dist/index.js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Data comes from the public Census Geo API.
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const UA = 'mrfentmen-census-geo-mcp/1.0';
|
|
2
|
+
const BASE = 'https://geocoding.geo.census.gov/geocoder/locations';
|
|
3
|
+
export async function geocode(args) {
|
|
4
|
+
const addr = String(args.address).trim();
|
|
5
|
+
if (!addr)
|
|
6
|
+
throw new Error('Provide a street address.');
|
|
7
|
+
const res = await fetch(`${BASE}/onelineaddress?address=${encodeURIComponent(addr)}&benchmark=Public_AR_Current&format=json`, {
|
|
8
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
9
|
+
signal: AbortSignal.timeout(25000),
|
|
10
|
+
});
|
|
11
|
+
if (!res.ok)
|
|
12
|
+
throw new Error(`Census geocoder returned ${res.status}`);
|
|
13
|
+
const d = (await res.json());
|
|
14
|
+
const matches = d.result?.addressMatches ?? [];
|
|
15
|
+
if (!matches.length)
|
|
16
|
+
return `No address match for "${args.address}".`;
|
|
17
|
+
const m = matches[0];
|
|
18
|
+
const block = m.geographies?.['Census Blocks']?.[0];
|
|
19
|
+
return `Address match for "${args.address}":\nMatched: ${m.matchedAddress ?? '?'}\nCoordinates: ${m.coordinates?.y ?? '?'}, ${m.coordinates?.x ?? '?'}\nFIPS block: ${block?.GEOID ?? '?'} (state ${block?.STATE ?? '?'}, county ${block?.COUNTY ?? '?'}, tract ${block?.TRACT ?? '?'}, block ${block?.BLOCK ?? '?'})`;
|
|
20
|
+
}
|
|
21
|
+
export async function coordinates(args) {
|
|
22
|
+
const x = Number(args.x), y = Number(args.y);
|
|
23
|
+
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
24
|
+
throw new Error('Provide valid x (lon) and y (lat).');
|
|
25
|
+
const res = await fetch(`${BASE}/coordinates?x=${x}&y=${y}&benchmark=Public_AR_Current&format=json`, {
|
|
26
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
27
|
+
signal: AbortSignal.timeout(25000),
|
|
28
|
+
});
|
|
29
|
+
if (!res.ok)
|
|
30
|
+
throw new Error(`Census geocoder returned ${res.status}`);
|
|
31
|
+
const d = (await res.json());
|
|
32
|
+
const block = d.result?.geographies?.['Census Blocks']?.[0];
|
|
33
|
+
if (!block?.GEOID)
|
|
34
|
+
throw new Error(`No census geography for ${x},${y}.`);
|
|
35
|
+
return `Census geography for ${x},${y}:\nFIPS block: ${block.GEOID}\nState: ${block.STATE ?? '?'} | County: ${block.COUNTY ?? '?'} | Tract: ${block.TRACT ?? '?'} | Block: ${block.BLOCK ?? '?'}`;
|
|
36
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
const main = async () => { const server = createServer(); await server.connect(new StdioServerTransport()); };
|
|
4
|
+
main().catch((error) => { console.error("Fatal error:", error); process.exit(1); });
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { coordinates } from "./api.js";
|
|
4
|
+
import { geocode } from "./api.js";
|
|
5
|
+
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
6
|
+
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
7
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
8
|
+
const error = (e) => `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
9
|
+
export function createServer() {
|
|
10
|
+
const server = new McpServer({ name: "census-geo-mcp", version: "1.0.0" });
|
|
11
|
+
server.registerTool("geocode", {
|
|
12
|
+
title: "Geocode",
|
|
13
|
+
description: "Geocode a street address.",
|
|
14
|
+
inputSchema: z.object({ address: z.string().describe("Street address.") }),
|
|
15
|
+
annotations: READ_ONLY,
|
|
16
|
+
}, async (args) => {
|
|
17
|
+
try {
|
|
18
|
+
return text(await geocode(args));
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return textError(error(e));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
server.registerTool("coordinates", {
|
|
25
|
+
title: "Coordinates",
|
|
26
|
+
description: "Reverse geocode coordinates.",
|
|
27
|
+
inputSchema: z.object({ x: z.number().describe("Longitude."), y: z.number().describe("Latitude.") }),
|
|
28
|
+
annotations: READ_ONLY,
|
|
29
|
+
}, async (args) => {
|
|
30
|
+
try {
|
|
31
|
+
return text(await coordinates(args));
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return textError(error(e));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return server;
|
|
38
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/mrfentmen/census-geo-mcp.git"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"census-geo-mcp": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"server.json",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.json",
|
|
19
|
+
"start": "node dist/index.js",
|
|
20
|
+
"dev": "npm run build && node dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
25
|
+
"zod": "^3.23.8"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.0.0",
|
|
29
|
+
"typescript": "^5.6.0"
|
|
30
|
+
},
|
|
31
|
+
"name": "census-geo-mcp",
|
|
32
|
+
"description": "Census Bureau geocoding API: address to coordinates and census geography.",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"mcp",
|
|
35
|
+
"census",
|
|
36
|
+
"geocoding",
|
|
37
|
+
"address",
|
|
38
|
+
"fips"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20"
|
|
42
|
+
},
|
|
43
|
+
"mcpName": "io.github.mrfentmen/census-geo-mcp"
|
|
44
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.mrfentmen/census-geo-mcp",
|
|
4
|
+
"description": "Census Bureau geocoding API: address to coordinates and census geography.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/mrfentmen/census-geo-mcp",
|
|
7
|
+
"source": "github"
|
|
8
|
+
},
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"packages": [
|
|
11
|
+
{
|
|
12
|
+
"registryType": "npm",
|
|
13
|
+
"identifier": "census-geo-mcp",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"transport": {
|
|
16
|
+
"type": "stdio"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|